1818from ._collections import FreezableDefaultDict , Pair
1919from ._compat import (
2020 NullFinder ,
21- PyPy_repr ,
2221 install ,
2322 pypy_partial ,
2423)
@@ -126,9 +125,7 @@ def valid(line):
126125 return line and not line .startswith ('#' )
127126
128127
129- class EntryPoint (
130- PyPy_repr , collections .namedtuple ('EntryPointBase' , 'name value group' )
131- ):
128+ class EntryPoint :
132129 """An entry point as defined by Python packaging conventions.
133130
134131 See `the packaging docs on entry points
@@ -159,6 +156,9 @@ class EntryPoint(
159156
160157 dist : Optional ['Distribution' ] = None
161158
159+ def __init__ (self , * , name , value , group ):
160+ vars (self ).update (name = name , value = value , group = group )
161+
162162 def load (self ):
163163 """Load the entry point from its definition. If only a module
164164 is indicated by the value, return that module. Otherwise,
@@ -185,7 +185,7 @@ def extras(self):
185185 return list (re .finditer (r'\w+' , match .group ('extras' ) or '' ))
186186
187187 def _for (self , dist ):
188- self . dist = dist
188+ vars ( self ). update ( dist = dist )
189189 return self
190190
191191 def __iter__ (self ):
@@ -199,16 +199,31 @@ def __iter__(self):
199199 warnings .warn (msg , DeprecationWarning )
200200 return iter ((self .name , self ))
201201
202- def __reduce__ (self ):
203- return (
204- self .__class__ ,
205- (self .name , self .value , self .group ),
206- )
207-
208202 def matches (self , ** params ):
209203 attrs = (getattr (self , param ) for param in params )
210204 return all (map (operator .eq , params .values (), attrs ))
211205
206+ def _key (self ):
207+ return tuple (getattr (self , key ) for key in 'name value group' .split ())
208+
209+ def __lt__ (self , other ):
210+ return self ._key () < other ._key ()
211+
212+ def __eq__ (self , other ):
213+ return self ._key () == other ._key ()
214+
215+ def __setattr__ (self , name , value ):
216+ raise AttributeError ("EntryPoint objects are immutable." )
217+
218+ def __repr__ (self ):
219+ return (
220+ f'EntryPoint(name={ self .name !r} , value={ self .value !r} , '
221+ f'group={ self .group !r} )'
222+ )
223+
224+ def __hash__ (self ):
225+ return hash (self ._key ())
226+
212227
213228class DeprecatedList (list ):
214229 """
@@ -356,15 +371,11 @@ def groups(self):
356371 def _from_text_for (cls , text , dist ):
357372 return cls (ep ._for (dist ) for ep in cls ._from_text (text ))
358373
359- @classmethod
360- def _from_text (cls , text ):
361- return itertools .starmap (EntryPoint , cls ._parse_groups (text or '' ))
362-
363374 @staticmethod
364- def _parse_groups (text ):
375+ def _from_text (text ):
365376 return (
366- ( item .value .name , item .value .value , item .name )
367- for item in Sectioned .section_pairs (text )
377+ EntryPoint ( name = item .value .name , value = item .value .value , group = item .name )
378+ for item in Sectioned .section_pairs (text or '' )
368379 )
369380
370381
0 commit comments