Context#
Lazy workspace context for conda state and platform introspection.
Workspace context — lazy properties for conda & workspace state.
Provides a namespace of lazily-evaluated properties that downstream code can use without importing conda at module level. This keeps import-time overhead negligible.
- class conda_workspaces.context.CondaContext(manifest_path: Path | None = None)[source]#
Lazy-evaluated namespace exposed as
conda.*in task templates.Attribute access is deferred so conda internals load only when a template references a variable.
- property environment: _EnvironmentProxy#
Allows
{{ conda.environment.name }}in templates.
- property environment_name: str#
Name of the currently active conda environment, or
"base".
- property init_cwd: str#
The working directory at the time of context creation.
- property is_linux: bool#
True when the host platform is Linux.
- property is_osx: bool#
True when the host platform is macOS.
- property is_unix: bool#
True when running on a Unix-like system (Linux or macOS).
- property is_win: bool#
True when running on Windows.
- property manifest_path: str#
Path to the task definition file, or empty string if unknown.
- property platform: str#
The conda platform/subdir string, e.g.
linux-64orosx-arm64.
- property prefix: str#
Absolute path to the target conda environment prefix.
- property version: str#
The installed conda version string.
- class conda_workspaces.context.WorkspaceContext(config: WorkspaceConfig | None = None)[source]#
Lazy-evaluated context for the current workspace.
Properties are resolved on first access and cached. Conda imports are deferred to keep plugin load time under 1 ms.
- property config: WorkspaceConfig#
The parsed workspace configuration.
- property envs_dir: Path#
Directory where project-local environments are stored.
- envs_from_lockfile(env_name: str, *, requested_platforms: tuple[str, ...] = ()) list[Environment][source]#
Load
Environmentobjects from the workspaceconda.lock.Delegates to
CondaLockLoader, the same entry point conda uses when it reads--file conda.lockthroughEnvironment.from_cli_with_file_envs().When requested_platforms is empty, every platform present in the lockfile is returned. Otherwise the list is filtered and
PlatformErroris raised for any requested platform the lockfile does not contain.
- envs_from_manifest(env_name: str, *, requested_platforms: tuple[str, ...] = ()) list[Environment][source]#
Build
Environmentobjects from the workspace manifest.Produces an
Environmentper target platform withrequested_packagespopulated from the manifest’s declared specs (no solver, no installed packages required) — the novel capability ofconda workspace exportvs.conda export, which always operates on an installed prefix. When the manifest declares platforms conda doesn’t know, falls back toplatformso the export still produces something useful rather than crashing on validation.This is the natural entry point for third-party exporter plugins (or other tooling) that want to turn a
conda.tomlinto a list ofEnvironmentobjects without going through the CLI.
- envs_from_prefix(env_name: str, *, requested_platforms: tuple[str, ...] = (), from_history: bool = False, no_builds: bool = False, ignore_channels: bool = False) list[Environment][source]#
Build
Environmentobjects from an installed workspace prefix.Thin wrapper around the same
Environment.from_prefix()+Environment.extrapolate()pair thatconda.cli.main_export.execute()uses; the only workspace-specific pieces are the prefix lookup (env_prefix()) and theEnvironmentNotInstalledErrorguard.When requested_platforms is empty or equals
(self.platform,), a singleEnvironmentfor the host platform is returned. Otherwise oneEnvironmentper requested platform is produced viaEnvironment.extrapolate().
- property platform: str#
Current conda subdir (e.g.
osx-arm64).
- property root: Path#
Workspace root directory.
- property root_prefix: Path#
Conda root prefix (base environment).
- conda_workspaces.context.build_template_context(manifest_path: Path | None = None, task_args: dict[str, str] | None = None) dict[str, object][source]#
Build the full Jinja2 template context dict.
The returned dict contains: -
conda: aCondaContextinstance -pixi: alias to the same context (for pixi.toml compatibility) - Any user-supplied task argument values