diff options
author | Miss Islington (bot) <31488909+miss-islington@users.noreply.github.com> | 2021-05-27 01:22:25 (GMT) |
---|---|---|
committer | GitHub <noreply@github.com> | 2021-05-27 01:22:25 (GMT) |
commit | 5d569ef9dd57cf03473ef0c04f0e58b6c5cb5d04 (patch) | |
tree | c3965342764f1abc528222d1fbf4b7efc6745e46 /Lib/importlib | |
parent | 4115996342278de7c2a1b59ac348322e7a4e9072 (diff) | |
download | cpython-5d569ef9dd57cf03473ef0c04f0e58b6c5cb5d04.zip cpython-5d569ef9dd57cf03473ef0c04f0e58b6c5cb5d04.tar.gz cpython-5d569ef9dd57cf03473ef0c04f0e58b6c5cb5d04.tar.bz2 |
[3.10] bpo-44241: Incorporate changes from importlib_metadata 4.1. (GH-26382) (GH-26395)
(cherry picked from commit 06ac3a4742228b0230981720060248a7425b2486)
Co-authored-by: Jason R. Coombs <jaraco@jaraco.com>
Automerge-Triggered-By: GH:jaraco
Diffstat (limited to 'Lib/importlib')
-rw-r--r-- | Lib/importlib/metadata/__init__.py | 17 | ||||
-rw-r--r-- | Lib/importlib/metadata/_adapters.py | 1 | ||||
-rw-r--r-- | Lib/importlib/metadata/_meta.py | 18 |
3 files changed, 28 insertions, 8 deletions
diff --git a/Lib/importlib/metadata/__init__.py b/Lib/importlib/metadata/__init__.py index 629f185..94b8386 100644 --- a/Lib/importlib/metadata/__init__.py +++ b/Lib/importlib/metadata/__init__.py @@ -19,6 +19,7 @@ from ._meta import PackageMetadata from ._collections import FreezableDefaultDict, Pair from ._functools import method_cache from ._itertools import unique_everseen +from ._meta import PackageMetadata, SimplePath from contextlib import suppress from importlib import import_module @@ -611,10 +612,11 @@ class DistributionFinder(MetaPathFinder): @property 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 - to ``sys.path``. + Typically refers to Python installed package paths such as + "site-packages" directories and defaults to ``sys.path``. """ return vars(self).get('path', sys.path) @@ -771,11 +773,10 @@ class MetadataPathFinder(DistributionFinder): class PathDistribution(Distribution): - def __init__(self, path): - """Construct a distribution from a path to the metadata directory. + def __init__(self, path: SimplePath): + """Construct a distribution. - :param path: A pathlib.Path or similar object supporting - .joinpath(), __div__, .parent, and .read_text(). + :param path: SimplePath indicating the metadata directory. """ self._path = path @@ -869,7 +870,7 @@ def requires(distribution_name): Return a list of requirements for the named package. :return: An iterator of requirements, suitable for - packaging.requirement.Requirement. + packaging.requirement.Requirement. """ return distribution(distribution_name).requires diff --git a/Lib/importlib/metadata/_adapters.py b/Lib/importlib/metadata/_adapters.py index ab08618..aa460d3 100644 --- a/Lib/importlib/metadata/_adapters.py +++ b/Lib/importlib/metadata/_adapters.py @@ -19,6 +19,7 @@ class Message(email.message.Message): 'Requires-Dist', 'Requires-External', 'Supported-Platform', + 'Dynamic', ], ) ) diff --git a/Lib/importlib/metadata/_meta.py b/Lib/importlib/metadata/_meta.py index 04d9a02..1a6edbf 100644 --- a/Lib/importlib/metadata/_meta.py +++ b/Lib/importlib/metadata/_meta.py @@ -27,3 +27,21 @@ class PackageMetadata(Protocol): """ 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 |