summaryrefslogtreecommitdiff
path: root/setuptools
diff options
context:
space:
mode:
authorJason R. Coombs <jaraco@jaraco.com>2022-02-06 12:43:29 -0500
committerJason R. Coombs <jaraco@jaraco.com>2022-02-06 13:46:02 -0500
commitb257d137ae2bcf1ef2e188f20e60f3ca5770e090 (patch)
tree4f5bf0e3c019814e1ad92d1060843cf0ef088417 /setuptools
parent161ff0ff6f679967d323e9fd461eff312d0f12e6 (diff)
downloadpython-setuptools-git-b257d137ae2bcf1ef2e188f20e60f3ca5770e090.tar.gz
In egg_info, port use of pkg_resources.EntryPoint to importlib.metadata
Diffstat (limited to 'setuptools')
-rw-r--r--setuptools/_itertools.py23
-rw-r--r--setuptools/command/egg_info.py14
2 files changed, 34 insertions, 3 deletions
diff --git a/setuptools/_itertools.py b/setuptools/_itertools.py
new file mode 100644
index 00000000..b8bf6d21
--- /dev/null
+++ b/setuptools/_itertools.py
@@ -0,0 +1,23 @@
+from setuptools.extern.more_itertools import consume # noqa: F401
+
+
+# copied from jaraco.itertools 6.1
+def ensure_unique(iterable, key=lambda x: x):
+ """
+ Wrap an iterable to raise a ValueError if non-unique values are encountered.
+
+ >>> list(ensure_unique('abc'))
+ ['a', 'b', 'c']
+ >>> consume(ensure_unique('abca'))
+ Traceback (most recent call last):
+ ...
+ ValueError: Duplicate element 'a' encountered.
+ """
+ seen = set()
+ seen_add = seen.add
+ for element in iterable:
+ k = key(element)
+ if k in seen:
+ raise ValueError(f"Duplicate element {element!r} encountered.")
+ seen_add(k)
+ yield element
diff --git a/setuptools/command/egg_info.py b/setuptools/command/egg_info.py
index afab5cd6..2ed58eef 100644
--- a/setuptools/command/egg_info.py
+++ b/setuptools/command/egg_info.py
@@ -16,8 +16,10 @@ import io
import warnings
import time
import collections
+import operator
from .._importlib import metadata
+from .._itertools import ensure_unique
from setuptools import Command
from setuptools.command.sdist import sdist
@@ -26,7 +28,7 @@ from setuptools.command.setopt import edit_config
from setuptools.command import bdist_egg
from pkg_resources import (
Requirement, safe_name, parse_version,
- safe_version, yield_lines, EntryPoint, to_filename)
+ safe_version, yield_lines, to_filename)
import setuptools.unicode_utils as unicode_utils
from setuptools.glob import glob
@@ -721,8 +723,14 @@ def entry_point_definition_to_str(value):
Given a value of an entry point or series of entry points,
return each entry point on a single line.
"""
- parsed = EntryPoint.parse_group('anything', value)
- return '\n'.join(sorted(map(str, parsed.values())))
+ # normalize to a single sequence of lines
+ lines = yield_lines(value)
+ parsed = metadata.EntryPoints._from_text('[x]\n' + '\n'.join(lines))
+ valid = ensure_unique(parsed, key=operator.attrgetter('name'))
+
+ def ep_to_str(ep):
+ return f'{ep.name} = {ep.value}'
+ return '\n'.join(sorted(map(ep_to_str, valid)))
entry_point_definition_to_str.register(str, lambda x: x)