Skip to content

Commit e9f70d2

Browse files
authored
Merge pull request #317 from python/feature/faster-entry-points
Use normalized names to distinguish unique distributions for performance
2 parents 277d669 + abc13a2 commit e9f70d2

File tree

2 files changed

+20
-1
lines changed

2 files changed

+20
-1
lines changed

CHANGES.rst

Lines changed: 7 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,3 +1,10 @@
1+
v4.3.0
2+
=======
3+
4+
* #317: De-duplication of distributions no longer requires
5+
loading the full metadata for ``PathDistribution`` objects,
6+
entry point loading performance by ~10x.
7+
18
v4.2.0
29
=======
310

importlib_metadata/__init__.py

Lines changed: 13 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -498,6 +498,11 @@ def name(self):
498498
"""Return the 'Name' metadata for the distribution package."""
499499
return self.metadata['Name']
500500

501+
@property
502+
def _normalized_name(self):
503+
"""Return a normalized version of the name."""
504+
return Prepared.normalize(self.name)
505+
501506
@property
502507
def version(self):
503508
"""Return the 'Version' metadata for the distribution package."""
@@ -805,6 +810,12 @@ def read_text(self, filename):
805810
def locate_file(self, path):
806811
return self._path.parent / path
807812

813+
@property
814+
def _normalized_name(self):
815+
stem = os.path.basename(str(self._path))
816+
name, sep, rest = stem.partition('-')
817+
return name
818+
808819

809820
def distribution(distribution_name):
810821
"""Get the ``Distribution`` instance for the named package.
@@ -859,7 +870,8 @@ def entry_points(**params) -> Union[EntryPoints, SelectableGroups]:
859870
860871
:return: EntryPoints or SelectableGroups for all installed packages.
861872
"""
862-
unique = functools.partial(unique_everseen, key=operator.attrgetter('name'))
873+
norm_name = operator.attrgetter('_normalized_name')
874+
unique = functools.partial(unique_everseen, key=norm_name)
863875
eps = itertools.chain.from_iterable(
864876
dist.entry_points for dist in unique(distributions())
865877
)

0 commit comments

Comments
 (0)