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
Distribution
instance 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
Union
representingDistribution
andWheelDistribution
. 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 thetuple
interface (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-info
directory and return its content.has_file
(filename)Returns whether the
*.dist-info
directory contains a file namedfilename
._asdict
()Return a new dict which maps field names to their values.
_replace
(**kwargs)Make a new
DistributionType
object, of the same type as this one, replacing the specified fields with new values._make
(iterable)Make a new
DistributionType
object, 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/METADATA
file.Returns the content of the
*.dist-info/WHEEL
file, orNone
if the file does not exist.Returns the parsed content of the
*.dist-info/RECORD
file, orNone
if the file does not exist.__repr__
()Returns a string representation of the
DistributionType
.-
abstract
read_file
(filename)[source]¶ Read a file from the
*.dist-info
directory and return its content.
-
abstract
has_file
(filename)[source]¶ Returns whether the
*.dist-info
directory contains a file namedfilename
.
-
_replace
(**kwargs)[source]¶ Make a new
DistributionType
object, of the same type as this one, replacing the specified fields with new values.- Parameters
iterable
- Return type
-
classmethod
_make
(iterable)[source]¶ Make a new
DistributionType
object, 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.EntryPoint
objects 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/WHEEL
file, orNone
if 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/RECORD
file, orNone
if the file does not exist.- Return type
- Returns
A
dist_meta.record.RecordEntry
object for each line in the record (i.e. each file in the distribution). This includes files in the*.dist-info
directory.
-
__repr__
()[source]¶ Returns a string representation of the
DistributionType
.- Return type
-
abstract
-
namedtuple
Distribution
(name, version, path)[source]¶ Bases:
DistributionType
Represents an installed Python distribution.
- Fields
-
classmethod
from_path
(path)[source]¶ Construct a
Distribution
from a filesystem path to the*.dist-info
directory.- Parameters
- Return type
-
has_file
(filename)[source]¶ Returns whether the
*.dist-info
directory contains a file namedfilename
.
-
get_record
()[source]¶ Returns the parsed content of the
*.dist-info/RECORD
file, orNone
if the file does not exist.- Return type
- Returns
A
dist_meta.record.RecordEntry
object for each line in the record (i.e. each file in the distribution). This includes files in the*.dist-info
directory.
-
namedtuple
WheelDistribution
(name, version, path, wheel_zip)[source]¶ Bases:
DistributionType
Represents a Python distribution in wheel form.
- Fields
A
WheelDistribution
can be used as a contextmanager, which will close the underlyingzipfile.ZipFile
when exiting thewith
block.-
classmethod
from_path
(path, **kwargs)[source]¶ Construct a
WheelDistribution
from a filesystem path to the.whl
file.- Parameters
**kwargs – Additional keyword arguments passed to
zipfile.ZipFile
.
- Return type
-
has_file
(filename)[source]¶ Returns whether the
*.dist-info
directory contains a file namedfilename
.
-
get_wheel
()[source]¶ Returns the content of the
*.dist-info/WHEEL
file.- Raises
FileNotFoundError – if the file does not exist.
- Return type
-
get_record
()[source]¶ Returns the parsed content of the
*.dist-info/RECORD
file, orNone
if the file does not exist.- Return type
- Returns
A
dist_meta.record.RecordEntry
object for each line in the record (i.e. each file in the distribution). This includes files in the*.dist-info
directory.- Raises
FileNotFoundError – if the file does not exist.
-
exception
DistributionNotFoundError
[source]¶ Bases:
ValueError
Raised when a distribution cannot be located.
-
_DT
= TypeVar(_DT, bound=DistributionType)¶ Type:
TypeVar
Invariant
TypeVar
bound todist_meta.distributions.DistributionType
.