Skip to content

Commit

Permalink
DOC: Custom Sphinx extension to invoke Jupytext
Browse files Browse the repository at this point in the history
  • Loading branch information
agriyakhetarpal committed May 9, 2024
1 parent 9316a36 commit 5cab1ec
Showing 1 changed file with 30 additions and 2 deletions.
32 changes: 30 additions & 2 deletions doc/source/conf.py
Original file line number Diff line number Diff line change
Expand Up @@ -23,6 +23,27 @@
except TypeError:
pass

from sphinx.application import Sphinx


def convert_md_to_ipynb(app: Sphinx, *args, **kwargs):
import subprocess
import sys
print("Converting Markdown files to IPyNB...")
print("This may take a while.")
subprocess.check_call(
[
sys.executable,
"-m",
"jupytext",
"--to",
"ipynb",
"doc/source/regression/*.md",
]
)

def setup(app):
app.connect("config-inited", convert_md_to_ipynb)

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

# The suffix of source filenames.
source_suffix = '.rst'
source_suffix = {
'.rst': 'restructuredtext',
'.md': 'myst-nb',
'ipynb': None, # do not parse IPyNB files
}

# The encoding of source files.
source_encoding = 'utf-8'
Expand Down Expand Up @@ -276,7 +301,10 @@

# List of patterns, relative to source directory, that match files and
# directories to ignore when looking for source files.
exclude_patterns = ['substitutions.rst', ]
exclude_patterns = [
'substitutions.rst',
'regression/*.ipynb' # exclude IPyNB files from the build
]

# numpydoc_show_class_members = False
numpydoc_class_members_toctree = False
Expand Down

0 comments on commit 5cab1ec

Please sign in to comment.