jupyter_notebook_binary
Rules
jupyter_notebook_binary
load("@rules_jupyter//jupyter:jupyter_notebook_binary.bzl", "jupyter_notebook_binary")
jupyter_notebook_binary(name, data, cwd_mode, env, env_inherit, exporter_args, notebook, out_dir,
reports)
An executable rule that runs a Jupyter notebook and optionally generates reports.
Unlike jupyter_notebook_test, this rule creates an executable target for use with bazel run.
Outputs (executed notebook and reports) are written to a configurable output directory, defaulting
to the caller's working directory (BUILD_WORKING_DIRECTORY).
Example:
jupyter_notebook(
name = "my_notebook",
src = "notebook.py",
deps = ["@pip_deps//polars"],
)
jupyter_notebook_binary(
name = "run_notebook",
notebook = ":my_notebook",
reports = ["html"],
)
Then run: bazel run :run_notebook or bazel run :run_notebook -- --my-flag value
ATTRIBUTES
| Name | Description | Type | Mandatory | Default |
|---|---|---|---|---|
| name | A unique name for this target. | Name | required | |
| data | Additional data files required by the notebook (e.g., input data files, images, configuration files). | List of labels | optional | [] |
| cwd_mode | The working directory mode for notebook execution. If not specified, uses the toolchain's default_cwd. execution_root sets the working directory to the workspace root, while notebook_root sets it to the notebook's parent directory. This affects how relative paths in the notebook are resolved. | String | optional | "" |
| env | Environment variables to set when executing the notebook. Values support location expansion (e.g., $(location :target)). | Dictionary: String -> String | optional | {} |
| env_inherit | Specifies additional environment variables to inherit from the external environment. | List of strings | optional | [] |
| exporter_args | Traitlets-style flags forwarded to nbconvert exporters (e.g. --WebPDFExporter.exclude_input=true). | List of strings | optional | [] |
| notebook | The notebook to execute. Must be a jupyter_notebook target. | Label | required | |
| out_dir | Directory to write output files to. If not specified, outputs are written to a subdirectory named after the target under the caller's working directory (e.g., bazel run :run_notebook writes to ./run_notebook/). Absolute paths (e.g., /tmp) are used as-is; relative paths are resolved against the caller's working directory. | String | optional | "" |
| reports | List of report types to generate after successful notebook execution. Valid values: 'html', 'markdown', 'latex', 'webpdf'. | List of strings | optional | [] |