Python API#

Module enforce_notebook_run_order#

Validates notebooks were executed sequentially.

The tool inspects existing execution_count values of non-empty code cells and raises an error if: - Any code cell was not executed (execution_count is None) - The first non-empty code cell does not start from execution_count=1 - Execution counts are not strictly sequential (must increase by exactly 1) - There are gaps in the execution sequence (e.g., 1, 2, 4 with 3 missing)

It does not execute notebooks or inspect outputs.

exception enforce_notebook_run_order.enforce_notebook_run_order.InvalidNotebookRunError#

Raised when any problems were identified with a notebook’s run order

exception enforce_notebook_run_order.enforce_notebook_run_order.NotebookCodeCellNotRunError#

Raised when a notebook code cell was not run

exception enforce_notebook_run_order.enforce_notebook_run_order.NotebookRunOrderError#

Raised when a notebook is run out of order

enforce_notebook_run_order.enforce_notebook_run_order.check_notebook_run_order(notebook_data: Dict) None#

Checks that the notebook cells were run sequentially and fails if not.

Enforces that all non-empty code cells must have been executed (execution_count is not None), execution must start from 1 (first non-empty code cell must have execution_count=1), and execution must be strictly sequential without gaps (1, 2, 3, … with no skipped numbers).

Args:

notebook_data (Dict): Notebook data in dictionary format.

Raises:

NotebookCodeCellNotRunError: If a code cell in the notebook was not run. NotebookRunOrderError: If the cells in the notebook were not run sequentially,

including if they don’t start from 1 or have gaps in the sequence.

enforce_notebook_run_order.enforce_notebook_run_order.check_single_notebook(notebook_path: str) None#

Check a single notebook for sequential execution.

Args:

notebook_path (str): Path to the notebook file.

Raises:

InvalidNotebookRunError: If any problems were identified with the notebook’s run order.

enforce_notebook_run_order.enforce_notebook_run_order.process_path(path: str) None#

Process a path to a notebook file or directory recursively.

Args:

path (str): Path to a single .ipynb file or a directory containing notebooks.

Raises:

ValueError: If the path is neither a directory nor a .ipynb file.

Module utils#

Contains shared functionality used across multiple modules

enforce_notebook_run_order.utils.get_code_cells(notebook_data: Dict) List[Dict]#

Returns a list of code cells from the notebook data.

Args:

notebook_data (Dict): Notebook data in dictionary format.

Returns:

List[Dict]: List of code cells from the notebook.

enforce_notebook_run_order.utils.load_notebook_data(notebook_path: str) Dict#

Loads the notebook data from the given path.

Args:

notebook_path (str): Path to the notebook file.

Returns:

Dict: Notebook data in dictionary format.