Skip to content

Commit a66c841

Browse files
authored
Make gallery builder more flexible and restructure. (#598)
* Make gallery builder more flexible and restructure. * Fix * Restructure. * Fix. * Fix. * fix * fix
1 parent 0ce7ddb commit a66c841

File tree

5 files changed

+68
-46
lines changed

5 files changed

+68
-46
lines changed

sphinxext/thumbnail_extractor.py

+68-46
Original file line numberDiff line numberDiff line change
@@ -32,48 +32,6 @@
3232
3333
object_index/index
3434
35-
Core notebooks
36-
--------------
37-
38-
.. grid:: 1 2 3 3
39-
:gutter: 4
40-
41-
.. grid-item-card:: Introductory Overview of PyMC
42-
:img-top: https://raw.githubusercontent.com/pymc-devs/brand/main/pymc/pymc_logos/PyMC_square.svg
43-
:link: pymc:pymc_overview
44-
:link-type: ref
45-
:shadow: none
46-
47-
.. grid-item-card:: GLM: Linear regression
48-
:img-top: ../_thumbnails/core_notebooks/glm_linear.png
49-
:link: pymc:glm_linear
50-
:link-type: ref
51-
:shadow: none
52-
53-
.. grid-item-card:: Model Comparison
54-
:img-top: ../_thumbnails/core_notebooks/model_comparison.png
55-
:link: pymc:model_comparison
56-
:link-type: ref
57-
:shadow: none
58-
59-
.. grid-item-card:: Prior and Posterior Predictive Checks
60-
:img-top: ../_thumbnails/core_notebooks/posterior_predictive.png
61-
:link: pymc:posterior_predictive
62-
:link-type: ref
63-
:shadow: none
64-
65-
.. grid-item-card:: Distribution Dimensionality
66-
:img-top: ../_thumbnails/core_notebooks/dimensionality.png
67-
:link: pymc:dimensionality
68-
:link-type: ref
69-
:shadow: none
70-
71-
.. grid-item-card:: PyMC and PyTensor
72-
:img-top: ../_thumbnails/core_notebooks/pytensor_pymc.png
73-
:link: pymc:pymc_pytensor
74-
:link-type: ref
75-
:shadow: none
76-
7735
"""
7836

7937
SECTION_TEMPLATE = """
@@ -88,14 +46,64 @@
8846
"""
8947

9048
ITEM_TEMPLATE = """
91-
.. grid-item-card:: :doc:`{doc_reference}`
49+
.. grid-item-card:: :doc:`{doc_name}`
9250
:img-top: {image}
9351
:link: {doc_reference}
94-
:link-type: doc
52+
:link-type: {link_type}
9553
:shadow: none
9654
"""
9755

56+
intro_nb = {
57+
"doc_name": "General Overview",
58+
"image": "https://raw.githubusercontent.com/pymc-devs/brand/main/pymc/pymc_logos/PyMC_square.svg",
59+
"doc_reference": "pymc:pymc_overview",
60+
"link_type": "ref",
61+
}
62+
63+
glm_nb = {
64+
"doc_name": "Simple Linear Regression",
65+
"image": "../_thumbnails/core_notebooks/glm_linear.png",
66+
"doc_reference": "pymc:glm_linear",
67+
"link_type": "ref",
68+
}
69+
70+
model_comparison_nb = {
71+
"doc_name": "Model Comparison",
72+
"image": "../_thumbnails/core_notebooks/posterior_predictive.png",
73+
"doc_reference": "pymc:model_comparison",
74+
"link_type": "ref",
75+
}
76+
77+
prior_pred_nb = {
78+
"doc_name": "Prior and Posterior Predictive Checks",
79+
"image": "../_thumbnails/core_notebooks/model_comparison.png",
80+
"doc_reference": "pymc:posterior_predictive",
81+
"link_type": "ref",
82+
}
83+
84+
dimensionality_nb = {
85+
"doc_name": "Distribution Dimensionality",
86+
"image": "../_thumbnails/core_notebooks/dimensionality.png",
87+
"doc_reference": "pymc:dimensionality",
88+
"link_type": "ref",
89+
}
90+
91+
pytensor_nb = {
92+
"doc_name": "PyMC and PyTensor",
93+
"image": "../_thumbnails/core_notebooks/pytensor_pymc.png",
94+
"doc_reference": "pymc:pymc_pytensor",
95+
"link_type": "ref",
96+
}
97+
98+
external_nbs = {
99+
"introductory": [intro_nb, glm_nb],
100+
"fundamentals": [dimensionality_nb, pytensor_nb],
101+
"howto": [prior_pred_nb, model_comparison_nb],
102+
}
103+
98104
folder_title_map = {
105+
"introductory": "Introductory",
106+
"fundamentals": "Library Fundamentals",
99107
"generalized_linear_models": "(Generalized) Linear and Hierarchical Linear Models",
100108
"case_studies": "Case Studies",
101109
"causal_inference": "Causal Inference",
@@ -185,7 +193,6 @@ def main(app):
185193
file = [HEAD]
186194

187195
for folder, title in folder_title_map.items():
188-
nb_paths = glob(f"{folder}/*.ipynb")
189196
file.append(
190197
SECTION_TEMPLATE.format(
191198
section_title=title, section_id=folder, underlines="-" * len(title)
@@ -195,12 +202,27 @@ def main(app):
195202
if not os.path.isdir(target_dir):
196203
os.mkdir(target_dir)
197204

205+
if folder in external_nbs.keys():
206+
for descr in external_nbs[folder]:
207+
file.append(
208+
ITEM_TEMPLATE.format(
209+
doc_name=descr["doc_name"],
210+
image=descr["image"],
211+
doc_reference=descr["doc_reference"],
212+
link_type=descr["link_type"],
213+
)
214+
)
215+
216+
nb_paths = glob(f"{folder}/*.ipynb")
198217
for nb_path in nb_paths:
199218
nbg = NotebookGenerator(nb_path, "..", folder)
200219
nbg.gen_previews()
201220
file.append(
202221
ITEM_TEMPLATE.format(
203-
doc_reference=os.path.join(folder, nbg.stripped_name), image=nbg.png_path
222+
doc_name=os.path.join(folder, nbg.stripped_name),
223+
image=nbg.png_path,
224+
doc_reference=os.path.join(folder, nbg.stripped_name),
225+
link_type="doc",
204226
)
205227
)
206228

0 commit comments

Comments
 (0)