@@ -493,6 +493,11 @@ def name(self):
493
493
"""Return the 'Name' metadata for the distribution package."""
494
494
return self .metadata ['Name' ]
495
495
496
+ @property
497
+ def _normalized_name (self ):
498
+ """Return a normalized version of the name."""
499
+ return Prepared .normalize (self .name )
500
+
496
501
@property
497
502
def version (self ):
498
503
"""Return the 'Version' metadata for the distribution package."""
@@ -795,6 +800,22 @@ def read_text(self, filename):
795
800
def locate_file (self , path ):
796
801
return self ._path .parent / path
797
802
803
+ @property
804
+ def _normalized_name (self ):
805
+ """
806
+ Performance optimization: where possible, resolve the
807
+ normalized name from the file system path.
808
+ """
809
+ stem = os .path .basename (str (self ._path ))
810
+ return self ._name_from_stem (stem ) or super ()._normalized_name
811
+
812
+ def _name_from_stem (self , stem ):
813
+ name , ext = os .path .splitext (stem )
814
+ if ext not in ('.dist-info' , '.egg-info' ):
815
+ return
816
+ name , sep , rest = stem .partition ('-' )
817
+ return name
818
+
798
819
799
820
def distribution (distribution_name ):
800
821
"""Get the ``Distribution`` instance for the named package.
@@ -849,7 +870,8 @@ def entry_points(**params) -> Union[EntryPoints, SelectableGroups]:
849
870
850
871
:return: EntryPoints or SelectableGroups for all installed packages.
851
872
"""
852
- 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 )
853
875
eps = itertools .chain .from_iterable (
854
876
dist .entry_points for dist in unique (distributions ())
855
877
)
0 commit comments