Skip to content

Commit f604d3e

Browse files
authored
Merge pull request #453 from jherland/symlinked-packages-work
Detecting and handling PDM's symlinked packages
2 parents 62144eb + 53e47d9 commit f604d3e

File tree

3 files changed

+35
-2
lines changed

3 files changed

+35
-2
lines changed

CHANGES.rst

Lines changed: 7 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,3 +1,10 @@
1+
v6.7.0
2+
======
3+
4+
* #453: When inferring top-level names that are importable for
5+
distributions in ``package_distributions``, now symlinks to
6+
other directories are honored.
7+
18
v6.6.0
29
======
310

importlib_metadata/__init__.py

Lines changed: 6 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -981,30 +981,34 @@ def _topmost(name: PackagePath) -> Optional[str]:
981981
return top if rest else None
982982

983983

984-
def _get_toplevel_name(name: PackagePath) -> Optional[str]:
984+
def _get_toplevel_name(name: PackagePath) -> str:
985985
"""
986986
Infer a possibly importable module name from a name presumed on
987987
sys.path.
988988
989989
>>> _get_toplevel_name(PackagePath('foo.py'))
990990
'foo'
991+
>>> _get_toplevel_name(PackagePath('foo'))
992+
'foo'
991993
>>> _get_toplevel_name(PackagePath('foo.pyc'))
992994
'foo'
993995
>>> _get_toplevel_name(PackagePath('foo/__init__.py'))
994996
'foo'
995997
>>> _get_toplevel_name(PackagePath('foo.pth'))
998+
'foo.pth'
996999
>>> _get_toplevel_name(PackagePath('foo.dist-info'))
1000+
'foo.dist-info'
9971001
"""
9981002
return _topmost(name) or (
9991003
# python/typeshed#10328
10001004
inspect.getmodulename(name) # type: ignore
1005+
or str(name)
10011006
)
10021007

10031008

10041009
def _top_level_inferred(dist):
10051010
opt_names = set(map(_get_toplevel_name, always_iterable(dist.files)))
10061011

1007-
@pass_none
10081012
def importable_name(name):
10091013
return '.' not in name
10101014

tests/test_main.py

Lines changed: 22 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -9,6 +9,7 @@
99

1010
from . import fixtures
1111
from ._context import suppress
12+
from ._path import Symlink
1213
from importlib_metadata import (
1314
Distribution,
1415
EntryPoint,
@@ -399,6 +400,27 @@ def test_packages_distributions_all_module_types(self):
399400

400401
assert not any(name.endswith('.dist-info') for name in distributions)
401402

403+
def test_packages_distributions_symlinked_top_level(self):
404+
"""
405+
Distribution is resolvable from a simple top-level symlink in RECORD.
406+
See #452.
407+
"""
408+
409+
files: fixtures.FilesSpec = {
410+
"symlinked_pkg-1.0.0.dist-info": {
411+
"METADATA": """
412+
Name: symlinked-pkg
413+
Version: 1.0.0
414+
""",
415+
"RECORD": "symlinked,,\n",
416+
},
417+
".symlink.target": {},
418+
"symlinked": Symlink(".symlink.target"),
419+
}
420+
421+
fixtures.build_files(files, self.site_dir)
422+
assert packages_distributions()['symlinked'] == ['symlinked-pkg']
423+
402424

403425
class PackagesDistributionsEggTest(
404426
fixtures.EggInfoPkg,

0 commit comments

Comments
 (0)