Skip to content

Gallery #328

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Merged
merged 7 commits into from
May 31, 2022
Merged
Show file tree
Hide file tree
Changes from 6 commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
1 change: 0 additions & 1 deletion .pre-commit-config.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -45,7 +45,6 @@ repos:
- id: bibtex-tidy
files: examples/references.bib
args: ["--sort=key", --quiet]
language_version: 15.14.0
- repo: local
hooks:
- id: watermark
Expand Down
101 changes: 98 additions & 3 deletions examples/conf.py
Original file line number Diff line number Diff line change
@@ -1,12 +1,15 @@
import os
import os, sys
from sphinx.application import Sphinx

# -- Project information -----------------------------------------------------
project = "PyMC"
copyright = "2021, PyMC Community"
copyright = "2022, PyMC Community"
author = "PyMC Community"

# -- General configuration ---------------------------------------------------

sys.path.insert(0, os.path.abspath("../sphinxext"))

# Add any Sphinx extension module names here, as strings. They can be
# extensions coming with Sphinx (named 'sphinx.ext.*') or your custom
# ones.
Expand All @@ -21,6 +24,8 @@
"sphinxcontrib.bibtex",
"sphinx_codeautolink",
"notfound.extension",
"sphinx_gallery.load_style",
"gallery_generator",
]

# List of patterns, relative to source directory, that match files and
Expand All @@ -37,6 +42,96 @@
]


def hack_nbsphinx(app: Sphinx) -> None:
from nbsphinx import (
depart_gallery_html,
doctree_resolved,
GalleryNode,
NbGallery,
patched_toctree_resolve,
NotebookParser,
NbInput,
NbOutput,
NbInfo,
NbWarning,
CodeAreaNode,
depart_codearea_html,
visit_codearea_latex,
depart_codearea_latex,
GetSizeFromImages,
)
from sphinx.environment.adapters import toctree

nbsphinx_thumbnails = {
"case_studies/stochastic_volatility": "_static/stochastic_volatility.png",
}

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

def do_nothing(*node):
pass

app.add_source_parser(NotebookParser)
# app.add_config_value('nbsphinx_execute', 'auto', rebuild='env')
app.add_config_value("nbsphinx_kernel_name", "", rebuild="env")
app.add_config_value("nbsphinx_execute_arguments", [], rebuild="env")
app.add_config_value("nbsphinx_allow_errors", False, rebuild="")
app.add_config_value("nbsphinx_timeout", None, rebuild="")
app.add_config_value("nbsphinx_codecell_lexer", "none", rebuild="env")
app.add_config_value("nbsphinx_prompt_width", "4.5ex", rebuild="html")
app.add_config_value("nbsphinx_responsive_width", "540px", rebuild="html")
app.add_config_value("nbsphinx_prolog", None, rebuild="env")
app.add_config_value("nbsphinx_epilog", None, rebuild="env")
app.add_config_value("nbsphinx_input_prompt", "[%s]:", rebuild="env")
app.add_config_value("nbsphinx_output_prompt", "[%s]:", rebuild="env")
app.add_config_value("nbsphinx_custom_formats", {}, rebuild="env")
# Default value is set in config_inited():
app.add_config_value("nbsphinx_requirejs_path", None, rebuild="html")
# Default value is set in config_inited():
app.add_config_value("nbsphinx_requirejs_options", None, rebuild="html")
# This will be updated in env_updated():
app.add_config_value("nbsphinx_widgets_path", None, rebuild="html")
app.add_config_value("nbsphinx_widgets_options", {}, rebuild="html")
# app.add_config_value('nbsphinx_thumbnails', {}, rebuild='html')
app.add_config_value("nbsphinx_assume_equations", True, rebuild="env")

app.add_directive("nbinput", NbInput)
app.add_directive("nboutput", NbOutput)
app.add_directive("nbinfo", NbInfo)
app.add_directive("nbwarning", NbWarning)
app.add_directive("nbgallery", NbGallery)
app.add_node(
CodeAreaNode,
html=(do_nothing, depart_codearea_html),
latex=(visit_codearea_latex, depart_codearea_latex),
text=(do_nothing, do_nothing),
)
app.connect("builder-inited", builder_inited)
app.connect("doctree-resolved", doctree_resolved)
app.add_post_transform(GetSizeFromImages)

app.add_config_value("nbsphinx_execute", "auto", rebuild="env")
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 setup(app: Sphinx):
hack_nbsphinx(app)


# -- Options for HTML output -------------------------------------------------

# The theme to use for HTML and HTML Help pages. See the documentation for
Expand Down Expand Up @@ -93,7 +188,7 @@
# Add any paths that contain custom static files (such as style sheets) here,
# relative to this directory. They are copied after the builtin static files,
# so a file named "default.css" will overwrite the builtin "default.css".
html_static_path = ["../_static"]
html_static_path = ["../_static", "../thumbnails"]
html_css_files = ["custom.css"]
templates_path = ["../_templates"]
html_sidebars = {
Expand Down
115 changes: 115 additions & 0 deletions examples/gallery.rst
Original file line number Diff line number Diff line change
@@ -0,0 +1,115 @@
Gallery
=======


(Generalized) Linear and Hierarchical Linear Models
-------------------------

.. nbgallery::
:caption: This is a thumbnail gallery:
:name: generalized_linear_models
:glob:
:reversed:

generalized_linear_models/*


Case Studies
------------

.. nbgallery::
:caption: This is a thumbnail gallery:
:name: case_studies
:glob:
:reversed:

case_studies/*

Diagnostics and Model Criticism
-------------------------------

.. nbgallery::
:caption: This is a thumbnail gallery:
:name: diagnostics_and_criticism
:glob:
:reversed:

diagnostics_and_criticism/*


Gaussian Processes
------------------

.. nbgallery::
:caption: This is a thumbnail gallery:
:name: gaussian_processes
:glob:
:reversed:

gaussian_processes/*

Inference in ODE models
-----------------------

.. nbgallery::
:caption: This is a thumbnail gallery:
:name: ode_models
:glob:
:reversed:

ode_models/*

MCMC
----

.. nbgallery::
:caption: This is a thumbnail gallery:
:name: samplers
:glob:
:reversed:

samplers/*

Mixture Models
--------------

.. nbgallery::
:caption: This is a thumbnail gallery:
:name: mixture_models
:glob:
:reversed:

mixture_models/*

Survival Analysis
-----------------

.. nbgallery::
:caption: This is a thumbnail gallery:
:name: survival_analysis
:glob:
:reversed:

survival_analysis/*

Time Series
-----------

.. nbgallery::
:caption: This is a thumbnail gallery:
:name: time_series
:glob:
:reversed:

time_series/*

Variational Inference
---------------------

.. nbgallery::
:caption: This is a thumbnail gallery:
:name: variational_inference
:glob:
:reversed:

variational_inference/*
2 changes: 1 addition & 1 deletion examples/index.md
Original file line number Diff line number Diff line change
Expand Up @@ -74,7 +74,7 @@ has tags in its metadata they are listed on the right sidebar after the {fas}`ta
:::{toctree}
:maxdepth: 1
:hidden:

gallery
blog
object_index/index
:::
2 changes: 2 additions & 0 deletions requirements-docs.txt
Original file line number Diff line number Diff line change
Expand Up @@ -8,3 +8,5 @@ ablog
sphinxext-opengraph
sphinx-codeautolink
sphinx-notfound-page
nbsphinx
sphinx-gallery