29
29
from importlib import import_module
30
30
from importlib .abc import MetaPathFinder
31
31
from itertools import starmap
32
- from typing import List , Mapping , Optional , Union
32
+ from typing import List , Mapping , Optional
33
33
34
34
35
35
__all__ = [
@@ -227,17 +227,6 @@ def _for(self, dist):
227
227
vars (self ).update (dist = dist )
228
228
return self
229
229
230
- def __iter__ (self ):
231
- """
232
- Supply iter so one may construct dicts of EntryPoints by name.
233
- """
234
- msg = (
235
- "Construction of dict of EntryPoints is deprecated in "
236
- "favor of EntryPoints."
237
- )
238
- warnings .warn (msg , DeprecationWarning )
239
- return iter ((self .name , self ))
240
-
241
230
def matches (self , ** params ):
242
231
"""
243
232
EntryPoint matches the given parameters.
@@ -283,77 +272,7 @@ def __hash__(self):
283
272
return hash (self ._key ())
284
273
285
274
286
- class DeprecatedList (list ):
287
- """
288
- Allow an otherwise immutable object to implement mutability
289
- for compatibility.
290
-
291
- >>> recwarn = getfixture('recwarn')
292
- >>> dl = DeprecatedList(range(3))
293
- >>> dl[0] = 1
294
- >>> dl.append(3)
295
- >>> del dl[3]
296
- >>> dl.reverse()
297
- >>> dl.sort()
298
- >>> dl.extend([4])
299
- >>> dl.pop(-1)
300
- 4
301
- >>> dl.remove(1)
302
- >>> dl += [5]
303
- >>> dl + [6]
304
- [1, 2, 5, 6]
305
- >>> dl + (6,)
306
- [1, 2, 5, 6]
307
- >>> dl.insert(0, 0)
308
- >>> dl
309
- [0, 1, 2, 5]
310
- >>> dl == [0, 1, 2, 5]
311
- True
312
- >>> dl == (0, 1, 2, 5)
313
- True
314
- >>> len(recwarn)
315
- 1
316
- """
317
-
318
- __slots__ = ()
319
-
320
- _warn = functools .partial (
321
- warnings .warn ,
322
- "EntryPoints list interface is deprecated. Cast to list if needed." ,
323
- DeprecationWarning ,
324
- stacklevel = pypy_partial (2 ),
325
- )
326
-
327
- def _wrap_deprecated_method (method_name : str ): # type: ignore
328
- def wrapped (self , * args , ** kwargs ):
329
- self ._warn ()
330
- return getattr (super (), method_name )(* args , ** kwargs )
331
-
332
- return method_name , wrapped
333
-
334
- locals ().update (
335
- map (
336
- _wrap_deprecated_method ,
337
- '__setitem__ __delitem__ append reverse extend pop remove '
338
- '__iadd__ insert sort' .split (),
339
- )
340
- )
341
-
342
- def __add__ (self , other ):
343
- if not isinstance (other , tuple ):
344
- self ._warn ()
345
- other = tuple (other )
346
- return self .__class__ (tuple (self ) + other )
347
-
348
- def __eq__ (self , other ):
349
- if not isinstance (other , tuple ):
350
- self ._warn ()
351
- other = tuple (other )
352
-
353
- return tuple (self ).__eq__ (other )
354
-
355
-
356
- class EntryPoints (DeprecatedList ):
275
+ class EntryPoints (tuple ):
357
276
"""
358
277
An immutable collection of selectable EntryPoint objects.
359
278
"""
@@ -364,14 +283,6 @@ def __getitem__(self, name): # -> EntryPoint:
364
283
"""
365
284
Get the EntryPoint in self matching name.
366
285
"""
367
- if isinstance (name , int ):
368
- warnings .warn (
369
- "Accessing entry points by index is deprecated. "
370
- "Cast to tuple if needed." ,
371
- DeprecationWarning ,
372
- stacklevel = 2 ,
373
- )
374
- return super ().__getitem__ (name )
375
286
try :
376
287
return next (iter (self .select (name = name )))
377
288
except StopIteration :
@@ -396,10 +307,6 @@ def names(self):
396
307
def groups (self ):
397
308
"""
398
309
Return the set of all groups of all entry points.
399
-
400
- For coverage while SelectableGroups is present.
401
- >>> EntryPoints().groups
402
- set()
403
310
"""
404
311
return {ep .group for ep in self }
405
312
@@ -415,101 +322,6 @@ def _from_text(text):
415
322
)
416
323
417
324
418
- class Deprecated :
419
- """
420
- Compatibility add-in for mapping to indicate that
421
- mapping behavior is deprecated.
422
-
423
- >>> recwarn = getfixture('recwarn')
424
- >>> class DeprecatedDict(Deprecated, dict): pass
425
- >>> dd = DeprecatedDict(foo='bar')
426
- >>> dd.get('baz', None)
427
- >>> dd['foo']
428
- 'bar'
429
- >>> list(dd)
430
- ['foo']
431
- >>> list(dd.keys())
432
- ['foo']
433
- >>> 'foo' in dd
434
- True
435
- >>> list(dd.values())
436
- ['bar']
437
- >>> len(recwarn)
438
- 1
439
- """
440
-
441
- _warn = functools .partial (
442
- warnings .warn ,
443
- "SelectableGroups dict interface is deprecated. Use select." ,
444
- DeprecationWarning ,
445
- stacklevel = pypy_partial (2 ),
446
- )
447
-
448
- def __getitem__ (self , name ):
449
- self ._warn ()
450
- return super ().__getitem__ (name )
451
-
452
- def get (self , name , default = None ):
453
- self ._warn ()
454
- return super ().get (name , default )
455
-
456
- def __iter__ (self ):
457
- self ._warn ()
458
- return super ().__iter__ ()
459
-
460
- def __contains__ (self , * args ):
461
- self ._warn ()
462
- return super ().__contains__ (* args )
463
-
464
- def keys (self ):
465
- self ._warn ()
466
- return super ().keys ()
467
-
468
- def values (self ):
469
- self ._warn ()
470
- return super ().values ()
471
-
472
-
473
- class SelectableGroups (Deprecated , dict ):
474
- """
475
- A backward- and forward-compatible result from
476
- entry_points that fully implements the dict interface.
477
- """
478
-
479
- @classmethod
480
- def load (cls , eps ):
481
- by_group = operator .attrgetter ('group' )
482
- ordered = sorted (eps , key = by_group )
483
- grouped = itertools .groupby (ordered , by_group )
484
- return cls ((group , EntryPoints (eps )) for group , eps in grouped )
485
-
486
- @property
487
- def _all (self ):
488
- """
489
- Reconstruct a list of all entrypoints from the groups.
490
- """
491
- groups = super (Deprecated , self ).values ()
492
- return EntryPoints (itertools .chain .from_iterable (groups ))
493
-
494
- @property
495
- def groups (self ):
496
- return self ._all .groups
497
-
498
- @property
499
- def names (self ):
500
- """
501
- for coverage:
502
- >>> SelectableGroups().names
503
- set()
504
- """
505
- return self ._all .names
506
-
507
- def select (self , ** params ):
508
- if not params :
509
- return self
510
- return self ._all .select (** params )
511
-
512
-
513
325
class PackagePath (pathlib .PurePosixPath ):
514
326
"""A reference to a path in a package"""
515
327
@@ -1029,27 +841,19 @@ def version(distribution_name):
1029
841
"""
1030
842
1031
843
1032
- def entry_points (** params ) -> Union [ EntryPoints , SelectableGroups ] :
844
+ def entry_points (** params ) -> EntryPoints :
1033
845
"""Return EntryPoint objects for all installed packages.
1034
846
1035
847
Pass selection parameters (group or name) to filter the
1036
848
result to entry points matching those properties (see
1037
849
EntryPoints.select()).
1038
850
1039
- For compatibility, returns ``SelectableGroups`` object unless
1040
- selection parameters are supplied. In the future, this function
1041
- will return ``EntryPoints`` instead of ``SelectableGroups``
1042
- even when no selection parameters are supplied.
1043
-
1044
- For maximum future compatibility, pass selection parameters
1045
- or invoke ``.select`` with parameters on the result.
1046
-
1047
- :return: EntryPoints or SelectableGroups for all installed packages.
851
+ :return: EntryPoints for all installed packages.
1048
852
"""
1049
853
eps = itertools .chain .from_iterable (
1050
854
dist .entry_points for dist in _unique (distributions ())
1051
855
)
1052
- return SelectableGroups . load (eps ).select (** params )
856
+ return EntryPoints (eps ).select (** params )
1053
857
1054
858
1055
859
def files (distribution_name ):
0 commit comments