Skip to content
Open
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
2 changes: 1 addition & 1 deletion importlib_metadata/__init__.py
Original file line numberDiff line numberDiff line change
Expand Up@@ -1043,7 +1043,7 @@ def read_text(self, filename: str | os.PathLike[str]) -> str | None:
read_text.__doc__ = Distribution.read_text.__doc__

def locate_file(self, path: str | os.PathLike[str]) -> SimplePath:
return self._path.parent / path
return self._path.parent / os.fspath(path)

@property
def _normalized_name(self):
Expand Down
11 changes: 11 additions & 0 deletions tests/test_api.py
Original file line numberDiff line numberDiff line change
@@ -1,11 +1,14 @@
import importlib
import pathlib
import re
import textwrap
import unittest

from importlib_metadata import (
Distribution,
PackageNotFoundError,
PackagePath,
PathDistribution,
Prepared,
distribution,
entry_points,
Expand DownExpand Up@@ -192,6 +195,14 @@ def test_file_hash_repr(self):
def test_files_dist_info(self):
self._test_files(files('distinfo-pkg'))

def test_locate_file_with_windows_absolute_path(self):
dist = PathDistribution(pathlib.PureWindowsPath('C:/site/sample-1.0.dist-info'))
path = PackagePath('C:/venv/Scripts/sample.exe')

assert dist.locate_file(path) == pathlib.PureWindowsPath(
'C:/venv/Scripts/sample.exe'
)

def test_files_egg_info(self):
self._test_files(files('egginfo-pkg'))
self._test_files(files('egg_with_module-pkg'))
Expand Down