Skip to content

local_env

The environment of a local run with snapshots: a venv of the run.

A run of the local backend with snapshots (--snapshot) must not install them into the environment of the service, the one of the user. The backend creates a venv per run in .simrun/envs/<run>/venv, which sees the packages of the service through a path file (BASE_PTH), installs the snapshots into it as editable packages from shadow trees in .simrun/envs/<run>/sources/ (simrun.worker.shadow_tree), and starts the harness with its python; a command task finds it first on PATH. The venv is removed at the end of the run.

The snapshots are installed without their dependencies, which the environment of the service has, with uv (on PATH or the uv package), else with pip; their build backends come from the index or the cache of the installer, as for any build.

BASE_PTH module-attribute

BASE_PTH = '~simrun-base.pth'

The path file of the packages of the service in the venv of a run; named to sort after the path files of the snapshots (site reads them in the order of their names), so a snapshot comes before the same package of the service.

RunEnvironmentError

Bases: RuntimeError

The venv of a run cannot be created or the snapshots cannot be installed.

base_site_dirs

base_site_dirs()

The site directories of this interpreter, the user site when enabled.

installer

installer(python)

The command which installs into the venv of python, before its arguments.

Raises:

Type Description
RunEnvironmentError

Neither uv nor pip is installed.

create

create(directory, snapshots, log, cancelled=lambda: False)

Create the venv of a run and install its snapshots into it.

Parameters:

Name Type Description Default
directory Path

The directory of the environment of the run, replaced.

required
snapshots list[str]

The paths of the snapshots.

required
log BinaryIO

Where the output of the installer goes.

required
cancelled Callable[[], bool]

Polled while the installer runs; when it holds, the installer is killed.

lambda: False

Returns:

Type Description
Path

The python of the venv.

Raises:

Type Description
RunEnvironmentError

The venv cannot be created, there is no installer, or the installation failed or was cancelled.