jellycell.run.context

Per-cell :class:RunContext delivered via ContextVar.

Spec §2.4: the runner sets this before each cell executes; :mod:jellycell.api reads it to decide between “inside a run” and “standalone” behavior.

For subprocess kernels, this ContextVar lives in the kernel’s Python process (the runner installs a setup prelude that imports this module and calls

func:

set_context). The runner’s own ContextVar tracks its side-of-the-wire state separately.

Module Contents

Classes

RunContext

State available to :mod:jellycell.api during a cell execution.

Functions

get_context

Return the current :class:RunContext or None if outside a run.

set_context

Install ctx as the current :class:RunContext. Returns the reset token.

reset_context

Restore the previous context via the token from :func:set_context.

API

class jellycell.run.context.RunContext

State available to :mod:jellycell.api during a cell execution.

notebook: str

None

Notebook path, relative to project root.

cell_id: str

None

Unique cell identifier within the notebook (e.g., analysis:3).

cell_name: str | None

None

Optional user-assigned name from a name=foo tag.

project: jellycell.paths.Project

None

The active :class:~jellycell.paths.Project.

declared_deps: list[str]

‘field(…)’

Deps declared via jc.deps(...) calls during cell execution.

jellycell.run.context.get_context() jellycell.run.context.RunContext | None

Return the current :class:RunContext or None if outside a run.

jellycell.run.context.set_context(ctx: jellycell.run.context.RunContext | None) contextvars.Token[jellycell.run.context.RunContext | None]

Install ctx as the current :class:RunContext. Returns the reset token.

jellycell.run.context.reset_context(token: contextvars.Token[jellycell.run.context.RunContext | None]) None

Restore the previous context via the token from :func:set_context.