Skip to content

Commit f33145a

Browse files
authored
Improve (and fix) gallery grid rendering (#539)
* supercharge custom sphinxext * black
1 parent 41dd3a7 commit f33145a

11 files changed

+123
-251
lines changed

.gitignore

+2
Original file line numberDiff line numberDiff line change
@@ -4,5 +4,7 @@
44
*.DS_Store
55

66
_build
7+
build
78
jupyter_execute
89
_thumbnails
10+
examples/gallery.rst
349 KB
Loading
102 KB
Loading
15.1 KB
Loading
Loading
102 KB
Loading

_thumbnails/thumbnails/README.txt

-1
This file was deleted.

examples/conf.py

+2-63
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,5 @@
1-
import os, sys
1+
import os
2+
import sys
23
from pathlib import Path
34
from sphinx.application import Sphinx
45

@@ -25,10 +26,8 @@
2526
"sphinxcontrib.bibtex",
2627
"sphinx_codeautolink",
2728
"notfound.extension",
28-
"sphinx_gallery.load_style",
2929
"thumbnail_extractor",
3030
"sphinxext.rediraffe",
31-
"sphinx_remove_toctrees",
3231
]
3332

3433
# List of patterns, relative to source directory, that match files and
@@ -46,49 +45,6 @@
4645
]
4746

4847

49-
def hack_nbsphinx(app: Sphinx) -> None:
50-
from nbsphinx import (
51-
depart_gallery_html,
52-
doctree_resolved,
53-
GalleryNode,
54-
NbGallery,
55-
patched_toctree_resolve,
56-
)
57-
from sphinx.environment.adapters import toctree
58-
59-
from glob import glob
60-
61-
nb_paths = glob("*/*.ipynb")
62-
nbsphinx_thumbnails = {}
63-
for nb_path in nb_paths:
64-
png_file = os.path.join(
65-
"thumbnails", os.path.splitext(os.path.split(nb_path)[-1])[0] + ".png"
66-
)
67-
nb_path_rel = os.path.splitext(nb_path)[0]
68-
nbsphinx_thumbnails[nb_path_rel] = png_file
69-
70-
def builder_inited(app: Sphinx):
71-
if not hasattr(app.env, "nbsphinx_thumbnails"):
72-
app.env.nbsphinx_thumbnails = {}
73-
74-
def do_nothing(*node):
75-
pass
76-
77-
app.add_config_value("nbsphinx_thumbnails", nbsphinx_thumbnails, rebuild="html")
78-
app.add_directive("nbgallery", NbGallery)
79-
app.add_node(
80-
GalleryNode,
81-
html=(do_nothing, depart_gallery_html),
82-
latex=(do_nothing, do_nothing),
83-
text=(do_nothing, do_nothing),
84-
)
85-
app.connect("builder-inited", builder_inited)
86-
app.connect("doctree-resolved", doctree_resolved)
87-
88-
# Monkey-patch Sphinx TocTree adapter
89-
toctree.TocTree.resolve = patched_toctree_resolve
90-
91-
9248
def remove_index(app):
9349
"""
9450
This removes the index pages so rediraffe generates the redirect placeholder
@@ -103,7 +59,6 @@ def remove_index(app):
10359

10460

10561
def setup(app: Sphinx):
106-
hack_nbsphinx(app)
10762
app.connect("html-collect-pages", remove_index, 100)
10863

10964

@@ -196,22 +151,6 @@ def setup(app: Sphinx):
196151
rediraffe_redirects = {
197152
"index.md": "gallery.md",
198153
}
199-
remove_from_toctrees = [
200-
"BART/*",
201-
"case_studies/*",
202-
"causal_inference/*",
203-
"diagnostics_and_criticism/*",
204-
"gaussian_processes/*",
205-
"generalized_linear_models/*",
206-
"mixture_models/*",
207-
"ode_models/*",
208-
"howto/*",
209-
"samplers/*",
210-
"splines/*",
211-
"survival_analysis/*",
212-
"time_series/*",
213-
"variational_inference/*",
214-
]
215154

216155
# bibtex config
217156
bibtex_bibfiles = ["references.bib"]

examples/gallery.rst

-172
This file was deleted.

requirements-docs.txt

+2-5
Original file line numberDiff line numberDiff line change
@@ -1,15 +1,12 @@
11
myst-nb
2-
sphinx==5.0.2 # see https://github.com/pymc-devs/pymc-examples/issues/409
3-
pymc-sphinx-theme==0.1
2+
sphinx>=5
3+
pymc-sphinx-theme==0.13
44
sphinx-design
55
sphinx-copybutton
66
sphinxcontrib-bibtex
77
ablog
88
sphinxext-opengraph
99
sphinx-codeautolink
1010
sphinx-notfound-page
11-
nbsphinx
12-
sphinx-gallery==0.10.1 # see https://github.com/pymc-devs/pymc-examples/issues/409
1311
matplotlib
1412
sphinxext-rediraffe
15-
sphinx-remove-toctrees

0 commit comments

Comments
 (0)