Skip to content

Commit

Permalink
Merge pull request #317 from python/feature/faster-entry-points
Browse files Browse the repository at this point in the history
Use normalized names to distinguish unique distributions for performance
  • Loading branch information
jaraco committed May 27, 2021
2 parents 277d669 + abc13a2 commit e9f70d2
Show file tree
Hide file tree
Showing 2 changed files with 20 additions and 1 deletion.
7 changes: 7 additions & 0 deletions CHANGES.rst
@@ -1,3 +1,10 @@
v4.3.0
=======

* #317: De-duplication of distributions no longer requires
loading the full metadata for ``PathDistribution`` objects,
entry point loading performance by ~10x.

v4.2.0
=======

Expand Down
14 changes: 13 additions & 1 deletion importlib_metadata/__init__.py
Expand Up @@ -498,6 +498,11 @@ def name(self):
"""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."""
Expand Down Expand Up @@ -805,6 +810,12 @@ def read_text(self, filename):
def locate_file(self, path):
return self._path.parent / path

@property
def _normalized_name(self):
stem = os.path.basename(str(self._path))
name, sep, rest = stem.partition('-')
return name


def distribution(distribution_name):
"""Get the ``Distribution`` instance for the named package.
Expand Down Expand Up @@ -859,7 +870,8 @@ def entry_points(**params) -> Union[EntryPoints, SelectableGroups]:
: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())
)
Expand Down

0 comments on commit e9f70d2

Please sign in to comment.