Skip to main content

Module env

Module env 

Source
Expand description

A project’s environments for its scripts: what Python runs them, with which packages, and which Rust toolchain builds them. The project folder holds them, so a project (and a pipeline built in it) runs the same on another computer:

scripts/
  pyproject.toml  uv.lock  .venv/               Python: the packages, locked; the environment
  Cargo.toml  Cargo.lock  rust-toolchain.toml   Rust: the crates, locked; the toolchain
  • Python runs with the environment’s own interpreter (.venv/bin/python): the project’s .venv, else the one activated ($VIRTUAL_ENV), else the app’s default environment. uv makes and syncs it from pyproject.toml and uv.lock (sync_python); the lock, not the .venv, is what travels (a .venv names its base interpreter, so it is made again elsewhere).
  • Rust has no environment to activate: Cargo.toml and Cargo.lock are the crates, and rust-toolchain.toml pins the toolchain (rustup reads it from the folder Cargo runs in). ensure_rust writes them; builds share one target folder.

Structs§

PythonEnv
A Python environment (a venv).

Enums§

PythonSource
Where a Python environment comes from.

Functions§

add_python
Adds packages to the environment in dir (uv add: pyproject.toml, uv.lock and the .venv together).
ensure_rust
Makes dir a Rust environment when it is not one yet: a Cargo workspace whose members are the scripts’ crates (members, globs allowed), and rust-toolchain.toml pinning the compiler found now. The lock (Cargo.lock) is written by the first build. Returns the toolchain pinned.
rust_toolchain
The Rust toolchain a folder pins (channel of its rust-toolchain.toml).
rustc_version
The version of the Rust compiler found (1.95.0), the one a new pin names.
sync_python
Makes or updates the Python environment in dir with uv: writes pyproject.toml first when there is none (with packages, the app’s own needs such as NumPy), then uv sync (the .venv matching uv.lock, made when missing). Returns uv’s report.
uv
uv, if found: $UV, the PATH, then where its installer puts it.
venv_python
The interpreter inside the venv at root, if there is one.