Commit 9bb11490 authored by Jason R. Coombs's avatar Jason R. Coombs

Unify the entry point template.

parent 1d841d78
...@@ -2070,33 +2070,37 @@ class ScriptWriter: ...@@ -2070,33 +2070,37 @@ class ScriptWriter:
gui apps. gui apps.
""" """
if sys.version_info >= (3, 8):
template = textwrap.dedent(r""" template = textwrap.dedent(r"""
# EASY-INSTALL-ENTRY-SCRIPT: %(spec)r,%(group)r,%(name)r # EASY-INSTALL-ENTRY-SCRIPT: %(spec)r,%(group)r,%(name)r
import re import re
import sys import sys
from importlib.metadata import distribution
if __name__ == '__main__': try:
sys.argv[0] = re.sub(r'(-script\.pyw?|\.exe)?$', '', sys.argv[0]) from importlib.metadata import distribution
for entry_point in distribution(%(spec)r.split('==')[0]).entry_points: except ImportError:
if entry_point.group == %(group)r and entry_point.name == %(name)r: try:
sys.exit(entry_point.load()()) from importlib_metadata import distribution
""").lstrip() # noqa: E501 except ImportError:
else:
template = textwrap.dedent(r"""
# EASY-INSTALL-ENTRY-SCRIPT: %(spec)r,%(group)r,%(name)r
__requires__ = %(spec)r
import re
import sys
from pkg_resources import load_entry_point from pkg_resources import load_entry_point
def importlib_load_entry_point(spec, group, name):
dist_name, _, _ = spec.partition('==')
matches = (
entry_point
for entry_point in distribution(dist_name).entry_points
if entry_point.group == group and entry_point.name == name
)
return next(matches).load()
globals().setdefault('load_entry_point', importlib_load_entry_point)
if __name__ == '__main__': if __name__ == '__main__':
sys.argv[0] = re.sub(r'(-script\.pyw?|\.exe)?$', '', sys.argv[0]) sys.argv[0] = re.sub(r'(-script\.pyw?|\.exe)?$', '', sys.argv[0])
sys.exit( sys.exit(load_entry_point(%(spec)r, %(group)r, %(name)r)())
load_entry_point(%(spec)r, %(group)r, %(name)r)() """).lstrip()
)
""").lstrip() # noqa: E501
command_spec_class = CommandSpec command_spec_class = CommandSpec
......
Markdown is supported
0%
or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment