Skip to content

Commit a393382

Browse files
MarcoGorelliMarco Gorelli
andauthored
Check notebooks are in table of contents, bump some hooks (#4197)
* check notebooks are in table of contents * check notebooks are in table of contents * update notebook * :doc: * restrict check-toc to jupyter * 🎨 Co-authored-by: Marco Gorelli <[email protected]>
1 parent 0f7686e commit a393382

File tree

6 files changed

+41
-11
lines changed

6 files changed

+41
-11
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+
types: [jupyter]
32+
entry: python scripts/check_toc_is_complete.py
33+
language: python

docs/source/notebooks/blackbox_external_likelihood.ipynb

Lines changed: 5 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -51,7 +51,7 @@
5151
"import theano\n",
5252
"import theano.tensor as tt\n",
5353
"\n",
54-
"print(\"Running on PyMC3 v{}\".format(pm.__version__))"
54+
"print(f\"Running on PyMC3 v{pm.__version__}\")"
5555
]
5656
},
5757
{
@@ -697,7 +697,7 @@
697697
" color=colors[i],\n",
698698
" hist_kwargs={\"density\": True},\n",
699699
" **hist2dkwargs,\n",
700-
" truths=[mtrue, ctrue]\n",
700+
" truths=[mtrue, ctrue],\n",
701701
" )\n",
702702
" else:\n",
703703
" corner.corner(\n",
@@ -729,15 +729,15 @@
729729
"test_grad_op_func = theano.function([var], test_grad_op(var))\n",
730730
"grad_vals = test_grad_op_func([mtrue, ctrue])\n",
731731
"\n",
732-
"print('Gradient returned by \"LogLikeGrad\": {}'.format(grad_vals))\n",
732+
"print(f'Gradient returned by \"LogLikeGrad\": {grad_vals}')\n",
733733
"\n",
734734
"# test the gradient called through LogLikeWithGrad\n",
735735
"test_gradded_op = LogLikeWithGrad(my_loglike, data, x, sigma)\n",
736736
"test_gradded_op_grad = tt.grad(test_gradded_op(var), var)\n",
737737
"test_gradded_op_grad_func = theano.function([var], test_gradded_op_grad)\n",
738738
"grad_vals_2 = test_gradded_op_grad_func([mtrue, ctrue])\n",
739739
"\n",
740-
"print('Gradient returned by \"LogLikeWithGrad\": {}'.format(grad_vals_2))\n",
740+
"print(f'Gradient returned by \"LogLikeWithGrad\": {grad_vals_2}')\n",
741741
"\n",
742742
"# test the gradient that PyMC3 uses for the Normal log likelihood\n",
743743
"test_model = pm.Model()\n",
@@ -751,7 +751,7 @@
751751
" gradfunc.set_extra_values({\"m_interval__\": mtrue, \"c_interval__\": ctrue})\n",
752752
" grad_vals_pymc3 = gradfunc(np.array([mtrue, ctrue]))[1] # get dlogp values\n",
753753
"\n",
754-
"print('Gradient returned by PyMC3 \"Normal\" distribution: {}'.format(grad_vals_pymc3))"
754+
"print(f'Gradient returned by PyMC3 \"Normal\" distribution: {grad_vals_pymc3}')"
755755
]
756756
},
757757
{

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",

pyproject.toml

Lines changed: 0 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -13,6 +13,3 @@ pyupgrade = 1
1313
[tool.nbqa.addopts]
1414
isort = ["--treat-comment-as-code", "# %%"]
1515
pyupgrade = ["--py36-plus"]
16-
17-
[tool.nbqa.ignore_cells]
18-
black = "%%cython"

scripts/check_toc_is_complete.py

Lines changed: 24 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,24 @@
1+
"""
2+
Check that given Jupyter notebooks all appear in the table of contents.
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+
import argparse
11+
12+
if __name__ == "__main__":
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+
parser = argparse.ArgumentParser()
20+
parser.add_argument("filenames", nargs="*")
21+
args = parser.parse_args()
22+
for file_ in args.filenames:
23+
stem = Path(file_).stem
24+
assert stem in toc_keys, f"Notebook '{stem}' not added to table of contents!"

0 commit comments

Comments
 (0)