index#

Tools for fetching the current index.

Classes#

Index

The Index provides information about available packages from all relevant sources.

ReducedIndex

Index that contains a subset of available packages.

Functions#

check_allowlist(→ None)

Check if the given channel URLs are allowed by the context's allowlist.

get_index(, prepend, platform, use_local, use_cache, ...)

Return the index of packages available on the channels

fetch_index(→ dict)

Fetch the package index from the specified channels.

dist_str_in_index(→ bool)

Check if a distribution string matches any package in the index.

_supplement_index_with_prefix(→ None)

Supplement the given index with information from the specified environment prefix.

_supplement_index_with_cache(→ None)

Supplement the given index with packages from the cache.

_make_virtual_package(→ conda.models.records.PackageRecord)

Create a virtual package record.

_supplement_index_with_features(→ None)

Supplement the given index with virtual feature records.

_supplement_index_with_system(→ None)

Loads and populates virtual package records from conda plugins

get_archspec_name(→ str | None)

Determine the architecture specification name for the current environment.

calculate_channel_urls(, prepend, platform, use_local)

Calculate the full list of channel URLs to use based on the given parameters.

get_reduced_index(→ dict)

Generate a reduced package index based on the given specifications.

Attributes#

check_allowlist(channel_urls: list[str]) None#

Check if the given channel URLs are allowed by the context's allowlist.

Parameters:

channel_urls -- A list of channel URLs to check against the allowlist.

Raises:
LAST_CHANNEL_URLS = []#
class Index(channels: Iterable[str | conda.models.channel.Channel] = (), prepend: bool = True, platform: str | None = None, subdirs: tuple[str, Ellipsis] | None = None, use_local: bool = False, use_cache: bool | None = None, prefix: str | os.PathLike[str] | pathlib.Path | conda.core.prefix_data.PrefixData | None = None, repodata_fn: str | None = context.repodata_fns[-1], use_system: bool = False)#

Bases: collections.UserDict

The Index provides information about available packages from all relevant sources.

There are four types of sources for package information, namely

Channels

represent packages available from standard sources identified with a url, mostly online, but can also be on a local filesystem using the file:// scheme. Programatically, channels are represented by conda.models.channel.Channel, their data is fetched using conda.core.subdir_data.SubdirData.

For more information see What is a "channel"?.

Individual packages from channels are usually represented by conda.models.records.PackageRecord.

Prefix

represents packages that are already installed. Every Index can be associated with exactly one Prefix, which is the location of one of the conda Environments. The package information about the installed packages is represented by conda.core.prefix_data.PrefixData.

Individual packages from prefixes are usually represented by conda.models.records.PrefixRecord.

Package Cache

represents packages that are locally unpacked, but may not be installed in the environment associated with this index. These are usually packages that have been installed in any environment of the local conda installation, but may have been removed from all environments by now.

Individual packages from the package are usually represented by conda.models.records.PackageCacheRecord.

Virtual Packages

represent properties of the system, not actual conda packages in the normal sense. These are, for example, system packages that inform the solver about the operating system in use, or track features that can be used to steer package priority.

Individual virtual packages are represented by special conda.models.records.PackageRecord, see conda.models.records.PackageRecord.virtual_package() and conda.models.records.PackageRecord.feature().

Initializes a new index with the desired components.

Parameters:
  • channels -- channels identified by canonical names or URLS or Channel objects; for more details, see conda.models.channel.Channel.from_value()

  • prepend -- if True (default), add configured channel with higher priority than passed channels; if False, do not add configured channels.

  • platform -- see subdirs.

  • subdirs -- platform and subdirs determine the selection of subdirs in the channels; if both are None, subdirs is taken from the configuration; if both are given, subdirs takes precedence and platform is ignored; if only platform is given, subdirs will be (platform, "noarch"); if subdirs is given, subdirs will be subdirs.

  • use_local -- if True, add the special "local" channel for locally built packages with lowest priority.

  • use_cache -- if True, add packages from the package cache.

  • prefix -- associate prefix with this index and add its packages.

  • repodata_fn -- filename of the repodata, default taken from config, almost always "repodata.json".

  • use_system -- if True, add system packages, that is virtual packages defined by plugins, usually used to make intrinsic information about the system, such as cpu architecture or operating system, available to the solver.

property cache_entries: tuple[conda.models.records.PackageCacheRecord, Ellipsis]#

Contents of the package cache if active.

Returns:

All packages available from the package cache.

property system_packages: dict[conda.models.records.PackageRecord, conda.models.records.PackageRecord]#

System packages provided by plugins.

Returns:

Identity mapping of the available system packages in a dict.

property features: dict[conda.models.records.PackageRecord, conda.models.records.PackageRecord]#

Active tracking features.

Returns:

Identity mapping of the local tracking features in a dict.

property data: dict[conda.models.records.PackageRecord, conda.models.records.PackageRecord]#

The entire index as a dict; avoid if possible.

Warning

This returns the entire contents of the index as a single identity mapping in a dict. This may be convenient, but it comes at a cost because all sources must be fully loaded at significant overhead for PackageRecord construction for every package.

Hence, all uses of data, including all iteration over the entire index, is strongly discouraged.

reload(*, prefix: bool = False, cache: bool = False, features: bool = False, system: bool = False) None#

Reload one or more of the index components.

Can be used to refresh the index with new information, for example after a new package has been installed into the index.

Parameters:
  • prefix -- if True, reload the prefix data.

  • cache -- if True, reload the package cache.

  • features -- if True, reload the tracking features.

  • system -- if True, reload the system packages.

__repr__() str#

Return repr(self).

get_reduced_index(specs: Iterable[conda.models.match_spec.MatchSpec]) ReducedIndex#

Create a reduced index with a subset of packages.

Can be used to create a reduced index as a subset from an existing index.

Parameters:

specs -- the specs that span the subset.

Returns:

a reduced index with the same sources as this index, but limited to specs and their dependency graph.

_supplement_index_dict_with_prefix() None#

Supplement the index with information from its prefix.

_supplement_index_dict_with_cache() None#
_realize() None#
_retrieve_from_channels(key: conda.models.records.PackageRecord) conda.models.records.PackageRecord | None#
_retrieve_all_from_channels(key: conda.models.records.PackageRecord) list[conda.models.records.PackageRecord]#
_update_from_prefix(key: conda.models.records.PackageRecord, prec: conda.models.records.PackageRecord | None) conda.models.records.PackageRecord | None#
_update_from_cache(key: conda.models.records.PackageRecord, prec: conda.models.records.PackageRecord | None) conda.models.records.PackageRecord | None#
__getitem__(key: conda.models.records.PackageRecord) conda.models.records.PackageRecord#
__contains__(key: conda.models.records.PackageRecord) bool#
__copy__() Self#
class ReducedIndex(specs: Iterable[conda.models.match_spec.MatchSpec], channels: tuple[str, Ellipsis] = (), prepend: bool = True, platform: str | None = None, subdirs: tuple[str, Ellipsis] | None = None, use_local: bool = False, use_cache: bool | None = None, prefix: str | os.PathLike[str] | pathlib.Path | conda.core.prefix_data.PrefixData | None = None, repodata_fn: str | None = context.repodata_fns[-1], use_system: bool = False)#

Bases: Index

Index that contains a subset of available packages.

Like Index, this makes information about packages from the same four sources available. However, the contents of the reduced index is limited to a subset of packages relevant to a given specification. This works by taking into account all packages that match the given specification together with their dependencies and their dependencies dependencies, etc.

Note

See Index.get_reduced_index() for convenient construction.

Initialize a new reduced index.

Parameters:
  • specs -- the collection of specifications that span the subset of packages.

  • args (all other) -- see Index.

__repr__() str#

Return repr(self).

_derive_reduced_index() None#
get_index(channel_urls: Iterable[str | conda.models.channel.Channel] = (), prepend: bool = True, platform: str | None = None, use_local: bool = False, use_cache: bool = False, unknown: bool | None = None, prefix: str | None = None, repodata_fn: str = context.repodata_fns[-1]) Index#

Return the index of packages available on the channels

If prepend=False, only the channels passed in as arguments are used. If platform=None, then the current platform is used. If prefix is supplied, then the packages installed in that prefix are added.

Parameters:
  • channel_urls -- Channels to include in the index.

  • prepend -- If False, only the channels passed in are used.

  • platform -- Target platform for the index.

  • use_local -- Whether to use local channels.

  • use_cache -- Whether to use cached index information.

  • unknown -- Include unknown packages.

  • prefix -- Path to environment prefix to include in the index.

  • repodata_fn -- Filename of the repodata file.

Returns:

A dictionary representing the package index.

fetch_index(channel_urls: list[str], use_cache: bool = False, index: dict | None = None, repodata_fn: str = context.repodata_fns[-1]) dict#

Fetch the package index from the specified channels.

Parameters:
  • channel_urls -- A list of channel URLs to fetch the index from.

  • use_cache -- Whether to use the cached index data.

  • index -- An optional pre-existing index to update.

  • repodata_fn -- The name of the repodata file.

Returns:

A dictionary representing the fetched or updated package index.

dist_str_in_index(index: dict[Any, Any], dist_str: str) bool#

Check if a distribution string matches any package in the index.

Parameters:
  • index -- The package index.

  • dist_str -- The distribution string to match against the index.

Returns:

True if there is a match; False otherwise.

_supplement_index_with_prefix(index: Index | dict[Any, Any], prefix: str | os.PathLike[str] | pathlib.Path | conda.core.prefix_data.PrefixData) None#

Supplement the given index with information from the specified environment prefix.

Parameters:
  • index -- The package index to supplement.

  • prefix -- The path to the environment prefix.

_supplement_index_with_cache(index: dict[Any, Any]) None#

Supplement the given index with packages from the cache.

Parameters:

index -- The package index to supplement.

_make_virtual_package(name: str, version: str | None = None, build_string: str | None = None) conda.models.records.PackageRecord#

Create a virtual package record.

Parameters:
  • name -- The name of the virtual package.

  • version -- The version of the virtual package, defaults to "0".

  • build_string -- The build string of the virtual package, defaults to "0".

Returns:

A PackageRecord representing the virtual package.

_supplement_index_with_features(index: dict[conda.models.records.PackageRecord, conda.models.records.PackageRecord], features: list[str] = []) None#

Supplement the given index with virtual feature records.

Parameters:
  • index -- The package index to supplement.

  • features -- A list of feature names to add to the index.

_supplement_index_with_system(index: dict[conda.models.records.PackageRecord, conda.models.records.PackageRecord]) None#

Loads and populates virtual package records from conda plugins and adds them to the provided index, unless there is a naming conflict.

Parameters:

index -- The package index to supplement.

get_archspec_name() str | None#

Determine the architecture specification name for the current environment.

Returns:

The architecture name if available, otherwise None.

calculate_channel_urls(channel_urls: tuple[str] = (), prepend: bool = True, platform: str | None = None, use_local: bool = False) list[str]#

Calculate the full list of channel URLs to use based on the given parameters.

Parameters:
  • channel_urls -- Initial list of channel URLs.

  • prepend -- Whether to prepend default channels to the list.

  • platform -- The target platform for the channels.

  • use_local -- Whether to include the local channel.

Returns:

The calculated list of channel URLs.

get_reduced_index(prefix: str | None, channels: list[str], subdirs: list[str], specs: list[conda.models.match_spec.MatchSpec], repodata_fn: str) dict#

Generate a reduced package index based on the given specifications.

This function is useful for optimizing the solver by reducing the amount of data it needs to consider.

Parameters:
  • prefix -- Path to an environment prefix to include installed packages.

  • channels -- A list of channel names to include in the index.

  • subdirs -- A list of subdirectories to consider for each channel.

  • specs -- A list of MatchSpec objects to filter the packages.

  • repodata_fn -- Filename of the repodata file to use.

Returns:

A dictionary representing the reduced package index.