Skip to content

Commit a77395c

Browse files
committed
docs
1 parent 62c1a0e commit a77395c

5 files changed

Lines changed: 228 additions & 344 deletions

File tree

.readthedocs.yml

Lines changed: 7 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -7,12 +7,17 @@ version: 2
77

88
# Set the version of Python and other tools you might need
99
build:
10-
os: ubuntu-20.04
10+
os: ubuntu-22.04
1111
tools:
1212
python: "3.11"
1313
jobs:
1414
pre_build:
15-
- cp examples/*ipynb docs/source/examples/
15+
# Mirror authoritative notebooks from examples/ into docs/source/examples/
16+
# so Sphinx finds them. `docs/source/examples/*.ipynb` is gitignored.
17+
# The same copy also runs from docs/source/conf.py for local builds.
18+
- mkdir -p docs/source/examples
19+
- cp -fv examples/*.ipynb docs/source/examples/
20+
- ls -la docs/source/examples/
1621

1722
# Build documentation in the docs/ directory with Sphinx
1823
sphinx:

docs/source/conf.py

Lines changed: 19 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -5,18 +5,29 @@
55

66

77
def _sync_example_notebooks(app):
8-
"""Copy every *.ipynb from the repo examples/ dir into docs/source/examples/.
8+
"""Copy every *.ipynb from the repo ``examples/`` dir into
9+
``docs/source/examples/`` so Sphinx can find them.
910
10-
This keeps the docs in sync with the authoritative source notebooks without
11-
requiring a manual copy step. The ReadTheDocs pre_build step in
12-
.readthedocs.yaml also does this, but running it here means local ``make
13-
docs`` builds are always up to date as well.
11+
``docs/source/examples/*.ipynb`` is gitignored — the authoritative copies
12+
live in ``examples/``. Running this at every Sphinx build keeps the docs
13+
in sync, both locally (``make docs``) and on ReadTheDocs (in addition to
14+
the pre_build ``cp`` step in ``.readthedocs.yml``).
15+
16+
We use ``shutil.copy`` (not ``copy2``) so the destination mtime is updated
17+
to ``now`` — this guarantees Sphinx's incremental build sees the file as
18+
changed and re-renders it instead of using a cached ``.doctree``.
1419
"""
1520
src = Path(app.srcdir).parent.parent / "examples"
1621
dst = Path(app.srcdir) / "examples"
17-
dst.mkdir(exist_ok=True)
18-
for nb in src.glob("*.ipynb"):
19-
shutil.copy2(nb, dst / nb.name)
22+
if not src.is_dir():
23+
print(f"[conf.py] WARNING: examples source dir not found: {src}")
24+
return
25+
dst.mkdir(parents=True, exist_ok=True)
26+
copied = []
27+
for nb in sorted(src.glob("*.ipynb")):
28+
shutil.copy(nb, dst / nb.name)
29+
copied.append(nb.name)
30+
print(f"[conf.py] Synced {len(copied)} notebook(s) from {src} -> {dst}: {copied}")
2031

2132

2233
def setup(app):

0 commit comments

Comments
 (0)