A Sphinx extension to execute Jupyter NoteBooks based on include and exclude patterns instead of only exclude patterns.
Project description
Sphinx extension: NoteBook Execution Patterns
Introduction
A Sphinx extension to execute Jupyter NoteBooks (*.ipynb) and Text-based NoteBooks (*.md) based on include and exclude patterns instead of only exclude patterns.
This extension also applies the mystnb patch from JupyterBook-Patches.
Installation
To install the Sphinx-NB-Execution-Patterns extension, follow these steps:
Step 1: Install the Package
Install the Sphinx-NB-Execution-Patterns package using pip:
pip install sphinx-nb-execution-patterns
Step 2: Add to requirements.txt
Make sure that the package is included in your project's requirements.txt to track the dependency:
sphinx-nb-execution-patterns
Step 3: Enable in _config.yml
In your _config.yml file, add the extension to the list of Sphinx extra extensions:
sphinx:
extra_extensions:
- sphinx_nb_execution_patterns
Configuration
You can configure the extension in your _config.yml file. Here are the available options:
nb_execution_includepatterns: A list of glob patterns to indicate notebooks that must be included for execution. Default is an empty list.nb_execution_patterns_method: Sets the method used when both include and exclude patterns are provided. Allowed values are:only_include(default): Notebooks matching the include patterns are executed. All exclude patterns are ignored.only_exclude: Notebooks matching the exclude patterns are excluded from execution, all other notebooks are executed. All include patterns are ignored. This method is equivalent to the default behavior of JupyterBook/Sphinx.exclude_include: Notebooks matching the exclude patterns are excluded from execution, unless they also match the include patterns. All other notebooks are executed.include_exclude: Notebooks matching the include patterns are executed, unless they also match the exclude patterns.
This extension will only have an effect if include patterns are provided.
[!NOTE] Exclude patterns are supported by JupyterBook out-of-the-box. See the JupyterBook documentation for more details. Sphinx also supports exclude patterns natively. See the Sphinx documentation for more details. If both the JupyterBook and Sphinx syntax are used, the Sphinx syntax will take precedence.
Example Configuration
Here is an example configuration in _config.yml using both include and exclude patterns and JupyterBook syntax:
execute:
execute_notebooks: auto
exclude_patterns:
- "*NB1*"
sphinx:
config:
nb_execution_includepatterns:
- "*sol.ipynb"
nb_execution_patterns_method: "include_exclude"
Here is the same example configuration in _config.yml using Sphinx syntax:
sphinx:
config:
nb_execution_mode: "auto"
nb_execution_excludepatterns:
- "*NB1*"
nb_execution_includepatterns:
- "*sol.ipynb"
nb_execution_patterns_method: "include_exclude"
For the given example, all notebooks matching *sol.ipynb will be executed, unless they also match *NB1*.
If nb_execution_patterns_method is set to only_include, all notebooks matching *sol.ipynb will be executed, and the exclude pattern will be ignored.
If nb_execution_patterns_method is set to only_exclude, all notebooks matching *sol.ipynb will be excluded from execution, all other notebooks are executed, and the include pattern will be ignored.
If nb_execution_patterns_method is set to exclude_include, all notebooks matching *NB1* will be excluded from execution, unless they also match *sol.ipynb. All other notebooks will be executed.
Contribute
This tool's repository is stored on GitHub. If you'd like to contribute, you can create a fork and open a pull request on the GitHub repository.
The README.md of the branch Manual is also part of the TeachBooks manual.
Project details
Release history Release notifications | RSS feed
Download files
Download the file for your platform. If you're not sure which to choose, learn more about installing packages.
Source Distribution
Built Distribution
Filter files by name, interpreter, ABI, and platform.
If you're not sure about the file name format, learn more about wheel file names.
Copy a direct link to the current filters
File details
Details for the file sphinx_nb_execution_patterns-1.1.0.tar.gz.
File metadata
- Download URL: sphinx_nb_execution_patterns-1.1.0.tar.gz
- Upload date:
- Size: 9.3 kB
- Tags: Source
- Uploaded using Trusted Publishing? Yes
- Uploaded via: twine/6.1.0 CPython/3.13.7
File hashes
| Algorithm | Hash digest | |
|---|---|---|
| SHA256 |
d8b99c6393ebfbafe4def3030c0054d1140e6dcf884f09cdd9228c4ffe3bde48
|
|
| MD5 |
2b2024e10ae563f9f5a382e3530c9a02
|
|
| BLAKE2b-256 |
838908bf2f5609ae728e39456cbacfc5060d4e2a8204a273c8517495973b5c75
|
Provenance
The following attestation bundles were made for sphinx_nb_execution_patterns-1.1.0.tar.gz:
Publisher:
python-publish.yml on TeachBooks/Sphinx-NB-Execution-Patterns
-
Statement:
-
Statement type:
https://in-toto.io/Statement/v1 -
Predicate type:
https://docs.pypi.org/attestations/publish/v1 -
Subject name:
sphinx_nb_execution_patterns-1.1.0.tar.gz -
Subject digest:
d8b99c6393ebfbafe4def3030c0054d1140e6dcf884f09cdd9228c4ffe3bde48 - Sigstore transparency entry: 804650980
- Sigstore integration time:
-
Permalink:
TeachBooks/Sphinx-NB-Execution-Patterns@192a810eb53eda66fe53a73a29f321c12cfe05fa -
Branch / Tag:
refs/tags/v1.1.0 - Owner: https://github.com/TeachBooks
-
Access:
public
-
Token Issuer:
https://token.actions.githubusercontent.com -
Runner Environment:
github-hosted -
Publication workflow:
python-publish.yml@192a810eb53eda66fe53a73a29f321c12cfe05fa -
Trigger Event:
push
-
Statement type:
File details
Details for the file sphinx_nb_execution_patterns-1.1.0-py3-none-any.whl.
File metadata
- Download URL: sphinx_nb_execution_patterns-1.1.0-py3-none-any.whl
- Upload date:
- Size: 6.5 kB
- Tags: Python 3
- Uploaded using Trusted Publishing? Yes
- Uploaded via: twine/6.1.0 CPython/3.13.7
File hashes
| Algorithm | Hash digest | |
|---|---|---|
| SHA256 |
2cc93535c5ffeccb70126fc5f3234bda8b9c78f99bd9cf416ea9d4ea7dd62db8
|
|
| MD5 |
15b11501fabbbc4eb51c2da9a824fab6
|
|
| BLAKE2b-256 |
ef24a4bbc812400aae41072d7b42f99c8787a097618a1084e7439aa03de3c73d
|
Provenance
The following attestation bundles were made for sphinx_nb_execution_patterns-1.1.0-py3-none-any.whl:
Publisher:
python-publish.yml on TeachBooks/Sphinx-NB-Execution-Patterns
-
Statement:
-
Statement type:
https://in-toto.io/Statement/v1 -
Predicate type:
https://docs.pypi.org/attestations/publish/v1 -
Subject name:
sphinx_nb_execution_patterns-1.1.0-py3-none-any.whl -
Subject digest:
2cc93535c5ffeccb70126fc5f3234bda8b9c78f99bd9cf416ea9d4ea7dd62db8 - Sigstore transparency entry: 804650981
- Sigstore integration time:
-
Permalink:
TeachBooks/Sphinx-NB-Execution-Patterns@192a810eb53eda66fe53a73a29f321c12cfe05fa -
Branch / Tag:
refs/tags/v1.1.0 - Owner: https://github.com/TeachBooks
-
Access:
public
-
Token Issuer:
https://token.actions.githubusercontent.com -
Runner Environment:
github-hosted -
Publication workflow:
python-publish.yml@192a810eb53eda66fe53a73a29f321c12cfe05fa -
Trigger Event:
push
-
Statement type: