environment#

EXPERIMENTAL Conda environment data model

Classes#

EnvironmentConfig

Experimental While experimental, expect both major and minor changes across minor releases.

Environment

Experimental While experimental, expect both major and minor changes across minor releases.

Attributes#

T#
EXTERNAL_PACKAGES_PYPI_KEY: Final = 'pip'#
class EnvironmentConfig#

Experimental While experimental, expect both major and minor changes across minor releases.

Data model for a conda environment config.

aggressive_update_packages: tuple[str, Ellipsis] = ()#
channel_priority: conda.base.constants.ChannelPriority | None = None#
channels: tuple[str, Ellipsis] = ()#
channel_settings: tuple[dict[str, str], Ellipsis] = ()#
deps_modifier: conda.base.constants.DepsModifier | None = None#
disallowed_packages: tuple[str, Ellipsis] = ()#
pinned_packages: tuple[str, Ellipsis] = ()#
repodata_fns: tuple[str, Ellipsis] = ()#
sat_solver: conda.base.constants.SatSolverChoice | None = None#
solver: str | None = None#
track_features: tuple[str, Ellipsis] = ()#
update_modifier: conda.base.constants.UpdateModifier | None = None#
use_only_tar_bz2: bool | None = None#
_append_without_duplicates(first: collections.abc.Iterable[T], second: collections.abc.Iterable[T]) tuple[T, Ellipsis]#
_merge_channel_settings(first: tuple[dict[str, str], Ellipsis], second: tuple[dict[str, str], Ellipsis]) tuple[dict[str, str], Ellipsis]#

Merge channel settings.

An individual channel setting is a dict that may have the key "channels". Settings with matching "channels" should be merged together.

_merge(other: EnvironmentConfig) EnvironmentConfig#

Experimental While experimental, expect both major and minor changes across minor releases.

Merges an EnvironmentConfig into this one. Merging rules are: * Primitive types get clobbered if subsequent configs have a value, otherwise keep the last set value * Lists get appended to and deduplicated * Dicts get updated * Special cases:

  • channel settings is a list of dicts, it merges inner dicts, keyed on "channel"

  • channels: last wins for priority (prepended so later config's channels take precedence)

classmethod from_context() EnvironmentConfig#

Experimental While experimental, expect both major and minor changes across minor releases.

Create an EnvironmentConfig from the current context

classmethod from_cli_channels(args: argparse.Namespace) EnvironmentConfig#

Build a sparse EnvironmentConfig from CLI args for channels only.

Used to override channels from the CLI when files are provided.

classmethod merge(*configs: EnvironmentConfig) EnvironmentConfig#

Experimental While experimental, expect both major and minor changes across minor releases.

Merges a list of EnvironmentConfigs into a single one. Merging rules are: * Primitive types get clobbered if subsequent configs have a value, otherwise keep the last set value * Lists get appended to and deduplicated * Dicts get updated

class Environment#

Experimental While experimental, expect both major and minor changes across minor releases.

Data model for a conda environment.

platform: str#

The platform this environment may be installed on (required).

config: EnvironmentConfig#

Environment level configuration, eg. channels, solver options, etc.

TODO: may need to think more about the type of this field and how conda should be merging configs between environments.

external_packages: dict[str, list[str]]#

Map of other package types that conda can install. For example pypi packages.

explicit_packages: list[conda.models.records.PackageRecord] = []#

The complete list of specs for the environment.

E.g. after a solve, or from an explicit environment spec.

name: str | None = None#

Environment name.

prefix: str | None = None#

Prefix the environment is installed into.

requested_packages: list[conda.models.match_spec.MatchSpec] = []#

User requested specs for this environment.

variables: dict[str, str]#

Environment variables to be applied to the environment.

virtual_packages: list[conda.models.records.PackageRecord] = []#
__post_init__()#
classmethod merge(*environments)#

Experimental While experimental, expect both major and minor changes across minor releases.

Merges multiple environments into a single environment following the rules: * name, prefix: last wins (later env overrides earlier). * platform: must match across all envs. * requested_packages, explicit_packages, virtual_packages: union, deduplicated. * variables: merged dict, last value wins per key. * external_packages: concatenation per key (union of lists, deduplicated). * config: EnvironmentConfig.merge (last wins for primitives, append for lists).

classmethod from_prefix(prefix: str, name: str, platform: str, *, from_history: bool = False, no_builds: bool = False, ignore_channels: bool = False, channels: list[str] | None = None) Environment#

Create an Environment model from an existing conda prefix.

This method analyzes an installed conda environment and creates an Environment model that can be used for exporting or other operations.

Parameters:
  • prefix -- Path to the conda environment prefix

  • name -- Name for the environment

  • platform -- Target platform (e.g., 'linux-64', 'osx-64')

  • from_history -- Use explicit specs from history instead of installed packages

  • no_builds -- Exclude build strings from package specs

  • ignore_channels -- Don't include channel information in package specs

Returns:

Environment model representing the prefix

classmethod from_cli(args: argparse.Namespace, add_default_packages: bool = False) Environment#

Create an Environment model from command-line arguments.

This method will parse command-line arguments and create an Environment object. This includes: reading files provided as cli arguments, and pulling EnvironmentConfig from the context.

Parameters:

args -- argparse Namespace containing command-line arguments

Returns:

An Environment object representing the cli

classmethod from_cli_with_file_envs(args: argparse.Namespace, add_default_packages: bool = False) tuple[Environment, dict[str, Environment]]#

Create an Environment model from command-line arguments, with a map of file path to Environment for each environment file specified.

Parameters:

args -- argparse Namespace containing command-line arguments

Returns:

Tuple of (merged Environment, dict mapping file path to Environment)

static from_history(prefix: conda.common.path.PathType) list[conda.models.match_spec.MatchSpec]#
extrapolate(platform: str) Environment#

Given the current environment, solve for a comparable environment on a different platform.