Skip to content

[3.10] bpo-44241: Incorporate changes from importlib_metadata 4.1. (GH-26382) #26384

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Closed
Closed
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
17 changes: 9 additions & 8 deletions Lib/importlib/metadata/__init__.py
Original file line number Diff line number Diff line change
Expand Up @@ -19,6 +19,7 @@
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
Expand Down Expand Up @@ -612,10 +613,11 @@ def __init__(self, **kwargs):
@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)

Expand Down Expand Up @@ -772,11 +774,10 @@ def invalidate_caches(cls):


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

Expand Down Expand Up @@ -870,7 +871,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

Expand Down
1 change: 1 addition & 0 deletions Lib/importlib/metadata/_adapters.py
Original file line number Diff line number Diff line change
Expand Up @@ -19,6 +19,7 @@ class Message(email.message.Message):
'Requires-Dist',
'Requires-External',
'Supported-Platform',
'Dynamic',
],
)
)
Expand Down
18 changes: 18 additions & 0 deletions Lib/importlib/metadata/_meta.py
Original file line number Diff line number Diff line change
Expand Up @@ -27,3 +27,21 @@ def json(self) -> Dict[str, Union[str, List[str]]]:
"""
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
Original file line number Diff line number Diff line change
@@ -0,0 +1,2 @@
Incorporate minor tweaks from importlib_metadata 4.1: SimplePath protocol,
support for Metadata 2.2.