sitecustomize._vendor.importlib_metadata

Submodules

Package Contents

Classes

PackageMetadata

Base class for protocol classes.

Distribution

A Python distribution package.

DistributionFinder

A MetaPathFinder capable of discovering installed distributions.

Functions

distribution(distribution_name)

Get the Distribution instance for the named package.

distributions(**kwargs)

Get all Distribution instances in the current environment.

metadata(distribution_name)

Get the metadata for the named package.

version(distribution_name)

Get the version string for the named package.

entry_points(**params)

Return EntryPoint objects for all installed packages.

files(distribution_name)

Return a list of files for the named package.

requires(distribution_name)

Return a list of requirements for the named package.

packages_distributions()

Return a mapping of top-level packages to their

class sitecustomize._vendor.importlib_metadata.PackageMetadata

Bases: sitecustomize._vendor.importlib_metadata._compat.Protocol

Base class for protocol classes.

Protocol classes are defined as:

class Proto(Protocol):
    def meth(self) -> int:
        ...

Such classes are primarily used with static type checkers that recognize structural subtyping (static duck-typing), for example:

class C:
    def meth(self) -> int:
        return 0

def func(x: Proto) -> int:
    return x.meth()

func(C())  # Passes static type check

See PEP 544 for details. Protocol classes decorated with @typing.runtime_checkable act as simple-minded runtime protocols that check only the presence of given attributes, ignoring their type signatures. Protocol classes can be generic, they are defined as:

class GenProto(Protocol[T]):
    def meth(self) -> T:
        ...
property json: Dict[str, str | List[str]]

A JSON-compatible form of the metadata.

Return type:

Dict[str, Union[str, List[str]]]

__len__()
Return type:

int

__contains__(item)
Parameters:

item (str) –

Return type:

bool

__getitem__(key)
Parameters:

key (str) –

Return type:

str

__iter__()
Return type:

Iterator[str]

get_all(name, failobj=...)

Return all values associated with a possibly multi-valued key.

Parameters:
  • name (str) –

  • failobj (_T) –

Return type:

Union[List[Any], _T]

exception sitecustomize._vendor.importlib_metadata.PackageNotFoundError

Bases: ModuleNotFoundError

The package was not found.

property name
__str__()

Return str(self).

class sitecustomize._vendor.importlib_metadata.Distribution

A Python distribution package.

property metadata: _meta.PackageMetadata

Return the parsed metadata for this Distribution.

The returned object will have keys that name the various bits of metadata. See PEP 566 for details.

Return type:

_meta.PackageMetadata

property name

Return the ‘Name’ metadata for the distribution package.

property _normalized_name

Return a normalized version of the name.

property version

Return the ‘Version’ metadata for the distribution package.

property entry_points
property files

Files in this distribution.

Returns:

List of PackagePath for this distribution or None

Result is None if the metadata file that enumerates files (i.e. RECORD for dist-info or SOURCES.txt for egg-info) is missing. Result may be empty if the metadata exists but is empty.

property requires

Generated requirements specified for this Distribution

abstract read_text(filename)

Attempt to load metadata file given by the name.

Parameters:

filename – The name of the file in the distribution info.

Returns:

The text if found, otherwise None.

abstract locate_file(path)

Given a path to a file in this distribution, return a path to it.

classmethod from_name(name)

Return the Distribution for the given package name.

Parameters:

name – The name of the distribution package to search for.

Returns:

The Distribution instance (or subclass thereof) for the named package, if found.

Raises:

PackageNotFoundError – When the named package’s distribution metadata cannot be found.

classmethod discover(**kwargs)

Return an iterable of Distribution objects for all packages.

Pass a context or pass keyword arguments for constructing a context.

Context:

A DistributionFinder.Context object.

Returns:

Iterable of Distribution objects for all packages.

static at(path)

Return a Distribution for the indicated metadata path

Parameters:

path – a string or path-like object

Returns:

a concrete Distribution instance for the path

static _discover_resolvers()

Search the meta_path for resolvers.

_read_files_distinfo()

Read the lines of RECORD

_read_files_egginfo()

SOURCES.txt might contain literal commas, so wrap each line in quotes.

_read_dist_info_reqs()
_read_egg_info_reqs()
classmethod _deps_from_requires_text(source)
static _convert_egg_info_reqs_to_simple_reqs(sections)

Historically, setuptools would solicit and store ‘extra’ requirements, including those with environment markers, in separate sections. More modern tools expect each dependency to be defined separately, with any relevant extras and environment markers attached directly to that requirement. This method converts the former to the latter. See _test_deps_from_requires_text for an example.

class sitecustomize._vendor.importlib_metadata.DistributionFinder

Bases: importlib.abc.MetaPathFinder

A MetaPathFinder capable of discovering installed distributions.

class Context(**kwargs)

Keyword arguments presented by the caller to distributions() or Distribution.discover() to narrow the scope of a search for distributions in all DistributionFinders.

Each DistributionFinder may expect any parameters and should attempt to honor the canonical parameters defined below when appropriate.

property path

The sequence of directory path that a distribution finder should search.

Typically refers to Python installed package paths such as “site-packages” directories and defaults to sys.path.

name

Specific name for which a distribution finder should match. A name of None matches all distributions.

abstract find_distributions(context=Context())

Find distributions.

Return an iterable of all Distribution instances capable of loading the metadata for packages matching the context, a DistributionFinder.Context instance.

sitecustomize._vendor.importlib_metadata.distribution(distribution_name)

Get the Distribution instance for the named package.

Parameters:

distribution_name – The name of the distribution package as a string.

Returns:

A Distribution instance (or subclass thereof).

sitecustomize._vendor.importlib_metadata.distributions(**kwargs)

Get all Distribution instances in the current environment.

Returns:

An iterable of Distribution instances.

sitecustomize._vendor.importlib_metadata.metadata(distribution_name)

Get the metadata for the named package.

Parameters:

distribution_name – The name of the distribution package to query.

Returns:

A PackageMetadata containing the parsed metadata.

Return type:

_meta.PackageMetadata

sitecustomize._vendor.importlib_metadata.version(distribution_name)

Get the version string for the named package.

Parameters:

distribution_name – The name of the distribution package to query.

Returns:

The version string for the package as defined in the package’s “Version” metadata key.

sitecustomize._vendor.importlib_metadata.entry_points(**params)

Return EntryPoint objects for all installed packages.

Pass selection parameters (group or name) to filter the result to entry points matching those properties (see EntryPoints.select()).

For compatibility, returns SelectableGroups object unless selection parameters are supplied. In the future, this function will return EntryPoints instead of SelectableGroups even when no selection parameters are supplied.

For maximum future compatibility, pass selection parameters or invoke .select with parameters on the result.

Returns:

EntryPoints or SelectableGroups for all installed packages.

Return type:

Union[EntryPoints, SelectableGroups]

sitecustomize._vendor.importlib_metadata.files(distribution_name)

Return a list of files for the named package.

Parameters:

distribution_name – The name of the distribution package to query.

Returns:

List of files composing the distribution.

sitecustomize._vendor.importlib_metadata.requires(distribution_name)

Return a list of requirements for the named package.

Returns:

An iterator of requirements, suitable for packaging.requirement.Requirement.

sitecustomize._vendor.importlib_metadata.packages_distributions()

Return a mapping of top-level packages to their distributions.

>>> import collections.abc
>>> pkgs = packages_distributions()
>>> all(isinstance(dist, collections.abc.Sequence) for dist in pkgs.values())
True
Return type:

Mapping[str, List[str]]