Resolver#

Feature-to-environment resolution.

Feature-to-environment resolver.

Takes a WorkspaceConfig and resolves which conda/PyPI packages need to be installed for a given environment by composing its constituent features.

class conda_workspaces.resolver.ResolvedEnvironment(name: str, conda_dependencies: dict[str, MatchSpec]=<factory>, pypi_dependencies: dict[str, PyPIDependency]=<factory>, channels: list[Channel] = <factory>, platforms: list[str] = <factory>, activation_scripts: list[str] = <factory>, activation_env: dict[str, str]=<factory>, system_requirements: dict[str, str]=<factory>, channel_priority: str | None = None)[source]#

The fully resolved dependency set for a single environment.

This is what the environment manager uses to install or update a project-local conda environment.

activation_env: dict[str, str]#
activation_scripts: list[str]#
channel_priority: str | None = None#
channels: list[Channel]#
conda_dependencies: dict[str, MatchSpec]#
name: str#
platforms: list[str]#
pypi_dependencies: dict[str, PyPIDependency]#
scoped_virtual_packages(platform: str) Iterator[None][source]#

Scope virtual_package_overrides() around a solver call.

Conda deprecated conda.common.io.env_vars() and its siblings in 26.9 (removal targeted for 27.3) and recommends monkeypatch.setenv / monkeypatch.delenv as replacements — but those are test-only. This production path needs to scope CONDA_OVERRIDE_* overrides around a solver call, for which upstream does not ship a drop-in replacement, so we keep a small local context manager until conda exposes one (tracked in conda/conda#14095 / PR conda/conda#15728).

solve_for_platform(platform: str, *, prefix: str | Path) list[PackageRecord][source]#

Solve this environment for platform and return package records.

Uses conda’s solver API to resolve dependencies without installing, producing the list of exact packages that would be installed. Applies the same transformations as conda_workspaces.envs.install_environment(): PyPI deps are translated and merged, system requirements are added as virtual package constraints, and channel priority is honoured.

The solver is targeted at platform by (a) constructing it with subdirs=(platform, "noarch") and (b) overriding context._subdir for the duration of the solve. Conda’s virtual package plugins (__linux, __osx, __win) gate on context.subdir, so this single override also yields the correct cross-platform virtual package set.

On cross-compiled targets the host cannot detect libc/kernel/macOS versions, so scoped_virtual_packages() seeds conservative CONDA_OVERRIDE_* defaults for the duration of the solve. User knobs stay authoritative: explicit CONDA_OVERRIDE_* env vars are left untouched, and [system-requirements] versions are lifted into the override so __glibc >=2.28 in the manifest and the baseline record agree.

prefix is the environment prefix path the solver should target — workspace-owned, so callers that run under a WorkspaceContext pass ctx.env_prefix(resolved.name).

Raises SolveError when the solver cannot satisfy the specs or no backend is registered.

system_requirements: dict[str, str]#
target_platforms(*, requested: tuple[str, ...] = (), fallback: str) tuple[str, ...][source]#

Return the platforms this environment should emit for.

platforms is the declared set (feature ∩ workspace, already merged by resolve_environment()); if empty, fallback (typically the host subdir) is used instead. When requested is supplied, the result is the intersection with that set, preserving caller-supplied order; any value not in the declared set raises PlatformError.

Used by WorkspaceContext.envs_from_manifest() to decide which platforms a manifest-only export emits, and safe to use by any caller that needs the same policy.

virtual_package_overrides(platform: str) dict[str, str][source]#

Return CONDA_OVERRIDE_* env vars that enable a cross-platform solve.

Mirrors rattler_virtual_packages::VirtualPackages::detect_for_platform from rattler: when we solve for a target that the host cannot detect a virtual package for (e.g. linux-64 from macOS emits no __glibc record), inject conservative defaults so packages gated on those virtuals remain resolvable out of the box.

Precedence (highest to lowest):

  1. CONDA_OVERRIDE_* already present in os.environ — the user is explicitly in charge and this helper returns no entry for that key, leaving the existing value untouched.

  2. [system-requirements] declared in the manifest for the same virtual package (e.g. glibc = "2.28") — used as the override so the virtual package record lines up with the spec constraint conda_workspaces.envs._apply_system_requirements appends.

  3. A conservative built-in baseline (__glibc == 2.17 for any non-native linux target, __osx >= 10.15 / >= 11.0 for osx-64 / osx-arm64 cross-compiles, presence-only __win for win targets).

__cuda and __archspec are not seeded — the caller must opt in via [system-requirements] or CONDA_OVERRIDE_* if they want those available. Native solves (target family matches host family) return an empty mapping so byte-for-byte output stays unchanged.

conda_workspaces.resolver.known_platforms(config: WorkspaceConfig, resolved_envs: Iterable[ResolvedEnvironment] = ()) set[str][source]#

All platforms this workspace could legitimately be solved for.

Returns the union of workspace-level config.platforms and any feature-declared platforms surfaced through resolved_envs (i.e. the intersection of feature platforms per environment, falling back to config.platforms when no feature declares any).

A naive config.platforms check is not sufficient because features may declare platforms beyond the workspace level, and those reach the solver through ResolvedEnvironment.platforms without being clipped against the workspace set.

Intended for pre-solve CLI validation of --platform values (so typos like lixux-64 fail before any solver work runs) and for surfacing the reachable platform set in conda workspace info. Passing an empty resolved_envs degrades to “workspace platforms only”.

conda_workspaces.resolver.resolve_all_environments(config: WorkspaceConfig, platform: str | None = None) dict[str, ResolvedEnvironment][source]#

Resolve all environments in the workspace.

Returns a dict mapping environment name to its resolved deps.

conda_workspaces.resolver.resolve_environment(config: WorkspaceConfig, env_name: str, platform: str | None = None) ResolvedEnvironment[source]#

Resolve an environment by composing its features.

Merges conda deps, PyPI deps, channels, activation scripts/env, and system requirements across all features in the environment.

If platform is given, target-specific overrides are included and platform support is validated.