]>
crepu.dev Git - config.git/blob - djavu-asus/elpy/rpc-venv/lib/python3.11/site-packages/setuptools/_entry_points.py
5 from .errors
import OptionError
6 from .extern
.jaraco
.text
import yield_lines
7 from .extern
.jaraco
.functools
import pass_none
8 from ._importlib
import metadata
9 from ._itertools
import ensure_unique
10 from .extern
.more_itertools
import consume
15 Exercise one of the dynamic properties to trigger
20 except AttributeError as ex
:
22 f
"Problems to parse {ep}.\nPlease ensure entry-point follows the spec: "
23 "https://packaging.python.org/en/latest/specifications/entry-points/"
25 raise OptionError(msg
) from ex
28 def load_group(value
, group
):
30 Given a value of an entry point or series of entry points,
31 return each as an EntryPoint.
33 # normalize to a single sequence of lines
34 lines
= yield_lines(value
)
35 text
= f
'[{group}]\n' + '\n'.join(lines
)
36 return metadata
.EntryPoints
._from
_text
(text
)
39 def by_group_and_name(ep
):
40 return ep
.group
, ep
.name
43 def validate(eps
: metadata
.EntryPoints
):
45 Ensure entry points are unique by group and name and validate each.
47 consume(map(ensure_valid
, ensure_unique(eps
, key
=by_group_and_name
)))
51 @functools.singledispatch
54 Given a Distribution.entry_points, produce EntryPoints.
56 groups
= itertools
.chain
.from_iterable(
57 load_group(value
, group
)
58 for group
, value
in eps
.items())
59 return validate(metadata
.EntryPoints(groups
))
65 >>> ep, = load('[console_scripts]\nfoo=bar')
73 return validate(metadata
.EntryPoints(metadata
.EntryPoints
._from
_text
(eps
)))
76 load
.register(type(None), lambda x
: x
)
80 def render(eps
: metadata
.EntryPoints
):
81 by_group
= operator
.attrgetter('group')
82 groups
= itertools
.groupby(sorted(eps
, key
=by_group
), by_group
)
85 f
'[{group}]\n{render_items(items)}\n'
86 for group
, items
in groups
90 def render_items(eps
):
92 f
'{ep.name} = {ep.value}'