From 648c868e2bf83b6e23fb361108d3c796857c555d Mon Sep 17 00:00:00 2001 From: "Jason R. Coombs" Date: Sat, 21 May 2022 11:02:35 -0400 Subject: [PATCH] Merge pull request #379 from python/bugfix/egg-on-face Fix filesystem path distribution name inference parsing. --- Lib/importlib/metadata/__init__.py | 15 ++++++++++++--- 1 file changed, 12 insertions(+), 3 deletions(-) diff --git a/Lib/importlib/metadata/__init__.py b/Lib/importlib/metadata/__init__.py index b3063cd9..b70824e6 100644 --- a/Lib/importlib/metadata/__init__.py +++ b/Lib/importlib/metadata/__init__.py @@ -940,11 +940,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