subdir_data#

Tools for managing a subdir's repodata.json.

Classes#

SubdirDataType

PackageRecordList

Lazily convert dicts to PackageRecord.

SubdirData

A class representing the SubdirData.

Functions#

make_feature_record(→ conda.models.records.PackageRecord)

Create a feature record based on the given feature name.

Attributes#

REPODATA_PICKLE_VERSION = 30#
MAX_REPODATA_VERSION = 2#
REPODATA_HEADER_RE = b'"(_etag|_mod|_cache_control)":[ ]?"(.*?[^\\\\])"[,}\\s]'#
class SubdirDataType#

Bases: type

__call__(channel: conda.models.channel.Channel, repodata_fn: str = REPODATA_FN) SubdirData#

Call self as a function.

class PackageRecordList(initlist=None)#

Bases: collections.UserList

Lazily convert dicts to PackageRecord.

This class inherits from the built-in UserList class and provides a way to lazily convert dictionaries to PackageRecord objects. It overrides the __getitem__ method to check if the item at the given index is a PackageRecord object. If not, it converts the dictionary to a PackageRecord object and stores it in the data list.

Parameters:

data -- The list of items

__getitem__(i: int) conda.models.records.PackageRecord#

Returns the PackageRecord at index i. If i is a slice, returns a new instance of PackageRecordList containing the PackageRecords at the indices in i. If the PackageRecord at index i is not already an instance of PackageRecord, it is converted to one and stored back in the data list.

Parameters:

i -- An integer or slice object indicating the index or indices of the PackageRecord(s) to be returned.

Returns:

If i is a slice, returns a new instance of PackageRecordList containing the PackageRecords at the indices in i. If i is an integer, returns the PackageRecord at index i.

class SubdirData(channel: conda.models.channel.Channel, repodata_fn: str = REPODATA_FN, RepoInterface: type[SubdirData.__init__.RepoInterface] = CondaRepoInterface)#

A class representing the SubdirData.

This class provides functionality for managing and caching SubdirData instances.

Parameters:
  • channel -- The channel object

  • repodata_fn -- The name of the repodata file. Defaults to REPODATA_FN

Returns:

A SubdirData instance.

Initializes a new instance of the SubdirData class.

Parameters:
  • channel -- The channel object.

  • repodata_fn -- The repodata filename.

  • RepoInterface -- The RepoInterface class.

property _repo: conda.gateways.repodata.RepoInterface#

Changes as we mutate self.repodata_fn.

property repo_cache: conda.gateways.repodata.RepodataCache#

Returns the RepodataCache object associated with the current instance of SubdirData.

property repo_fetch: conda.gateways.repodata.RepodataFetch#

Object to get repodata. Not cached since self.repodata_fn is mutable.

Replaces self._repo & self.repo_cache.

property cache_path_base: str#

Get the base path for caching the repodata.json file.

This method returns the base path for caching the repodata.json file. It is used to construct the full path for caching the file.

property url_w_repodata_fn: str#

Get the URL with the repodata filename.

This method returns the URL with the repodata filename.

property cache_path_json: pathlib.Path#

Get the path to the cache file.

This method returns the path to the cache file.

property cache_path_state: pathlib.Path#

Out-of-band etag and other state needed by the RepoInterface.

Get the path to the cache state file.

This method returns the path to the cache state file.

property cache_path_pickle: str#

Get the path to the cache pickle file.

This method returns the path to the cache pickle file.

_cache_: dict[tuple[str, str], PackageRecordList | SubdirData]#
classmethod clear_cached_local_channel_data(exclude_file: bool = True) None#

Clear the cached local channel data.

This method is used to clear the cached local channel data. It is primarily used during unit tests to handle changes in the CONDA_USE_ONLY_TAR_BZ2 environment variable during the process lifetime.

Parameters:

exclude_file -- A flag indicating whether to exclude file:// URLs from the cache.

static query_all(package_ref_or_match_spec: conda.core.index.PackageRef | conda.models.match_spec.MatchSpec | str, channels: collections.abc.Iterable[conda.models.channel.Channel | str] | None = None, subdirs: collections.abc.Iterable[str] | None = None, repodata_fn: str = REPODATA_FN) tuple[conda.models.records.PackageRecord, Ellipsis]#

Executes a query against all repodata instances in the channel/subdir matrix.

Parameters:
  • package_ref_or_match_spec -- Either an exact PackageRef to match against, or a MatchSpec query object. A str will be turned into a MatchSpec automatically.

  • channels -- An iterable of urls for channels or Channel objects. If None, will fall back to context.channels.

  • subdirs -- If None, will fall back to context.subdirs.

  • repodata_fn -- The filename of the repodata.

Returns:

A tuple of PackageRecord objects.

query(package_ref_or_match_spec: str | conda.models.match_spec.MatchSpec) collections.abc.Iterator[conda.models.records.PackageRecord]#

A function that queries for a specific package reference or MatchSpec object.

Parameters:

package_ref_or_match_spec -- The package reference or MatchSpec object to query.

Yields:

PackageRecord objects.

reload() Self#

Update the instance with new information.

load() Self#

Load the internal state of the SubdirData instance.

This method loads the internal state of the SubdirData instance.

iter_records() collections.abc.Iterator[conda.models.records.PackageRecord]#

A function that iterates over package records.

This function checks if the package records are loaded. If not loaded, it loads them. It returns an iterator over the package records. The package_records attribute could potentially be replaced with fully-converted UserList data after going through the entire list.

_iter_records_by_name(name: str) collections.abc.Iterator[conda.models.records.PackageRecord]#

A function that iterates over package records by name.

This function iterates over package records and yields those whose name matches the given name. If include_self is True, it also yields the record with the given name.

_load() dict[str, Any]#

Try to load repodata. If e.g. we are downloading current_repodata.json, fall back to repodata.json when the former is unavailable.

_pickle_me() None#

Pickle the object to the specified file.

_read_local_repodata(state: conda.gateways.repodata.RepodataState) dict[str, Any]#

Read local repodata from the cache and process it.

_pickle_valid_checks(pickled_state: dict[str, Any], mod: str, etag: str) collections.abc.Iterator[tuple[str, Any, Any]]#

Throw away the pickle if these don't all match.

Parameters:
  • pickled_state -- The pickled state to compare against.

  • mod -- The modification information to check.

  • etag -- The etag to compare against.

Yields:

Tuples of the form (check_name, pickled_value, current_value).

_read_pickled(state: conda.gateways.repodata.RepodataState) dict[str, Any] | None#

Read pickled repodata from the cache and process it.

Parameters:

state -- The repodata state.

Returns:

A dictionary containing the processed pickled repodata, or None if the repodata is not pickled.

_process_raw_repodata_str(raw_repodata_str: str, state: conda.gateways.repodata.RepodataState | None = None) dict[str, Any]#

State contains information that was previously in-band in raw_repodata_str.

Process the raw repodata string and return the processed repodata.

Parameters:

raw_repodata_str -- The raw repodata string.

Returns:

A dictionary containing the processed repodata.

_process_raw_repodata(repodata: dict[str, Any], state: conda.gateways.repodata.RepodataState | None = None) dict[str, Any]#

Process the raw repodata dictionary and return the processed repodata.

Parameters:
  • repodata -- The raw repodata dictionary.

  • state -- The repodata state. Defaults to None.

Returns:

A dictionary containing the processed repodata.

_get_base_url(repodata: dict, with_credentials: bool = True) str#

In repodata_version=1, .tar.bz2 and .conda artifacts are assumed to be colocated next to repodata.json, in the same server and directory.

In repodata_version=2, repodata.json files can define a 'base_url' field to override that default assumption. See CEP-15 for more details.

This method deals with both cases and returns the appropriate value.

Get the base URL for the given endpoint.

Parameters:

endpoint -- The endpoint for which the base URL is needed.

Returns:

The base URL corresponding to the provided endpoint.

make_feature_record(feature_name: str) conda.models.records.PackageRecord#

Create a feature record based on the given feature name.

Parameters:

feature_name -- The name of the feature

Returns:

The created PackageRecord for the feature.