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-64 or osx-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.

env_exists(env_name: str) bool[source]#

Check whether the prefix is a valid conda environment.

env_prefix(env_name: str) Path[source]#

Return the prefix path for a named environment.

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 Environment objects from the workspace conda.lock.

Delegates to CondaLockLoader, the same entry point conda uses when it reads --file conda.lock through Environment.from_cli_with_file_envs().

When requested_platforms is empty, every platform present in the lockfile is returned. Otherwise the list is filtered and PlatformError is raised for any requested platform the lockfile does not contain.

envs_from_manifest(env_name: str, *, requested_platforms: tuple[str, ...] = ()) list[Environment][source]#

Build Environment objects from the workspace manifest.

Produces an Environment per target platform with requested_packages populated from the manifest’s declared specs (no solver, no installed packages required) — the novel capability of conda workspace export vs. conda export, which always operates on an installed prefix. When the manifest declares platforms conda doesn’t know, falls back to platform so 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.toml into a list of Environment objects 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 Environment objects from an installed workspace prefix.

Thin wrapper around the same Environment.from_prefix() + Environment.extrapolate() pair that conda.cli.main_export.execute() uses; the only workspace-specific pieces are the prefix lookup (env_prefix()) and the EnvironmentNotInstalledError guard.

When requested_platforms is empty or equals (self.platform,), a single Environment for the host platform is returned. Otherwise one Environment per requested platform is produced via Environment.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: a CondaContext instance - pixi: alias to the same context (for pixi.toml compatibility) - Any user-supplied task argument values