python / importlib_metadata

Library to access metadata for Python packages
https://importlib-metadata.readthedocs.io
Apache License 2.0
123 stars 80 forks source link

Distribution._normalized_name for .egg-info has 'egg' in it. #413

Closed jaraco closed 1 year ago

jaraco commented 1 year ago

In https://github.com/jaraco/keyring/issues/526#issuecomment-1304167862, I learned that _normalized_name for .egg-info distributions is resolving to <pkg>.egg and thus is unique against the same package with .dist-info, failing the expectation that entry points for a given package are loaded only once.

jaraco commented 1 year ago

I've managed to put together a test that captures the failure, but the test passes on 4.11.4, failing on 4.11.3 and earlier only:

 importlib_metadata afdb973b3e $ git diff --cached
diff --git a/tests/test_main.py b/tests/test_main.py
index 215662dd04..8583146f2a 100644
--- a/tests/test_main.py
+++ b/tests/test_main.py
@@ -121,6 +121,23 @@ class NameNormalizationTests(fixtures.OnSysPath, fixtures.SiteDir, unittest.Test

         assert len(after) == len(before)

+    def test_egg_and_dist_same(self):
+        """
+        Two distributions varying only by metadata style should resolve
+        as the same.
+        """
+        dist_info = {'storytime.dist-info': dict(METADATA='VERSION: 1.0\n')}
+        fixtures.build_files(dist_info, self.site_dir)
+        egg_info = {'storytime.egg-info': dict(METADATA='VERSION: 1.0\n')}
+        fixtures.build_files(egg_info, self.site_dir)
+        dists = [
+            dist
+            for dist in distributions()
+            if dist._normalized_name.startswith('storytime')
+        ]
+        assert len(dists) == 2
+        assert all(dist._normalized_name == 'storytime' for dist in dists)
+
jaraco commented 1 year ago

Indeed, the issue is a duplicate of #377.