Skip to content

Commit

Permalink
Merge pull request #315 from FFY00/pathdistribution-type-hint
Browse files Browse the repository at this point in the history
meta: add SimplePath protocol for PathDistribution
  • Loading branch information
jaraco authored May 26, 2021
2 parents 335a758 + 92084b8 commit 5a4699d
Show file tree
Hide file tree
Showing 3 changed files with 25 additions and 5 deletions.
3 changes: 3 additions & 0 deletions CHANGES.rst
Original file line number Diff line number Diff line change
Expand Up @@ -3,6 +3,9 @@ v4.1.0

* #312: Add support for metadata 2.2 (``Dynamic`` field).

* #315: Add ``SimplePath`` protocol for interface clarity
in ``PathDistribution``.

v4.0.1
=======

Expand Down
9 changes: 4 additions & 5 deletions importlib_metadata/__init__.py
Original file line number Diff line number Diff line change
Expand Up @@ -23,7 +23,7 @@
)
from ._functools import method_cache
from ._itertools import unique_everseen
from ._meta import PackageMetadata
from ._meta import PackageMetadata, SimplePath

from contextlib import suppress
from importlib import import_module
Expand Down Expand Up @@ -783,11 +783,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
18 changes: 18 additions & 0 deletions importlib_metadata/_meta.py
Original file line number Diff line number Diff line change
Expand Up @@ -28,3 +28,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

0 comments on commit 5a4699d

Please sign in to comment.