Skip to content

Commit 0023c15

Browse files
committed
Attempt to fix issue with symlinked packages
1 parent 4b61913 commit 0023c15

File tree

1 file changed

+24
-2
lines changed

1 file changed

+24
-2
lines changed

importlib_metadata/__init__.py

Lines changed: 24 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -31,7 +31,7 @@
3131
from importlib import import_module
3232
from importlib.abc import MetaPathFinder
3333
from itertools import starmap
34-
from typing import List, Mapping, Optional, cast
34+
from typing import Iterable, Iterator, List, Mapping, Optional, cast
3535

3636

3737
__all__ = [
@@ -961,10 +961,32 @@ def _top_level_declared(dist):
961961
return (dist.read_text('top_level.txt') or '').split()
962962

963963

964+
def _walk_dirs(package_paths: Iterable[PackagePath]) -> Iterator[PackagePath]:
965+
for package_path in package_paths:
966+
967+
def make_file(name):
968+
result = PackagePath(name)
969+
result.hash = None
970+
result.size = None
971+
result.dist = package_path.dist
972+
return result
973+
974+
real_path = package_path.locate()
975+
real_sitedir = package_path.dist.locate_file("") # type: ignore
976+
if real_path.is_dir() and real_path.is_symlink():
977+
# .files only mentions symlink, we must recurse into it ourselves:
978+
for root, dirs, files in os.walk(real_path):
979+
for filename in files:
980+
real_file = pathlib.Path(root, filename)
981+
yield make_file(real_file.relative_to(real_sitedir))
982+
else:
983+
yield package_path
984+
985+
964986
def _top_level_inferred(dist):
965987
opt_names = {
966988
f.parts[0] if len(f.parts) > 1 else inspect.getmodulename(f)
967-
for f in always_iterable(dist.files)
989+
for f in _walk_dirs(always_iterable(dist.files))
968990
}
969991

970992
@pass_none

0 commit comments

Comments
 (0)