Skip to content

Commit

Permalink
DOC: Use the jupytext API instead of its CLI
Browse files Browse the repository at this point in the history
  • Loading branch information
agriyakhetarpal committed Jun 7, 2024
1 parent 1f4bd32 commit 07a0926
Showing 1 changed file with 10 additions and 13 deletions.
23 changes: 10 additions & 13 deletions doc/source/conf.py
Original file line number Diff line number Diff line change
Expand Up @@ -34,21 +34,18 @@ def preprocess_notebooks(app: Sphinx, *args, **kwargs):
"""Preprocess Markdown notebooks to convert them to IPyNB format
and remove cells tagged with 'ignore-when-converting' metadata."""

import subprocess
import sys
import jupytext
import nbformat

print("Converting Markdown files to IPyNB...")
subprocess.check_call(
[
sys.executable,
"-m",
"jupytext",
"--to",
"ipynb",
f"{HERE / 'regression' / '*.md'}",
]
)
for path in (HERE / "regression").glob("*.md"):
nb = jupytext.read(str(path))
nb.cells = [cell for cell in nb.cells if "true" not in cell.metadata.get("ignore-when-converting", [])]
ipynb_path = path.with_suffix(".ipynb")
with open(ipynb_path, "w") as f:
nbformat.write(nb, f)
print(f"Converted {path} to {ipynb_path}")

import nbformat

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

0 comments on commit 07a0926

Please sign in to comment.