Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Fix expectation on unique packages to include normalization. #381

Merged
merged 3 commits into from May 21, 2022
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Jump to
Jump to file
Failed to load files.
Diff view
Diff view
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