From 8c32477c65fb2a57cc768ad8c06ba05ba0731912 Mon Sep 17 00:00:00 2001 From: Thomas Wiecki Date: Fri, 17 Nov 2023 16:56:08 +0100 Subject: [PATCH 1/7] Make gallery builder more flexible and restructure. --- sphinxext/thumbnail_extractor.py | 111 ++++++++++++++++++------------- 1 file changed, 66 insertions(+), 45 deletions(-) diff --git a/sphinxext/thumbnail_extractor.py b/sphinxext/thumbnail_extractor.py index ed6e41c14..1fe294a76 100644 --- a/sphinxext/thumbnail_extractor.py +++ b/sphinxext/thumbnail_extractor.py @@ -32,48 +32,6 @@ object_index/index -Core notebooks --------------- - -.. grid:: 1 2 3 3 - :gutter: 4 - - .. grid-item-card:: Introductory Overview of PyMC - :img-top: https://raw.githubusercontent.com/pymc-devs/brand/main/pymc/pymc_logos/PyMC_square.svg - :link: pymc:pymc_overview - :link-type: ref - :shadow: none - - .. grid-item-card:: GLM: Linear regression - :img-top: ../_thumbnails/core_notebooks/glm_linear.png - :link: pymc:glm_linear - :link-type: ref - :shadow: none - - .. grid-item-card:: Model Comparison - :img-top: ../_thumbnails/core_notebooks/model_comparison.png - :link: pymc:model_comparison - :link-type: ref - :shadow: none - - .. grid-item-card:: Prior and Posterior Predictive Checks - :img-top: ../_thumbnails/core_notebooks/posterior_predictive.png - :link: pymc:posterior_predictive - :link-type: ref - :shadow: none - - .. grid-item-card:: Distribution Dimensionality - :img-top: ../_thumbnails/core_notebooks/dimensionality.png - :link: pymc:dimensionality - :link-type: ref - :shadow: none - - .. grid-item-card:: PyMC and PyTensor - :img-top: ../_thumbnails/core_notebooks/pytensor_pymc.png - :link: pymc:pymc_pytensor - :link-type: ref - :shadow: none - """ SECTION_TEMPLATE = """ @@ -88,14 +46,63 @@ """ ITEM_TEMPLATE = """ - .. grid-item-card:: :doc:`{doc_reference}` + .. grid-item-card:: :doc:`{doc_name}` :img-top: {image} :link: {doc_reference} - :link-type: doc + :link-type: {link_type} :shadow: none """ +intro_nb = { + "doc_name": "Introductory Overview of PyMC", + "image": "https://raw.githubusercontent.com/pymc-devs/brand/main/pymc/pymc_logos/PyMC_square.svg", + "doc_reference": "pymc:pymc_overview", + "link_type": "ref", +} + +glm_nb = { + "doc_name": "GLM: Linear regression", + "image": "../_thumbnails/core_notebooks/glm_linear.png", + "doc_reference": "pymc:glm_linear", + "link_type": "ref", +} + +model_comparison_nb = { + "doc_name": "Model Comparison", + "image": "../_thumbnails/core_notebooks/posterior_predictive.png", + "doc_reference": "pymc:model_comparison", + "link_type": "ref", +} + +prior_pred_nb = { + "doc_name": "Prior and Posterior Predictive Checks", + "image": "../_thumbnails/core_notebooks/model_comparison.png", + "doc_reference": "pymc:posterior_predictive", + "link_type": "ref", +} + +dimensionality_nb = { + "doc_name": "Distribution Dimensionality", + "image": "../_thumbnails/core_notebooks/dimensionality.png", + "doc_reference": "pymc:dimensionality", + "link_type": "ref", +} + +pytensor_nb = { + "doc_name": "PyMC and PyTensor", + "image": "../_thumbnails/core_notebooks/pytensor_pymc.png", + "doc_reference": "pymc:pymc_pytensor", + "link_type": "ref", +} + +external_nbs = { + "introductory": [glm_nb], + "fundamentals": [intro_nb, dimensionality_nb, pytensor_nb], +} + folder_title_map = { + "introductory": "Introductory", + "fundamentals": "Library Fundamentals", "generalized_linear_models": "(Generalized) Linear and Hierarchical Linear Models", "case_studies": "Case Studies", "causal_inference": "Causal Inference", @@ -184,6 +191,17 @@ def main(app): file = [HEAD] for folder, title in folder_title_map.items(): + if folder in external_nbs.keys(): + for descr in external_nbs[folder]: + file.append( + ITEM_TEMPLATE.format( + doc_reference=descr["doc_name"], + image=descr["image"], + link_ref=descr["doc_reference"], + link_type=descr["link_type"], + ) + ) + nb_paths = glob(f"{folder}/*.ipynb") file.append( SECTION_TEMPLATE.format( @@ -199,7 +217,10 @@ def main(app): nbg.gen_previews() file.append( ITEM_TEMPLATE.format( - doc_reference=os.path.join(folder, nbg.stripped_name), image=nbg.png_path + doc_name=os.path.join(folder, nbg.stripped_name), + doc_reference=os.path.join(folder, nbg.stripped_name), + image=nbg.png_path, + link_ref="doc", ) ) From 23332f9e6201578bd08f2973b9e4484f4044630f Mon Sep 17 00:00:00 2001 From: Thomas Wiecki Date: Fri, 17 Nov 2023 17:10:52 +0100 Subject: [PATCH 2/7] Fix --- sphinxext/thumbnail_extractor.py | 10 +++++----- 1 file changed, 5 insertions(+), 5 deletions(-) diff --git a/sphinxext/thumbnail_extractor.py b/sphinxext/thumbnail_extractor.py index 1fe294a76..93e9cf8b7 100644 --- a/sphinxext/thumbnail_extractor.py +++ b/sphinxext/thumbnail_extractor.py @@ -96,8 +96,8 @@ } external_nbs = { - "introductory": [glm_nb], - "fundamentals": [intro_nb, dimensionality_nb, pytensor_nb], + "introductory": [glm_nb, intro_nb], + "fundamentals": [dimensionality_nb, pytensor_nb], } folder_title_map = { @@ -195,9 +195,9 @@ def main(app): for descr in external_nbs[folder]: file.append( ITEM_TEMPLATE.format( - doc_reference=descr["doc_name"], + doc_name=descr["doc_name"], image=descr["image"], - link_ref=descr["doc_reference"], + doc_reference=descr["doc_reference"], link_type=descr["link_type"], ) ) @@ -218,8 +218,8 @@ def main(app): file.append( ITEM_TEMPLATE.format( doc_name=os.path.join(folder, nbg.stripped_name), - doc_reference=os.path.join(folder, nbg.stripped_name), image=nbg.png_path, + doc_reference=os.path.join(folder, nbg.stripped_name), link_ref="doc", ) ) From 87da4f4358f187c3deb6d0ef4a42c6446b694b28 Mon Sep 17 00:00:00 2001 From: Thomas Wiecki Date: Fri, 17 Nov 2023 17:20:08 +0100 Subject: [PATCH 3/7] Restructure. --- examples/{howto => fundamentals}/data_container.ipynb | 0 examples/{howto => fundamentals}/data_container.myst.md | 0 sphinxext/thumbnail_extractor.py | 5 +++-- 3 files changed, 3 insertions(+), 2 deletions(-) rename examples/{howto => fundamentals}/data_container.ipynb (100%) rename examples/{howto => fundamentals}/data_container.myst.md (100%) diff --git a/examples/howto/data_container.ipynb b/examples/fundamentals/data_container.ipynb similarity index 100% rename from examples/howto/data_container.ipynb rename to examples/fundamentals/data_container.ipynb diff --git a/examples/howto/data_container.myst.md b/examples/fundamentals/data_container.myst.md similarity index 100% rename from examples/howto/data_container.myst.md rename to examples/fundamentals/data_container.myst.md diff --git a/sphinxext/thumbnail_extractor.py b/sphinxext/thumbnail_extractor.py index 93e9cf8b7..cdc7a04e2 100644 --- a/sphinxext/thumbnail_extractor.py +++ b/sphinxext/thumbnail_extractor.py @@ -54,14 +54,14 @@ """ intro_nb = { - "doc_name": "Introductory Overview of PyMC", + "doc_name": "General Overview", "image": "https://raw.githubusercontent.com/pymc-devs/brand/main/pymc/pymc_logos/PyMC_square.svg", "doc_reference": "pymc:pymc_overview", "link_type": "ref", } glm_nb = { - "doc_name": "GLM: Linear regression", + "doc_name": "Simple Linear Regression", "image": "../_thumbnails/core_notebooks/glm_linear.png", "doc_reference": "pymc:glm_linear", "link_type": "ref", @@ -98,6 +98,7 @@ external_nbs = { "introductory": [glm_nb, intro_nb], "fundamentals": [dimensionality_nb, pytensor_nb], + "howto": [prior_pred_nb, model_comparison_nb], } folder_title_map = { From 97f8e14e45b7a526de66f3875f6fb58097b4156a Mon Sep 17 00:00:00 2001 From: Thomas Wiecki Date: Fri, 17 Nov 2023 17:22:04 +0100 Subject: [PATCH 4/7] Fix. --- sphinxext/thumbnail_extractor.py | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/sphinxext/thumbnail_extractor.py b/sphinxext/thumbnail_extractor.py index cdc7a04e2..98cac13e9 100644 --- a/sphinxext/thumbnail_extractor.py +++ b/sphinxext/thumbnail_extractor.py @@ -221,7 +221,7 @@ def main(app): doc_name=os.path.join(folder, nbg.stripped_name), image=nbg.png_path, doc_reference=os.path.join(folder, nbg.stripped_name), - link_ref="doc", + link_type="doc", ) ) From 8c7c128c9530d5a73b75f9f2ba2bcdb0c5154b94 Mon Sep 17 00:00:00 2001 From: Thomas Wiecki Date: Fri, 17 Nov 2023 17:25:18 +0100 Subject: [PATCH 5/7] Fix. --- sphinxext/thumbnail_extractor.py | 20 ++++++++++---------- 1 file changed, 10 insertions(+), 10 deletions(-) diff --git a/sphinxext/thumbnail_extractor.py b/sphinxext/thumbnail_extractor.py index 98cac13e9..a1c3ee176 100644 --- a/sphinxext/thumbnail_extractor.py +++ b/sphinxext/thumbnail_extractor.py @@ -192,6 +192,16 @@ def main(app): file = [HEAD] for folder, title in folder_title_map.items(): + nb_paths = glob(f"{folder}/*.ipynb") + file.append( + SECTION_TEMPLATE.format( + section_title=title, section_id=folder, underlines="-" * len(title) + ) + ) + target_dir = os.path.join("..", "_thumbnails", folder) + if not os.path.isdir(target_dir): + os.mkdir(target_dir) + if folder in external_nbs.keys(): for descr in external_nbs[folder]: file.append( @@ -203,16 +213,6 @@ def main(app): ) ) - nb_paths = glob(f"{folder}/*.ipynb") - file.append( - SECTION_TEMPLATE.format( - section_title=title, section_id=folder, underlines="-" * len(title) - ) - ) - target_dir = os.path.join("..", "_thumbnails", folder) - if not os.path.isdir(target_dir): - os.mkdir(target_dir) - for nb_path in nb_paths: nbg = NotebookGenerator(nb_path, "..", folder) nbg.gen_previews() From dc1f6b8f0183e454d244a21538af23cbe8bad29d Mon Sep 17 00:00:00 2001 From: Thomas Wiecki Date: Fri, 17 Nov 2023 17:27:39 +0100 Subject: [PATCH 6/7] fix --- examples/{howto => introductory}/api_quickstart.ipynb | 0 examples/{howto => introductory}/api_quickstart.myst.md | 0 sphinxext/thumbnail_extractor.py | 2 +- 3 files changed, 1 insertion(+), 1 deletion(-) rename examples/{howto => introductory}/api_quickstart.ipynb (100%) rename examples/{howto => introductory}/api_quickstart.myst.md (100%) diff --git a/examples/howto/api_quickstart.ipynb b/examples/introductory/api_quickstart.ipynb similarity index 100% rename from examples/howto/api_quickstart.ipynb rename to examples/introductory/api_quickstart.ipynb diff --git a/examples/howto/api_quickstart.myst.md b/examples/introductory/api_quickstart.myst.md similarity index 100% rename from examples/howto/api_quickstart.myst.md rename to examples/introductory/api_quickstart.myst.md diff --git a/sphinxext/thumbnail_extractor.py b/sphinxext/thumbnail_extractor.py index a1c3ee176..e910944a7 100644 --- a/sphinxext/thumbnail_extractor.py +++ b/sphinxext/thumbnail_extractor.py @@ -192,7 +192,6 @@ def main(app): file = [HEAD] for folder, title in folder_title_map.items(): - nb_paths = glob(f"{folder}/*.ipynb") file.append( SECTION_TEMPLATE.format( section_title=title, section_id=folder, underlines="-" * len(title) @@ -213,6 +212,7 @@ def main(app): ) ) + nb_paths = glob(f"{folder}/*.ipynb") for nb_path in nb_paths: nbg = NotebookGenerator(nb_path, "..", folder) nbg.gen_previews() From 08a11eaa87c295142da64e48cc4b9d452a72b2c1 Mon Sep 17 00:00:00 2001 From: Thomas Wiecki Date: Fri, 17 Nov 2023 17:28:07 +0100 Subject: [PATCH 7/7] fix --- sphinxext/thumbnail_extractor.py | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/sphinxext/thumbnail_extractor.py b/sphinxext/thumbnail_extractor.py index e910944a7..8e67ee4b6 100644 --- a/sphinxext/thumbnail_extractor.py +++ b/sphinxext/thumbnail_extractor.py @@ -96,7 +96,7 @@ } external_nbs = { - "introductory": [glm_nb, intro_nb], + "introductory": [intro_nb, glm_nb], "fundamentals": [dimensionality_nb, pytensor_nb], "howto": [prior_pred_nb, model_comparison_nb], }