Skip to content

Commit

Permalink
Improve (and fix) gallery grid rendering (pymc-devs#539)
Browse files Browse the repository at this point in the history
* supercharge custom sphinxext

* black
  • Loading branch information
OriolAbril authored Apr 6, 2023
1 parent 41dd3a7 commit f33145a
Show file tree
Hide file tree
Showing 11 changed files with 123 additions and 251 deletions.
2 changes: 2 additions & 0 deletions .gitignore
Original file line number Diff line number Diff line change
Expand Up @@ -4,5 +4,7 @@
*.DS_Store

_build
build
jupyter_execute
_thumbnails
examples/gallery.rst
Binary file added _thumbnails/core_notebooks/dimensionality.png
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Binary file added _thumbnails/core_notebooks/glm_linear.png
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Binary file added _thumbnails/core_notebooks/model_comparison.png
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Binary file added _thumbnails/core_notebooks/pytensor_pymc.png
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
1 change: 0 additions & 1 deletion _thumbnails/thumbnails/README.txt

This file was deleted.

65 changes: 2 additions & 63 deletions examples/conf.py
Original file line number Diff line number Diff line change
@@ -1,4 +1,5 @@
import os, sys
import os
import sys
from pathlib import Path
from sphinx.application import Sphinx

Expand All @@ -25,10 +26,8 @@
"sphinxcontrib.bibtex",
"sphinx_codeautolink",
"notfound.extension",
"sphinx_gallery.load_style",
"thumbnail_extractor",
"sphinxext.rediraffe",
"sphinx_remove_toctrees",
]

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


def hack_nbsphinx(app: Sphinx) -> None:
from nbsphinx import (
depart_gallery_html,
doctree_resolved,
GalleryNode,
NbGallery,
patched_toctree_resolve,
)
from sphinx.environment.adapters import toctree

from glob import glob

nb_paths = glob("*/*.ipynb")
nbsphinx_thumbnails = {}
for nb_path in nb_paths:
png_file = os.path.join(
"thumbnails", os.path.splitext(os.path.split(nb_path)[-1])[0] + ".png"
)
nb_path_rel = os.path.splitext(nb_path)[0]
nbsphinx_thumbnails[nb_path_rel] = png_file

def builder_inited(app: Sphinx):
if not hasattr(app.env, "nbsphinx_thumbnails"):
app.env.nbsphinx_thumbnails = {}

def do_nothing(*node):
pass

app.add_config_value("nbsphinx_thumbnails", nbsphinx_thumbnails, rebuild="html")
app.add_directive("nbgallery", NbGallery)
app.add_node(
GalleryNode,
html=(do_nothing, depart_gallery_html),
latex=(do_nothing, do_nothing),
text=(do_nothing, do_nothing),
)
app.connect("builder-inited", builder_inited)
app.connect("doctree-resolved", doctree_resolved)

# Monkey-patch Sphinx TocTree adapter
toctree.TocTree.resolve = patched_toctree_resolve


def remove_index(app):
"""
This removes the index pages so rediraffe generates the redirect placeholder
Expand All @@ -103,7 +59,6 @@ def remove_index(app):


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


Expand Down Expand Up @@ -196,22 +151,6 @@ def setup(app: Sphinx):
rediraffe_redirects = {
"index.md": "gallery.md",
}
remove_from_toctrees = [
"BART/*",
"case_studies/*",
"causal_inference/*",
"diagnostics_and_criticism/*",
"gaussian_processes/*",
"generalized_linear_models/*",
"mixture_models/*",
"ode_models/*",
"howto/*",
"samplers/*",
"splines/*",
"survival_analysis/*",
"time_series/*",
"variational_inference/*",
]

# bibtex config
bibtex_bibfiles = ["references.bib"]
Expand Down
172 changes: 0 additions & 172 deletions examples/gallery.rst

This file was deleted.

7 changes: 2 additions & 5 deletions requirements-docs.txt
Original file line number Diff line number Diff line change
@@ -1,15 +1,12 @@
myst-nb
sphinx==5.0.2 # see https://github.com/pymc-devs/pymc-examples/issues/409
pymc-sphinx-theme==0.1
sphinx>=5
pymc-sphinx-theme==0.13
sphinx-design
sphinx-copybutton
sphinxcontrib-bibtex
ablog
sphinxext-opengraph
sphinx-codeautolink
sphinx-notfound-page
nbsphinx
sphinx-gallery==0.10.1 # see https://github.com/pymc-devs/pymc-examples/issues/409
matplotlib
sphinxext-rediraffe
sphinx-remove-toctrees
Loading

0 comments on commit f33145a

Please sign in to comment.