PrefixData
loaders#
The PrefixData
class exposes the contents of a given conda environment
(prefix) as a series of PrefixRecord
objects. This plugin hook allows
users to write logic to expose non-conda packages as conda-like metadata.
This can be useful to allow conda list
to report additional ecosystems,
like PyPI or others.
- class CondaPrefixDataLoader#
Define new loaders to expose non-conda packages in a given prefix as
PrefixRecord
objects.- Parameters:
name -- name of the loader
loader -- a function that takes a prefix and a dictionary that maps package names to
PrefixRecord
objects. The newly loaded packages must be inserted in the passed dictionary accordingly, and also returned as a separate dictionary.
- loader#
- name#
- conda_prefix_data_loaders()#
Register new loaders for PrefixData
The example below defines how to expose the packages installed by a hypothetical 'penguin' tool as conda packages.
Example:
from pathlib import Path from conda import plugins from conda.common.path import PathType from conda.models.records import PrefixRecord from conda.plugins.types import CondaPrefixDataLoader @plugins.hookimpl def conda_prefix_data_loaders(): yield CondaPrefixDataLoader( "hypothetical", load_hypothetical_packages, ) def load_hypothetical_packages( prefix: PathType, records: dict[str, PrefixRecord] ) -> dict[str, PrefixRecord]: penguin_records = {} for info in Path(prefix).glob("lib/penguin/*.penguin-info"): name, version = info.name.rsplit("-", 1) kwargs = {} # retrieve extra fields here penguin_records[name] = PrefixRecord( name=name, version=version, build_number=0, build="0", **kwargs ) records.update(penguin_records) return penguin_records