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 recommendsmonkeypatch.setenv/monkeypatch.delenvas replacements — but those are test-only. This production path needs to scopeCONDA_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 inconda/conda#14095/ PRconda/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) overridingcontext._subdirfor the duration of the solve. Conda’s virtual package plugins (__linux,__osx,__win) gate oncontext.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 conservativeCONDA_OVERRIDE_*defaults for the duration of the solve. User knobs stay authoritative: explicitCONDA_OVERRIDE_*env vars are left untouched, and[system-requirements]versions are lifted into the override so__glibc >=2.28in 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
WorkspaceContextpassctx.env_prefix(resolved.name).Raises
SolveErrorwhen 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.
platformsis the declared set (feature ∩ workspace, already merged byresolve_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 raisesPlatformError.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_platformfromrattler: when we solve for a target that the host cannot detect a virtual package for (e.g.linux-64from macOS emits no__glibcrecord), inject conservative defaults so packages gated on those virtuals remain resolvable out of the box.Precedence (highest to lowest):
CONDA_OVERRIDE_*already present inos.environ— the user is explicitly in charge and this helper returns no entry for that key, leaving the existing value untouched.[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 constraintconda_workspaces.envs._apply_system_requirementsappends.A conservative built-in baseline (
__glibc == 2.17for any non-native linux target,__osx >= 10.15/>= 11.0forosx-64/osx-arm64cross-compiles, presence-only__winfor win targets).
__cudaand__archspecare not seeded — the caller must opt in via[system-requirements]orCONDA_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.platformsand any feature-declared platforms surfaced through resolved_envs (i.e. the intersection of feature platforms per environment, falling back toconfig.platformswhen no feature declares any).A naive
config.platformscheck is not sufficient because features may declare platforms beyond the workspace level, and those reach the solver throughResolvedEnvironment.platformswithout being clipped against the workspace set.Intended for pre-solve CLI validation of
--platformvalues (so typos likelixux-64fail before any solver work runs) and for surfacing the reachable platform set inconda 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.