Skip to content

Commit 5d569ef

Browse files
[3.10] bpo-44241: Incorporate changes from importlib_metadata 4.1. (GH-26382) (GH-26395)
(cherry picked from commit 06ac3a4) Co-authored-by: Jason R. Coombs <[email protected]> Automerge-Triggered-By: GH:jaraco
1 parent 4115996 commit 5d569ef

File tree

4 files changed

+30
-8
lines changed

4 files changed

+30
-8
lines changed

Lib/importlib/metadata/__init__.py

Lines changed: 9 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -19,6 +19,7 @@
1919
from ._collections import FreezableDefaultDict, Pair
2020
from ._functools import method_cache
2121
from ._itertools import unique_everseen
22+
from ._meta import PackageMetadata, SimplePath
2223

2324
from contextlib import suppress
2425
from importlib import import_module
@@ -611,10 +612,11 @@ def __init__(self, **kwargs):
611612
@property
612613
def path(self):
613614
"""
614-
The path that a distribution finder should search.
615+
The sequence of directory path that a distribution finder
616+
should search.
615617
616-
Typically refers to Python package paths and defaults
617-
to ``sys.path``.
618+
Typically refers to Python installed package paths such as
619+
"site-packages" directories and defaults to ``sys.path``.
618620
"""
619621
return vars(self).get('path', sys.path)
620622

@@ -771,11 +773,10 @@ def invalidate_caches(cls):
771773

772774

773775
class PathDistribution(Distribution):
774-
def __init__(self, path):
775-
"""Construct a distribution from a path to the metadata directory.
776+
def __init__(self, path: SimplePath):
777+
"""Construct a distribution.
776778
777-
:param path: A pathlib.Path or similar object supporting
778-
.joinpath(), __div__, .parent, and .read_text().
779+
:param path: SimplePath indicating the metadata directory.
779780
"""
780781
self._path = path
781782

@@ -869,7 +870,7 @@ def requires(distribution_name):
869870
Return a list of requirements for the named package.
870871
871872
:return: An iterator of requirements, suitable for
872-
packaging.requirement.Requirement.
873+
packaging.requirement.Requirement.
873874
"""
874875
return distribution(distribution_name).requires
875876

Lib/importlib/metadata/_adapters.py

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -19,6 +19,7 @@ class Message(email.message.Message):
1919
'Requires-Dist',
2020
'Requires-External',
2121
'Supported-Platform',
22+
'Dynamic',
2223
],
2324
)
2425
)

Lib/importlib/metadata/_meta.py

Lines changed: 18 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -27,3 +27,21 @@ def json(self) -> Dict[str, Union[str, List[str]]]:
2727
"""
2828
A JSON-compatible form of the metadata.
2929
"""
30+
31+
32+
class SimplePath(Protocol):
33+
"""
34+
A minimal subset of pathlib.Path required by PathDistribution.
35+
"""
36+
37+
def joinpath(self) -> 'SimplePath':
38+
... # pragma: no cover
39+
40+
def __div__(self) -> 'SimplePath':
41+
... # pragma: no cover
42+
43+
def parent(self) -> 'SimplePath':
44+
... # pragma: no cover
45+
46+
def read_text(self) -> str:
47+
... # pragma: no cover
Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,2 @@
1+
Incorporate minor tweaks from importlib_metadata 4.1: SimplePath protocol,
2+
support for Metadata 2.2.

0 commit comments

Comments
 (0)