Skip to content

Commit 07a0926

Browse files
DOC: Use the jupytext API instead of its CLI
1 parent 1f4bd32 commit 07a0926

File tree

1 file changed

+10
-13
lines changed

1 file changed

+10
-13
lines changed

doc/source/conf.py

Lines changed: 10 additions & 13 deletions
Original file line numberDiff line numberDiff line change
@@ -34,21 +34,18 @@ def preprocess_notebooks(app: Sphinx, *args, **kwargs):
3434
"""Preprocess Markdown notebooks to convert them to IPyNB format
3535
and remove cells tagged with 'ignore-when-converting' metadata."""
3636

37-
import subprocess
38-
import sys
37+
import jupytext
38+
import nbformat
39+
3940
print("Converting Markdown files to IPyNB...")
40-
subprocess.check_call(
41-
[
42-
sys.executable,
43-
"-m",
44-
"jupytext",
45-
"--to",
46-
"ipynb",
47-
f"{HERE / 'regression' / '*.md'}",
48-
]
49-
)
41+
for path in (HERE / "regression").glob("*.md"):
42+
nb = jupytext.read(str(path))
43+
nb.cells = [cell for cell in nb.cells if "true" not in cell.metadata.get("ignore-when-converting", [])]
44+
ipynb_path = path.with_suffix(".ipynb")
45+
with open(ipynb_path, "w") as f:
46+
nbformat.write(nb, f)
47+
print(f"Converted {path} to {ipynb_path}")
5048

51-
import nbformat
5249

5350
for path in (HERE / "regression").glob("*.ipynb"):
5451
with open(path) as f:

0 commit comments

Comments
 (0)