Skip to content

Commit 2ee86fc

Browse files
authored
Merge pull request #381 from python/bugfix/entry-points-unique-normalized
Fix expectation on unique packages to include normalization.
2 parents 4c7ef61 + 21bacb9 commit 2ee86fc

File tree

3 files changed

+11
-4
lines changed

3 files changed

+11
-4
lines changed

CHANGES.rst

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -3,6 +3,10 @@ v4.11.4
33

44
* #377: In ``PathDistribution._name_from_stem``, avoid including
55
parts of the extension in the result.
6+
# #381: In ``PathDistribution._normalized_name``, ensure names
7+
loaded from the stem of the filename are also normalized, ensuring
8+
duplicate entry points by packages varying only by non-normalized
9+
name are hidden.
610

711
v4.11.3
812
=======

importlib_metadata/__init__.py

Lines changed: 4 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -956,7 +956,10 @@ def _normalized_name(self):
956956
normalized name from the file system path.
957957
"""
958958
stem = os.path.basename(str(self._path))
959-
return self._name_from_stem(stem) or super()._normalized_name
959+
return (
960+
pass_none(Prepared.normalize)(self._name_from_stem(stem))
961+
or super()._normalized_name
962+
)
960963

961964
@staticmethod
962965
def _name_from_stem(stem):

tests/test_api.py

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -89,15 +89,15 @@ def test_entry_points_distribution(self):
8989
self.assertIn(ep.dist.name, ('distinfo-pkg', 'egginfo-pkg'))
9090
self.assertEqual(ep.dist.version, "1.0.0")
9191

92-
def test_entry_points_unique_packages(self):
92+
def test_entry_points_unique_packages_normalized(self):
9393
"""
9494
Entry points should only be exposed for the first package
95-
on sys.path with a given name.
95+
on sys.path with a given name (even when normalized).
9696
"""
9797
alt_site_dir = self.fixtures.enter_context(fixtures.tempdir())
9898
self.fixtures.enter_context(self.add_sys_path(alt_site_dir))
9999
alt_pkg = {
100-
"distinfo_pkg-1.1.0.dist-info": {
100+
"DistInfo_pkg-1.1.0.dist-info": {
101101
"METADATA": """
102102
Name: distinfo-pkg
103103
Version: 1.1.0

0 commit comments

Comments
 (0)