bpo-44241: Incorporate changes from importlib_metadata 4.1. (#26382)

This commit is contained in:
Jason R. Coombs 2021-05-26 13:40:05 -04:00 committed by GitHub
parent 90a6c07cb2
commit 06ac3a4742
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
4 changed files with 30 additions and 8 deletions

View File

@ -19,6 +19,7 @@ from ._meta import PackageMetadata
from ._collections import FreezableDefaultDict, Pair from ._collections import FreezableDefaultDict, Pair
from ._functools import method_cache from ._functools import method_cache
from ._itertools import unique_everseen from ._itertools import unique_everseen
from ._meta import PackageMetadata, SimplePath
from contextlib import suppress from contextlib import suppress
from importlib import import_module from importlib import import_module
@ -612,10 +613,11 @@ class DistributionFinder(MetaPathFinder):
@property @property
def path(self): def path(self):
""" """
The path that a distribution finder should search. The sequence of directory path that a distribution finder
should search.
Typically refers to Python package paths and defaults Typically refers to Python installed package paths such as
to ``sys.path``. "site-packages" directories and defaults to ``sys.path``.
""" """
return vars(self).get('path', sys.path) return vars(self).get('path', sys.path)
@ -772,11 +774,10 @@ class MetadataPathFinder(DistributionFinder):
class PathDistribution(Distribution): class PathDistribution(Distribution):
def __init__(self, path): def __init__(self, path: SimplePath):
"""Construct a distribution from a path to the metadata directory. """Construct a distribution.
:param path: A pathlib.Path or similar object supporting :param path: SimplePath indicating the metadata directory.
.joinpath(), __div__, .parent, and .read_text().
""" """
self._path = path self._path = path
@ -870,7 +871,7 @@ def requires(distribution_name):
Return a list of requirements for the named package. Return a list of requirements for the named package.
:return: An iterator of requirements, suitable for :return: An iterator of requirements, suitable for
packaging.requirement.Requirement. packaging.requirement.Requirement.
""" """
return distribution(distribution_name).requires return distribution(distribution_name).requires

View File

@ -19,6 +19,7 @@ class Message(email.message.Message):
'Requires-Dist', 'Requires-Dist',
'Requires-External', 'Requires-External',
'Supported-Platform', 'Supported-Platform',
'Dynamic',
], ],
) )
) )

View File

@ -27,3 +27,21 @@ class PackageMetadata(Protocol):
""" """
A JSON-compatible form of the metadata. A JSON-compatible form of the metadata.
""" """
class SimplePath(Protocol):
"""
A minimal subset of pathlib.Path required by PathDistribution.
"""
def joinpath(self) -> 'SimplePath':
... # pragma: no cover
def __div__(self) -> 'SimplePath':
... # pragma: no cover
def parent(self) -> 'SimplePath':
... # pragma: no cover
def read_text(self) -> str:
... # pragma: no cover

View File

@ -0,0 +1,2 @@
Incorporate minor tweaks from importlib_metadata 4.1: SimplePath protocol,
support for Metadata 2.2.