18
18
from ._collections import FreezableDefaultDict , Pair
19
19
from ._compat import (
20
20
NullFinder ,
21
- PyPy_repr ,
22
21
install ,
23
22
pypy_partial ,
24
23
)
@@ -126,9 +125,7 @@ def valid(line):
126
125
return line and not line .startswith ('#' )
127
126
128
127
129
- class EntryPoint (
130
- PyPy_repr , collections .namedtuple ('EntryPointBase' , 'name value group' )
131
- ):
128
+ class EntryPoint :
132
129
"""An entry point as defined by Python packaging conventions.
133
130
134
131
See `the packaging docs on entry points
@@ -159,6 +156,9 @@ class EntryPoint(
159
156
160
157
dist : Optional ['Distribution' ] = None
161
158
159
+ def __init__ (self , * , name , value , group ):
160
+ vars (self ).update (name = name , value = value , group = group )
161
+
162
162
def load (self ):
163
163
"""Load the entry point from its definition. If only a module
164
164
is indicated by the value, return that module. Otherwise,
@@ -185,7 +185,7 @@ def extras(self):
185
185
return list (re .finditer (r'\w+' , match .group ('extras' ) or '' ))
186
186
187
187
def _for (self , dist ):
188
- self . dist = dist
188
+ vars ( self ). update ( dist = dist )
189
189
return self
190
190
191
191
def __iter__ (self ):
@@ -199,16 +199,31 @@ def __iter__(self):
199
199
warnings .warn (msg , DeprecationWarning )
200
200
return iter ((self .name , self ))
201
201
202
- def __reduce__ (self ):
203
- return (
204
- self .__class__ ,
205
- (self .name , self .value , self .group ),
206
- )
207
-
208
202
def matches (self , ** params ):
209
203
attrs = (getattr (self , param ) for param in params )
210
204
return all (map (operator .eq , params .values (), attrs ))
211
205
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
+
212
227
213
228
class DeprecatedList (list ):
214
229
"""
@@ -356,15 +371,11 @@ def groups(self):
356
371
def _from_text_for (cls , text , dist ):
357
372
return cls (ep ._for (dist ) for ep in cls ._from_text (text ))
358
373
359
- @classmethod
360
- def _from_text (cls , text ):
361
- return itertools .starmap (EntryPoint , cls ._parse_groups (text or '' ))
362
-
363
374
@staticmethod
364
- def _parse_groups (text ):
375
+ def _from_text (text ):
365
376
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 '' )
368
379
)
369
380
370
381
0 commit comments