Skip to content

Commit

Permalink
Merge pull request #381 from python/bugfix/entry-points-unique-normal…
Browse files Browse the repository at this point in the history
…ized

Fix expectation on unique packages to include normalization.
  • Loading branch information
jaraco committed May 21, 2022
2 parents 4c7ef61 + 21bacb9 commit 2ee86fc
Show file tree
Hide file tree
Showing 3 changed files with 11 additions and 4 deletions.
4 changes: 4 additions & 0 deletions CHANGES.rst
Expand Up @@ -3,6 +3,10 @@ v4.11.4

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

v4.11.3
=======
Expand Down
5 changes: 4 additions & 1 deletion importlib_metadata/__init__.py
Expand Up @@ -956,7 +956,10 @@ def _normalized_name(self):
normalized name from the file system path.
"""
stem = os.path.basename(str(self._path))
return self._name_from_stem(stem) or super()._normalized_name
return (
pass_none(Prepared.normalize)(self._name_from_stem(stem))
or super()._normalized_name
)

@staticmethod
def _name_from_stem(stem):
Expand Down
6 changes: 3 additions & 3 deletions tests/test_api.py
Expand Up @@ -89,15 +89,15 @@ def test_entry_points_distribution(self):
self.assertIn(ep.dist.name, ('distinfo-pkg', 'egginfo-pkg'))
self.assertEqual(ep.dist.version, "1.0.0")

def test_entry_points_unique_packages(self):
def test_entry_points_unique_packages_normalized(self):
"""
Entry points should only be exposed for the first package
on sys.path with a given name.
on sys.path with a given name (even when normalized).
"""
alt_site_dir = self.fixtures.enter_context(fixtures.tempdir())
self.fixtures.enter_context(self.add_sys_path(alt_site_dir))
alt_pkg = {
"distinfo_pkg-1.1.0.dist-info": {
"DistInfo_pkg-1.1.0.dist-info": {
"METADATA": """
Name: distinfo-pkg
Version: 1.1.0
Expand Down

0 comments on commit 2ee86fc

Please sign in to comment.