Skip to content

Commit 533ca3c

Browse files
DOC: Custom Sphinx extension to invoke Jupytext
1 parent 5e1623b commit 533ca3c

File tree

1 file changed

+35
-2
lines changed

1 file changed

+35
-2
lines changed

doc/source/conf.py

Lines changed: 35 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -12,6 +12,7 @@
1212

1313
import datetime
1414
import importlib.metadata
15+
from pathlib import Path
1516

1617
import jinja2.filters
1718
import numpy as np
@@ -23,6 +24,29 @@
2324
except TypeError:
2425
pass
2526

27+
from sphinx.application import Sphinx
28+
29+
HERE = Path(__file__).parent
30+
31+
32+
def convert_md_to_ipynb(app: Sphinx, *args, **kwargs):
33+
import subprocess
34+
import sys
35+
print("Converting Markdown files to IPyNB...")
36+
subprocess.check_call(
37+
[
38+
sys.executable,
39+
"-m",
40+
"jupytext",
41+
"--to",
42+
"ipynb",
43+
f"{HERE / "regression" / "*.md"}",
44+
]
45+
)
46+
47+
48+
def setup(app):
49+
app.connect("builder-inited", convert_md_to_ipynb)
2650

2751
# If extensions (or modules to document with autodoc) are in another directory,
2852
# add these directories to sys.path here. If the directory is relative to the
@@ -53,7 +77,11 @@
5377
templates_path = ['_templates']
5478

5579
# The suffix of source filenames.
56-
source_suffix = '.rst'
80+
source_suffix = {
81+
'.rst': 'restructuredtext',
82+
'.md': 'myst-nb',
83+
'ipynb': None, # do not parse IPyNB files
84+
}
5785

5886
# The encoding of source files.
5987
source_encoding = 'utf-8'
@@ -276,7 +304,10 @@
276304

277305
# List of patterns, relative to source directory, that match files and
278306
# directories to ignore when looking for source files.
279-
exclude_patterns = ['substitutions.rst', ]
307+
exclude_patterns = [
308+
'substitutions.rst',
309+
'regression/*.ipynb' # exclude IPyNB files from the build
310+
]
280311

281312
# numpydoc_show_class_members = False
282313
numpydoc_class_members_toctree = False
@@ -297,6 +328,8 @@
297328

298329
# -- Options for JupyterLite -------------------------------------------------
299330

331+
jupyterlite_silence = False
332+
300333
global_enable_try_examples = True
301334
try_examples_global_button_text = "Try it in your browser!"
302335
try_examples_global_warning_text = (

0 commit comments

Comments
 (0)