Skip to content

Commit

Permalink
Move selectable groups after DeprecatedDict
Browse files Browse the repository at this point in the history
  • Loading branch information
jaraco committed Mar 4, 2021
1 parent 1f2a89c commit 401c041
Showing 1 changed file with 36 additions and 36 deletions.
72 changes: 36 additions & 36 deletions importlib_metadata/__init__.py
Original file line number Diff line number Diff line change
Expand Up @@ -193,42 +193,6 @@ def _from_text_for(cls, text, dist):
return cls(ep._for(dist) for ep in EntryPoint._from_text(text))


class SelectableGroups(dict):
"""
A backward- and forward-compatible result from
entry_points that fully implements the dict interface.
"""

@classmethod
def load(cls, eps):
by_group = operator.attrgetter('group')
ordered = sorted(eps, key=by_group)
grouped = itertools.groupby(ordered, by_group)
return cls((group, EntryPoints(eps)) for group, eps in grouped)

@property
def _all(self):
return EntryPoints(itertools.chain.from_iterable(self.values()))

@property
def groups(self):
return self._all.groups

@property
def names(self):
"""
for coverage:
>>> SelectableGroups().names
set()
"""
return self._all.names

def select(self, **params):
if not params:
return self
return self._all.select(**params)


class Flake8Bypass(warnings.catch_warnings, contextlib.ContextDecorator):
def __enter__(self):
super().__enter__()
Expand Down Expand Up @@ -291,6 +255,42 @@ def values(self):
return super().values()


class SelectableGroups(dict):
"""
A backward- and forward-compatible result from
entry_points that fully implements the dict interface.
"""

@classmethod
def load(cls, eps):
by_group = operator.attrgetter('group')
ordered = sorted(eps, key=by_group)
grouped = itertools.groupby(ordered, by_group)
return cls((group, EntryPoints(eps)) for group, eps in grouped)

@property
def _all(self):
return EntryPoints(itertools.chain.from_iterable(self.values()))

@property
def groups(self):
return self._all.groups

@property
def names(self):
"""
for coverage:
>>> SelectableGroups().names
set()
"""
return self._all.names

def select(self, **params):
if not params:
return self
return self._all.select(**params)


class PackagePath(pathlib.PurePosixPath):
"""A reference to a path in a package"""

Expand Down

0 comments on commit 401c041

Please sign in to comment.