Skip to content

Commit 06ac3a4

Browse files
authored
bpo-44241: Incorporate changes from importlib_metadata 4.1. (#26382)
1 parent 90a6c07 commit 06ac3a4

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
@@ -612,10 +613,11 @@ def __init__(self, **kwargs):
612613
@property
613614
def path(self):
614615
"""
615-
The path that a distribution finder should search.
616+
The sequence of directory path that a distribution finder
617+
should search.
616618
617-
Typically refers to Python package paths and defaults
618-
to ``sys.path``.
619+
Typically refers to Python installed package paths such as
620+
"site-packages" directories and defaults to ``sys.path``.
619621
"""
620622
return vars(self).get('path', sys.path)
621623

@@ -772,11 +774,10 @@ def invalidate_caches(cls):
772774

773775

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

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

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)