Skip to content

Commit

Permalink
Merge pull request #379 from python/bugfix/egg-on-face
Browse files Browse the repository at this point in the history
Fix filesystem path distribution name inference parsing.
  • Loading branch information
jaraco committed May 21, 2022
2 parents c68e382 + 9deee50 commit a92fbf3
Show file tree
Hide file tree
Showing 2 changed files with 18 additions and 3 deletions.
6 changes: 6 additions & 0 deletions 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
=======

Expand Down
15 changes: 12 additions & 3 deletions importlib_metadata/__init__.py
Expand Up @@ -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


Expand Down

0 comments on commit a92fbf3

Please sign in to comment.