smalldocs.browser

Prepare notebook downloads and a JupyterLite runner, using imports and a Pyodide disallow list.

imports

source

imports(notebook: dict) -> set[str]

Find imports in Python cells, leaving IPython magic and shell lines out of the parser.

Parameter Type Default Description
notebook dict required The source notebook
returns set[str] Its top-level import names

dependencies

source

dependencies(notebook: dict) -> list[str]

Map imported modules to package names, excluding the standard library and the browser kernel.

Parameter Type Default Description
notebook dict required The source notebook
returns list[str] Sorted distribution names for its imports

lint

source

lint(notebook: dict) -> list[str]

Check the Python kernel, code cells and package disallow list without running code.

Parameter Type Default Description
notebook dict required The source notebook
returns list[str] The reasons it cannot have a browser runner, empty when it passes

with_metadata

source

with_metadata(notebook: dict, packages: list[str]) -> dict

Put generated dependency metadata into a copy of a notebook.

Parameter Type Default Description
notebook dict required The source notebook, which stays unchanged
packages list[str] required The packages found from its imports
returns dict A copy with one generated PEP 723 cell

enabled

source

enabled(site: Site) -> bool

Read the opt-in setting, rejecting values other than true and false.

Parameter Type Default Description
site Site required The site being built
returns bool Whether browser notebooks are turned on

collect

source

collect(site: Site) -> dict[str, dict]

Lint the site’s notebooks and attach passing bundle entries to their pages.

Parameter Type Default Description
site Site required The site whose rendered pages have been discovered
returns dict[str, dict] Eligible notebooks, keyed by their source paths

require_jupyterlite

source

require_jupyterlite() -> None

Check that the optional JupyterLite builder and Pyodide kernel are installed.

build_runtime

source

build_runtime(output: Path) -> None

Build the same static JupyterLite apps and Pyodide kernel used by the website runner.

Parameter Type Default Description
output Path required The lab folder inside the site output

bundle

source

bundle(path: Path, destination: Path, packages: list[str]) -> list[str]

Bundle a notebook copy with the files under its assets and data folders.

Parameter Type Default Description
path Path required The source notebook
destination Path required The generated zip file
packages list[str] required Packages to put in its PEP 723 cell
returns list[str] The paths inside the zip

build

source

build(site: Site, nav: SiteNav, entries: dict[str, dict]) -> None

Write bundles, their manifest, and the themed JupyterLite loading page.

Parameter Type Default Description
site Site required The site being built
nav SiteNav required Its navigation, also used by the themed loading page
entries dict[str, dict] required The passing notebook entries