Skip to content

Commit

Permalink
Create 'localize_package_path' function to convert stdlib to local ve…
Browse files Browse the repository at this point in the history
…rsions of PackagePath.
  • Loading branch information
jaraco committed Sep 11, 2024
1 parent cb34638 commit bd4ba0f
Show file tree
Hide file tree
Showing 2 changed files with 13 additions and 1 deletion.
4 changes: 3 additions & 1 deletion importlib_metadata/__init__.py
Original file line number Diff line number Diff line change
Expand Up @@ -35,8 +35,9 @@
install,
localize_dist,
localize_metadata,
localize_package_path,
)
from ._functools import apply, method_cache, pass_none
from ._functools import apply, compose, method_cache, pass_none
from ._itertools import always_iterable, bucket, unique_everseen
from ._meta import PackageMetadata, SimplePath
from .compat import py39, py311
Expand Down Expand Up @@ -529,6 +530,7 @@ def entry_points(self) -> EntryPoints:
return EntryPoints._from_text_for(self.read_text('entry_points.txt'), self)

@property
@apply(pass_none(compose(list, functools.partial(map, localize_package_path))))
def files(self) -> Optional[List[PackagePath]]:
"""Files in this distribution.
Expand Down
10 changes: 10 additions & 0 deletions importlib_metadata/_compat.py
Original file line number Diff line number Diff line change
Expand Up @@ -91,3 +91,13 @@ def localize_metadata(
if isinstance(input, importlib_metadata._adapters.Message):
return input
return importlib_metadata._adapters.Message(input)


def localize_package_path(
input: importlib_metadata.PackagePath | importlib.metadata.PackagePath,
) -> importlib_metadata.PackagePath:
if isinstance(input, importlib_metadata.PackagePath):
return input
replacement = importlib_metadata.PackagePath(input)
vars(replacement).update(vars(input))
return replacement

0 comments on commit bd4ba0f

Please sign in to comment.