Skip to content

Commit 7e5bae4

Browse files
committed
Remove SelectableGroups
1 parent 5fb7029 commit 7e5bae4

File tree

2 files changed

+4
-158
lines changed

2 files changed

+4
-158
lines changed

importlib_metadata/__init__.py

+4-119
Original file line numberDiff line numberDiff line change
@@ -29,7 +29,7 @@
2929
from importlib import import_module
3030
from importlib.abc import MetaPathFinder
3131
from itertools import starmap
32-
from typing import List, Mapping, Optional, Union
32+
from typing import List, Mapping, Optional
3333

3434

3535
__all__ = [
@@ -344,10 +344,6 @@ def names(self):
344344
def groups(self):
345345
"""
346346
Return the set of all groups of all entry points.
347-
348-
For coverage while SelectableGroups is present.
349-
>>> EntryPoints().groups
350-
set()
351347
"""
352348
return set(ep.group for ep in self)
353349

@@ -367,109 +363,6 @@ def _parse_groups(text):
367363
)
368364

369365

370-
def flake8_bypass(func):
371-
# defer inspect import as performance optimization.
372-
import inspect
373-
374-
is_flake8 = any('flake8' in str(frame.filename) for frame in inspect.stack()[:5])
375-
return func if not is_flake8 else lambda: None
376-
377-
378-
class Deprecated:
379-
"""
380-
Compatibility add-in for mapping to indicate that
381-
mapping behavior is deprecated.
382-
383-
>>> recwarn = getfixture('recwarn')
384-
>>> class DeprecatedDict(Deprecated, dict): pass
385-
>>> dd = DeprecatedDict(foo='bar')
386-
>>> dd.get('baz', None)
387-
>>> dd['foo']
388-
'bar'
389-
>>> list(dd)
390-
['foo']
391-
>>> list(dd.keys())
392-
['foo']
393-
>>> 'foo' in dd
394-
True
395-
>>> list(dd.values())
396-
['bar']
397-
>>> len(recwarn)
398-
1
399-
"""
400-
401-
_warn = functools.partial(
402-
warnings.warn,
403-
"SelectableGroups dict interface is deprecated. Use select.",
404-
DeprecationWarning,
405-
stacklevel=2,
406-
)
407-
408-
def __getitem__(self, name):
409-
self._warn()
410-
return super().__getitem__(name)
411-
412-
def get(self, name, default=None):
413-
flake8_bypass(self._warn)()
414-
return super().get(name, default)
415-
416-
def __iter__(self):
417-
self._warn()
418-
return super().__iter__()
419-
420-
def __contains__(self, *args):
421-
self._warn()
422-
return super().__contains__(*args)
423-
424-
def keys(self):
425-
self._warn()
426-
return super().keys()
427-
428-
def values(self):
429-
self._warn()
430-
return super().values()
431-
432-
433-
class SelectableGroups(Deprecated, dict):
434-
"""
435-
A backward- and forward-compatible result from
436-
entry_points that fully implements the dict interface.
437-
"""
438-
439-
@classmethod
440-
def load(cls, eps):
441-
by_group = operator.attrgetter('group')
442-
ordered = sorted(eps, key=by_group)
443-
grouped = itertools.groupby(ordered, by_group)
444-
return cls((group, EntryPoints(eps)) for group, eps in grouped)
445-
446-
@property
447-
def _all(self):
448-
"""
449-
Reconstruct a list of all entrypoints from the groups.
450-
"""
451-
groups = super(Deprecated, self).values()
452-
return EntryPoints(itertools.chain.from_iterable(groups))
453-
454-
@property
455-
def groups(self):
456-
return self._all.groups
457-
458-
@property
459-
def names(self):
460-
"""
461-
for coverage:
462-
>>> SelectableGroups().names
463-
set()
464-
"""
465-
return self._all.names
466-
467-
def select(self, **params):
468-
if not params:
469-
return self
470-
return self._all.select(**params)
471-
472-
473366
class PackagePath(pathlib.PurePosixPath):
474367
"""A reference to a path in a package"""
475368

@@ -964,29 +857,21 @@ def version(distribution_name):
964857
return distribution(distribution_name).version
965858

966859

967-
def entry_points(**params) -> Union[EntryPoints, SelectableGroups]:
860+
def entry_points(**params) -> EntryPoints:
968861
"""Return EntryPoint objects for all installed packages.
969862
970863
Pass selection parameters (group or name) to filter the
971864
result to entry points matching those properties (see
972865
EntryPoints.select()).
973866
974-
For compatibility, returns ``SelectableGroups`` object unless
975-
selection parameters are supplied. In the future, this function
976-
will return ``EntryPoints`` instead of ``SelectableGroups``
977-
even when no selection parameters are supplied.
978-
979-
For maximum future compatibility, pass selection parameters
980-
or invoke ``.select`` with parameters on the result.
981-
982-
:return: EntryPoints or SelectableGroups for all installed packages.
867+
:return: EntryPoints for all installed packages.
983868
"""
984869
norm_name = operator.attrgetter('_normalized_name')
985870
unique = functools.partial(unique_everseen, key=norm_name)
986871
eps = itertools.chain.from_iterable(
987872
dist.entry_points for dist in unique(distributions())
988873
)
989-
return SelectableGroups.load(eps).select(**params)
874+
return EntryPoints(eps).select(**params)
990875

991876

992877
def files(distribution_name):

tests/test_api.py

-39
Original file line numberDiff line numberDiff line change
@@ -133,45 +133,6 @@ def test_entry_points_dict_construction(self):
133133
assert expected.category is DeprecationWarning
134134
assert "Construction of dict of EntryPoints is deprecated" in str(expected)
135135

136-
def test_entry_points_by_index(self):
137-
"""
138-
Prior versions of Distribution.entry_points would return a
139-
tuple that allowed access by index.
140-
Capture this now deprecated use-case
141-
See python/importlib_metadata#300 and bpo-44246.
142-
"""
143-
eps = distribution('distinfo-pkg').entry_points
144-
with warnings.catch_warnings(record=True) as caught:
145-
eps[0]
146-
147-
# check warning
148-
expected = next(iter(caught))
149-
assert expected.category is DeprecationWarning
150-
assert "Accessing entry points by index is deprecated" in str(expected)
151-
152-
def test_entry_points_groups_getitem(self):
153-
"""
154-
Prior versions of entry_points() returned a dict. Ensure
155-
that callers using '.__getitem__()' are supported but warned to
156-
migrate.
157-
"""
158-
with warnings.catch_warnings(record=True):
159-
entry_points()['entries'] == entry_points(group='entries')
160-
161-
with self.assertRaises(KeyError):
162-
entry_points()['missing']
163-
164-
def test_entry_points_groups_get(self):
165-
"""
166-
Prior versions of entry_points() returned a dict. Ensure
167-
that callers using '.get()' are supported but warned to
168-
migrate.
169-
"""
170-
with warnings.catch_warnings(record=True):
171-
entry_points().get('missing', 'default') == 'default'
172-
entry_points().get('entries', 'default') == entry_points()['entries']
173-
entry_points().get('missing', ()) == ()
174-
175136
def test_metadata_for_this_package(self):
176137
md = metadata('egginfo-pkg')
177138
assert md['author'] == 'Steven Ma'

0 commit comments

Comments
 (0)