NotebookRunner#

class mobu.services.business.notebookrunner.NotebookRunner(*, options, user, repo_manager, events, logger, flock)#

Bases: ABC, NubladoBusiness, Generic

Start a Jupyter lab and run a sequence of notebooks.

Parameters:
  • options (TypeVar(T, bound= NotebookRunnerOptions)) – Configuration options for the business.

  • user (AuthenticatedUser) – User with their authentication token to use to run the business.

  • events (Events) – Event publishers.

  • logger (BoundLogger) – Logger to use to report the results of business.

  • flock (str | None) – Flock that is running this business, if it is running in a flock.

  • repo_manager (RepoManager)

Methods Summary

cleanup()

common_notebook_event_attrs()

Return notebook event attrs with the other common attrs.

dump()

execute_cell(session, code, cell_id, context)

execute_code(session)

Run a set number of notebooks (flocks), or all available (CI).

execute_notebook(session, iteration)

execution_iterator()

Return an iterator to control sets of code executions.

find_notebooks()

initialize()

Prepare to run the business.

next_notebook()

notebook_idle()

Pause between each notebook execution.

open_session([notebook_name])

Override to add the notebook name.

read_notebook(notebook)

refresh()

shutdown()

Perform any cleanup required after stopping.

startup()

Run before the start of the first iteration and then not again.

trace_notebook(notebook, iteration)

Set up tracing context for executing a notebook.

Methods Documentation

async cleanup()#
Return type:

None

common_notebook_event_attrs()#

Return notebook event attrs with the other common attrs.

Return type:

_CommonNotebookEventAttrs

dump()#
Return type:

NotebookRunnerData

async execute_cell(session, code, cell_id, context)#
Parameters:
  • session (JupyterLabSession)

  • code (str)

  • cell_id (str)

  • context (CodeContext)

Return type:

None

async execute_code(session)#

Run a set number of notebooks (flocks), or all available (CI).

Parameters:

session (JupyterLabSession)

Return type:

None

async execute_notebook(session, iteration)#
Parameters:
  • session (JupyterLabSession)

  • iteration (str)

Return type:

None

abstract execution_iterator()#

Return an iterator to control sets of code executions.

Return type:

ExecutionIteration

find_notebooks()#
Return type:

set[Path]

async initialize()#

Prepare to run the business. :rtype: None

  • Get notebook repo files from the repo manager

  • Parse the in-repo config

  • Filter the notebooks

next_notebook()#
Return type:

Path

async notebook_idle()#

Pause between each notebook execution.

Return type:

bool

open_session(notebook_name=None)#

Override to add the notebook name.

Parameters:

notebook_name (str | None, default: None)

Return type:

AsyncGenerator[JupyterLabSession]

read_notebook(notebook)#
Parameters:

notebook (Path)

Return type:

list[dict[str, Any]]

async refresh()#
Return type:

None

async shutdown()#

Perform any cleanup required after stopping.

Return type:

None

async startup()#

Run before the start of the first iteration and then not again.

Return type:

None

trace_notebook(notebook, iteration)#

Set up tracing context for executing a notebook.

Parameters:
  • notebook (str)

  • iteration (str)

Return type:

Iterator[Transaction | Span]