dist_meta.distributions¶
Iterate over installed distributions.
Third-party distributions are installed into Python’s site-packages directory with tools such as pip.
Distributions must have a *.dist-info directory (as defined by PEP 566) to be discoverable.
Functions:
|
Returns a |
|
Returns an iterator over installed distributions on |
|
Returns a mapping of top-level packages to a list of distributions which provide them. |
Classes:
Abstract base class for |
|
|
Represents an installed Python distribution. |
|
Represents a Python distribution in wheel form. |
Exceptions:
Raised when a distribution cannot be located. |
Data:
Invariant |
- get_distribution(name, path=None)[source]¶
Returns a
Distributioninstance for the distribution with the given name.
- packages_distributions(path=None)[source]¶
Returns a mapping of top-level packages to a list of distributions which provide them.
The same top-level package may be provided by multiple distributions, especially in the case of namespace packages.
- Parameters
path (
Optional[Iterable[Union[str,Path,PathLike]]]) – The directories entries to search for distributions in. Defaultsys.path.
New in version 0.7.0.
Example:
>>> import collections.abc >>> pkgs = packages_distributions() >>> all(isinstance(dist, collections.abc.Sequence) for dist in pkgs.values()) True
- class DistributionType[source]¶
Abstract base class for
Distribution-like objects.Changed in version 0.3.0: Previously was a
UnionrepresentingDistributionandWheelDistribution. Now a common base class for those two classes, and custom classes providing the same APIThis class implements most of the
collections.namedtuple()API. Subclasses must implement_fields(as a tuple of field names) and thetupleinterface (specifically__iter__and__getitem__).Attributes:
The name of the distribution.
The version number of the distribution.
A tuple of field names for the "namedtuple".
A mapping of field names to default values.
Methods:
read_file(filename)Read a file from the
*.dist-infodirectory and return its content.has_file(filename)Returns whether the
*.dist-infodirectory contains a file namedfilename._asdict()Return a new dict which maps field names to their values.
_replace(**kwargs)Make a new
DistributionTypeobject, of the same type as this one, replacing the specified fields with new values._make(iterable)Make a new
DistributionTypeobject, of the same type as this one, from a sequence or iterable.Returns a mapping of entry point groups to entry points.
Returns the content of the
*.dist-info/METADATAfile.Returns the content of the
*.dist-info/WHEELfile, orNoneif the file does not exist.Returns the parsed content of the
*.dist-info/RECORDfile, orNoneif the file does not exist.__repr__()Returns a string representation of the
DistributionType.- abstract read_file(filename)[source]¶
Read a file from the
*.dist-infodirectory and return its content.
- abstract has_file(filename)[source]¶
Returns whether the
*.dist-infodirectory contains a file namedfilename.
- _replace(**kwargs)[source]¶
Make a new
DistributionTypeobject, of the same type as this one, replacing the specified fields with new values.- Parameters
**kwargs
- Return type
- classmethod _make(iterable)[source]¶
Make a new
DistributionTypeobject, of the same type as this one, from a sequence or iterable.- Parameters
iterable
- Return type
- get_entry_points()[source]¶
Returns a mapping of entry point groups to entry points.
Entry points in the group are contained in a dictionary mapping entry point names to objects.
dist_meta.entry_points.EntryPointobjects can be constructed as follows:for name, epstr in distro.get_entry_points().get("console_scripts", {}).items(): EntryPoint(name, epstr)
- get_wheel()[source]¶
Returns the content of the
*.dist-info/WHEELfile, orNoneif the file does not exist.The file will only be present if the distribution was installed from a wheel.
- Return type
- get_record()[source]¶
Returns the parsed content of the
*.dist-info/RECORDfile, orNoneif the file does not exist.- Return type
- Returns
A
dist_meta.record.RecordEntryobject for each line in the record (i.e. each file in the distribution). This includes files in the*.dist-infodirectory.
- __repr__()[source]¶
Returns a string representation of the
DistributionType.- Return type
- namedtuple Distribution(name, version, path)[source]¶
Bases:
DistributionTypeRepresents an installed Python distribution.
- Fields
- classmethod from_path(path)[source]¶
Construct a
Distributionfrom a filesystem path to the*.dist-infodirectory.- Parameters
- Return type
- has_file(filename)[source]¶
Returns whether the
*.dist-infodirectory contains a file namedfilename.
- get_record()[source]¶
Returns the parsed content of the
*.dist-info/RECORDfile, orNoneif the file does not exist.- Return type
- Returns
A
dist_meta.record.RecordEntryobject for each line in the record (i.e. each file in the distribution). This includes files in the*.dist-infodirectory.
- namedtuple WheelDistribution(name, version, path, wheel_zip)[source]¶
Bases:
DistributionTypeRepresents a Python distribution in wheel form.
- Fields
A
WheelDistributioncan be used as a contextmanager, which will close the underlyingzipfile.ZipFilewhen exiting thewithblock.- classmethod from_path(path, **kwargs)[source]¶
Construct a
WheelDistributionfrom a filesystem path to the.whlfile.- Parameters
**kwargs – Additional keyword arguments passed to
zipfile.ZipFile.
- Return type
- has_file(filename)[source]¶
Returns whether the
*.dist-infodirectory contains a file namedfilename.
- get_wheel()[source]¶
Returns the content of the
*.dist-info/WHEELfile.- Raises
FileNotFoundError – if the file does not exist.
- Return type
- get_record()[source]¶
Returns the parsed content of the
*.dist-info/RECORDfile, orNoneif the file does not exist.- Return type
- Returns
A
dist_meta.record.RecordEntryobject for each line in the record (i.e. each file in the distribution). This includes files in the*.dist-infodirectory.- Raises
FileNotFoundError – if the file does not exist.
- exception DistributionNotFoundError[source]¶
Bases:
ValueErrorRaised when a distribution cannot be located.
- _DT = TypeVar(_DT, bound=DistributionType)¶
Type:
TypeVarInvariant
TypeVarbound todist_meta.distributions.DistributionType.