bokeh.application.handlers.code_runner

Provide a utility class CodeRunner for use by handlers that execute Python source code.

class CodeRunner(source: str, path: Union[str, os.PathLike[str]], argv: List[str], package: Optional[module] = None)[source]

Compile and run Python source code.

Public Data Attributes:

doc

Contents of docstring, if code contains one.

error

If code execution fails, may contain a related error message.

error_detail

If code execution fails, may contain a traceback or other details.

failed

True if code execution failed

path

The path that new modules will be configured with.

source

The configured source code that will be executed when run is called.

Public Methods:

__init__(source, path, argv[, package])

param source

A string containing Python source code to execute

new_module()

Make a fresh module to run in.

reset_run_errors()

Clears any transient error conditions from a previous run.

run(module[, post_check])

Execute the configured source code in a module and run any post checks.


__init__(source: str, path: Union[str, os.PathLike[str]], argv: List[str], package: Optional[module] = None) None[source]
Parameters
  • source (str) – A string containing Python source code to execute

  • path (str) – A filename to use in any debugging or error output

  • argv (list[str]) – A list of string arguments to make available as sys.argv when the code executes

  • package (bool) – An optional package module to configure

Raises

ValueError, if package is specified for an __init__.py

new_module() module | None[source]

Make a fresh module to run in.

Returns

Module

reset_run_errors() None[source]

Clears any transient error conditions from a previous run.

Returns

None

run(module: module, post_check: Optional[Callable[[], None]] = None) None[source]

Execute the configured source code in a module and run any post checks.

Parameters
  • module (Module) – A module to execute the configured code in.

  • post_check (callable, optional) – A function that raises an exception if expected post-conditions are not met after code execution.

property doc: str | None

Contents of docstring, if code contains one.

property error: str | None

If code execution fails, may contain a related error message.

property error_detail: str | None

If code execution fails, may contain a traceback or other details.

property failed: bool

True if code execution failed

property path: Union[str, os.PathLike[str]]

The path that new modules will be configured with.

property source: str

The configured source code that will be executed when run is called.