Skip to main content

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


Download files

Download the file for your platform. If you're not sure which to choose, learn more about installing packages.

Source Distribution

sphinx_nb_execution_patterns-1.1.0.tar.gz (9.3 kB view details)

Uploaded Source

Built Distribution

If you're not sure about the file name format, learn more about wheel file names.

sphinx_nb_execution_patterns-1.1.0-py3-none-any.whl (6.5 kB view details)

Uploaded Python 3

File details

Details for the file sphinx_nb_execution_patterns-1.1.0.tar.gz.

File metadata

File hashes

Hashes for sphinx_nb_execution_patterns-1.1.0.tar.gz
Algorithm Hash digest
SHA256 d8b99c6393ebfbafe4def3030c0054d1140e6dcf884f09cdd9228c4ffe3bde48
MD5 2b2024e10ae563f9f5a382e3530c9a02
BLAKE2b-256 838908bf2f5609ae728e39456cbacfc5060d4e2a8204a273c8517495973b5c75

See more details on using hashes here.

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

Attestations: Values shown here reflect the state when the release was signed and may no longer be current.

File details

Details for the file sphinx_nb_execution_patterns-1.1.0-py3-none-any.whl.

File metadata

File hashes

Hashes for sphinx_nb_execution_patterns-1.1.0-py3-none-any.whl
Algorithm Hash digest
SHA256 2cc93535c5ffeccb70126fc5f3234bda8b9c78f99bd9cf416ea9d4ea7dd62db8
MD5 15b11501fabbbc4eb51c2da9a824fab6
BLAKE2b-256 ef24a4bbc812400aae41072d7b42f99c8787a097618a1084e7439aa03de3c73d

See more details on using hashes here.

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

Attestations: Values shown here reflect the state when the release was signed and may no longer be current.

Supported by

AWS Cloud computing and Security Sponsor Datadog Monitoring Depot Continuous Integration Fastly CDN Google Download Analytics Pingdom Monitoring Sentry Error logging StatusPage Status page