:py:mod:`subdir_data` ===================== .. py:module:: conda.core.subdir_data .. autoapi-nested-parse:: Tools for managing a subdir's repodata.json. Classes ------- .. autoapisummary:: conda.core.subdir_data.SubdirDataType conda.core.subdir_data.PackageRecordList conda.core.subdir_data.SubdirData Functions --------- .. autoapisummary:: conda.core.subdir_data.make_feature_record Attributes ---------- .. autoapisummary:: conda.core.subdir_data.REPODATA_PICKLE_VERSION conda.core.subdir_data.MAX_REPODATA_VERSION conda.core.subdir_data.REPODATA_HEADER_RE .. py:data:: REPODATA_PICKLE_VERSION :value: 30 .. py:data:: MAX_REPODATA_VERSION :value: 2 .. py:data:: REPODATA_HEADER_RE :value: b'"(_etag|_mod|_cache_control)":[ ]?"(.*?[^\\\\])"[,}\\s]' .. py:class:: SubdirDataType Bases: :py:obj:`type` .. py:method:: __call__(channel: conda.models.channel.Channel, repodata_fn: str = REPODATA_FN) -> SubdirData Call self as a function. .. py:class:: PackageRecordList(initlist=None) Bases: :py:obj:`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. :param data: The list of items .. py:method:: __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. :param i: An integer or slice object indicating the index or indices of the PackageRecord(s) to be returned. :return: 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. .. py: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. :param channel: The channel object :param repodata_fn: The name of the repodata file. Defaults to REPODATA_FN :return: A SubdirData instance. Initializes a new instance of the SubdirData class. :param channel: The channel object. :param repodata_fn: The repodata filename. :param RepoInterface: The RepoInterface class. .. py:property:: _repo :type: conda.gateways.repodata.RepoInterface Changes as we mutate self.repodata_fn. .. py:property:: repo_cache :type: conda.gateways.repodata.RepodataCache Returns the `RepodataCache` object associated with the current instance of `SubdirData`. .. py:property:: repo_fetch :type: conda.gateways.repodata.RepodataFetch Object to get repodata. Not cached since self.repodata_fn is mutable. Replaces self._repo & self.repo_cache. .. py:property:: cache_path_base :type: 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. .. py:property:: url_w_repodata_fn :type: str Get the URL with the repodata filename. This method returns the URL with the repodata filename. .. py:property:: cache_path_json :type: pathlib.Path Get the path to the cache file. This method returns the path to the cache file. .. py:property:: cache_path_state :type: 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. .. py:property:: cache_path_pickle :type: str Get the path to the cache pickle file. This method returns the path to the cache pickle file. .. py:attribute:: _cache_ :type: dict[tuple[str, str], PackageRecordList | SubdirData] .. py:method:: clear_cached_local_channel_data(exclude_file: bool = True) -> None :classmethod: 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. :param exclude_file: A flag indicating whether to exclude file:// URLs from the cache. .. py:method:: 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] :staticmethod: Executes a query against all repodata instances in the channel/subdir matrix. :param 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. :param channels: An iterable of urls for channels or `Channel` objects. If None, will fall back to `context.channels`. :param subdirs: If None, will fall back to context.subdirs. :param repodata_fn: The filename of the repodata. :return: A tuple of `PackageRecord` objects. .. py:method:: 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. :param package_ref_or_match_spec: The package reference or MatchSpec object to query. :yields: PackageRecord objects. .. py:method:: reload() -> Self Update the instance with new information. .. py:method:: load() -> Self Load the internal state of the SubdirData instance. This method loads the internal state of the SubdirData instance. .. py:method:: 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. .. py:method:: _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. .. py:method:: _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. .. py:method:: _pickle_me() -> None Pickle the object to the specified file. .. py:method:: _read_local_repodata(state: conda.gateways.repodata.RepodataState) -> dict[str, Any] Read local repodata from the cache and process it. .. py:method:: _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. :param pickled_state: The pickled state to compare against. :param mod: The modification information to check. :param etag: The etag to compare against. :yields: Tuples of the form (check_name, pickled_value, current_value). .. py:method:: _read_pickled(state: conda.gateways.repodata.RepodataState) -> dict[str, Any] | None Read pickled repodata from the cache and process it. :param state: The repodata state. :return: A dictionary containing the processed pickled repodata, or None if the repodata is not pickled. .. py:method:: _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. :param raw_repodata_str: The raw repodata string. :return: A dictionary containing the processed repodata. .. py:method:: _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. :param repodata: The raw repodata dictionary. :param state: The repodata state. Defaults to None. :return: A dictionary containing the processed repodata. .. py:method:: _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. :param endpoint: The endpoint for which the base URL is needed. :return: The base URL corresponding to the provided endpoint. .. py:function:: make_feature_record(feature_name: str) -> conda.models.records.PackageRecord Create a feature record based on the given feature name. :param feature_name: The name of the feature :return: The created PackageRecord for the feature.