Skip to content

Commit b153fbe

Browse files
Marco GorelliMarcoGorelli
authored andcommitted
check notebooks are in table of contents
1 parent 95accbd commit b153fbe

File tree

4 files changed

+34
-3
lines changed

4 files changed

+34
-3
lines changed

.pre-commit-config.yaml

Lines changed: 8 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -1,17 +1,17 @@
11
repos:
22
- repo: https://github.com/pre-commit/pre-commit-hooks
3-
rev: v3.2.0
3+
rev: v3.3.0
44
hooks:
55
- id: end-of-file-fixer
66
- id: check-toml
77
- repo: https://github.com/nbQA-dev/nbQA
8-
rev: 0.3.2
8+
rev: 0.3.5
99
hooks:
1010
- id: nbqa-black
1111
- id: nbqa-isort
1212
- id: nbqa-pyupgrade
1313
- repo: https://github.com/asottile/pyupgrade
14-
rev: v2.7.2
14+
rev: v2.7.3
1515
hooks:
1616
- id: pyupgrade
1717
args: [--py36-plus]
@@ -26,3 +26,8 @@ repos:
2626
types: [jupyter]
2727
entry: python scripts/check_watermark.py
2828
language: python
29+
- id: check-toc
30+
name: Check all notebooks appear in table of contents
31+
entry: python scripts/check_toc_is_complete.py
32+
language: python
33+
pass_filenames: false

docs/source/notebooks/table_of_contents_examples.js

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -34,6 +34,7 @@ Gallery.contents = {
3434
"gaussian_process": "Gaussian Processes",
3535
"conditional-autoregressive-model": "Gaussian Processes",
3636
"log-gaussian-cox-process":"Gaussian Processes",
37+
"GP-Circular": "Gaussian Processes",
3738
"dependent_density_regression": "Mixture Models",
3839
"dp_mix": "Mixture Models",
3940
"gaussian-mixture-model-advi": "Mixture Models",
@@ -59,6 +60,7 @@ Gallery.contents = {
5960
"ODE_with_manual_gradients": "Inference in ODE models",
6061
"ODE_API_introduction": "Inference in ODE models",
6162
"probabilistic_matrix_factorization": "Case Studies",
63+
"MLDA_introduction": "MCMC",
6264
"MLDA_simple_linear_regression": "MCMC",
6365
"MLDA_gravity_surveying": "MCMC",
6466
"MLDA_variance_reduction_linear_regression": "MCMC"

docs/source/notebooks/table_of_contents_tutorials.js

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -6,13 +6,15 @@ Gallery.contents = {
66
"Gaussian_Processes.rst": "Basics",
77
"data_container": "Basics",
88
"sampling_compound_step": "Deep dives",
9+
"sampling_callback": "Deep dives",
910
"sampler-stats": "Deep dives",
1011
"Diagnosing_biased_Inference_with_Divergences": "Deep dives",
1112
"Advanced_usage_of_Theano_in_PyMC3.rst": "Deep dives",
1213
"getting_started": "Deep dives",
1314
"ODE_API_shapes_and_benchmarking": "Deep dives",
1415
"DEMetropolisZ_EfficiencyComparison": "Deep dives",
1516
"DEMetropolisZ_tune_drop_fraction": "Deep dives",
17+
"factor_analysis": "Deep dives",
1618
"blackbox_external_likelihood": "How-To",
1719
"profiling": "How-To",
1820
"howto_debugging": "How-To",

scripts/check_toc_is_complete.py

Lines changed: 22 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,22 @@
1+
"""
2+
Check that given Jupyter notebooks all contain a final watermark cell to facilite reproducibility.
3+
4+
This is intended to be used as a pre-commit hook, see `.pre-commit-config.yaml`.
5+
You can run it manually with `pre-commit run check-toc --all`.
6+
"""
7+
8+
import json
9+
from pathlib import Path
10+
11+
if __name__ == "__main__":
12+
notebooks = (Path("docs") / "source/notebooks").glob("*.ipynb")
13+
toc_examples = (Path("docs") / "source/notebooks/table_of_contents_examples.js").read_text()
14+
toc_tutorials = (Path("docs") / "source/notebooks/table_of_contents_tutorials.js").read_text()
15+
toc_keys = {
16+
**json.loads(toc_examples[toc_examples.find("{") :]),
17+
**json.loads(toc_tutorials[toc_tutorials.find("{") :]),
18+
}.keys()
19+
for notebook in notebooks:
20+
assert (
21+
notebook.stem in toc_keys
22+
), f"Notebook {notebook.name} not added to table of contents!"

0 commit comments

Comments
 (0)