Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Remove unique_everseen #347

Closed
wants to merge 1 commit into from
Closed
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
21 changes: 13 additions & 8 deletions importlib_metadata/__init__.py
Original file line number Diff line number Diff line change
Expand Up @@ -23,14 +23,14 @@
pypy_partial,
)
from ._functools import method_cache
from ._itertools import always_iterable, unique_everseen
from ._itertools import always_iterable
from ._meta import PackageMetadata, SimplePath

from contextlib import suppress
from importlib import import_module
from importlib.abc import MetaPathFinder
from itertools import starmap
from typing import List, Mapping, Optional, Union
from typing import Iterator, List, Mapping, Optional, Set, Union


__all__ = [
Expand Down Expand Up @@ -957,6 +957,16 @@ def version(distribution_name):
return distribution(distribution_name).version


def _entry_points_iter() -> Iterator[EntryPoint]:
seen: Set[Optional[str]] = set()
seen_add = seen.add
for dist in distributions():
k = dist._normalized_name
if k not in seen:
seen_add(k)
yield from dist.entry_points


def entry_points(**params) -> Union[EntryPoints, SelectableGroups]:
"""Return EntryPoint objects for all installed packages.

Expand All @@ -974,12 +984,7 @@ def entry_points(**params) -> Union[EntryPoints, SelectableGroups]:

:return: EntryPoints or SelectableGroups for all installed packages.
"""
norm_name = operator.attrgetter('_normalized_name')
unique = functools.partial(unique_everseen, key=norm_name)
eps = itertools.chain.from_iterable(
dist.entry_points for dist in unique(distributions())
)
return SelectableGroups.load(eps).select(**params)
return SelectableGroups.load(_entry_points_iter()).select(**params)


def files(distribution_name):
Expand Down
21 changes: 0 additions & 21 deletions importlib_metadata/_itertools.py
Original file line number Diff line number Diff line change
@@ -1,24 +1,3 @@
from itertools import filterfalse


def unique_everseen(iterable, key=None):
"List unique elements, preserving order. Remember all elements ever seen."
# unique_everseen('AAAABBBCCDAABBB') --> A B C D
# unique_everseen('ABBCcAD', str.lower) --> A B C D
seen = set()
seen_add = seen.add
if key is None:
for element in filterfalse(seen.__contains__, iterable):
seen_add(element)
yield element
else:
for element in iterable:
k = key(element)
if k not in seen:
seen_add(k)
yield element


# copied from more_itertools 8.8
def always_iterable(obj, base_type=(str, bytes)):
"""If *obj* is iterable, return an iterator over its items::
Expand Down