diff --git a/CHANGES.rst b/CHANGES.rst index 91e3bcba..4f941897 100644 --- a/CHANGES.rst +++ b/CHANGES.rst @@ -1,3 +1,9 @@ +v4.11.4 +======= + +* #377: In ``PathDistribution._name_from_stem``, avoid including + parts of the extension in the result. + v4.11.3 ======= diff --git a/importlib_metadata/__init__.py b/importlib_metadata/__init__.py index 5ac8be23..e4e3a506 100644 --- a/importlib_metadata/__init__.py +++ b/importlib_metadata/__init__.py @@ -958,11 +958,20 @@ def _normalized_name(self): stem = os.path.basename(str(self._path)) return self._name_from_stem(stem) or super()._normalized_name - def _name_from_stem(self, stem): - name, ext = os.path.splitext(stem) + @staticmethod + def _name_from_stem(stem): + """ + >>> PathDistribution._name_from_stem('foo-3.0.egg-info') + 'foo' + >>> PathDistribution._name_from_stem('CherryPy-3.0.dist-info') + 'CherryPy' + >>> PathDistribution._name_from_stem('face.egg-info') + 'face' + """ + filename, ext = os.path.splitext(stem) if ext not in ('.dist-info', '.egg-info'): return - name, sep, rest = stem.partition('-') + name, sep, rest = filename.partition('-') return name