"""Return the 'Name' metadata for the distribution package."""
return self.metadata['Name']
+ @property
+ def _normalized_name(self):
+ """Return a normalized version of the name."""
+ return Prepared.normalize(self.name)
+
@property
def version(self):
"""Return the 'Version' metadata for the distribution package."""
def locate_file(self, path):
return self._path.parent / path
+ @property
+ def _normalized_name(self):
+ """
+ Performance optimization: where possible, resolve the
+ normalized name from the file system path.
+ """
+ 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)
+ if ext not in ('.dist-info', '.egg-info'):
+ return
+ name, sep, rest = stem.partition('-')
+ return name
+
def distribution(distribution_name):
"""Get the ``Distribution`` instance for the named package.
:return: EntryPoints or SelectableGroups for all installed packages.
"""
- unique = functools.partial(unique_everseen, key=operator.attrgetter('name'))
+ norm_name = operator.attrgetter('_normalized_name')
+ unique = functools.partial(unique_everseen, key=norm_name)
eps = itertools.chain.from_iterable(
dist.entry_points for dist in unique(distributions())
)
for file in files('example'):
path = str(file.dist.locate_file(file))
assert '.egg/' in path, path
+
+ def test_normalized_name(self):
+ dist = distribution('example')
+ assert dist._normalized_name == 'example'