diff options
author | Jason R. Coombs <jaraco@jaraco.com> | 2020-06-15 17:19:42 -0400 |
---|---|---|
committer | Jason R. Coombs <jaraco@jaraco.com> | 2020-06-15 17:19:42 -0400 |
commit | b88c8849a58346700eccdf3b44aa6b57a4b6ebcf (patch) | |
tree | 8c019fa46747d500e463a4d76ffe029367740297 | |
parent | 3955acbb0da75df804d86a52d6fbcc269075a9d3 (diff) | |
download | python-setuptools-git-feature/simple-dist-name-in-scripts.tar.gz |
Avoid the full spec and only rely on the dist name when generating script wrappers.feature/simple-dist-name-in-scripts
-rw-r--r-- | setuptools/command/develop.py | 26 | ||||
-rw-r--r-- | setuptools/command/easy_install.py | 9 | ||||
-rw-r--r-- | setuptools/tests/test_easy_install.py | 7 |
3 files changed, 7 insertions, 35 deletions
diff --git a/setuptools/command/develop.py b/setuptools/command/develop.py index b5619246..5d17c04b 100644 --- a/setuptools/command/develop.py +++ b/setuptools/command/develop.py @@ -192,30 +192,4 @@ class develop(namespaces.DevelopInstaller, easy_install): self.install_script(dist, script_name, script_text, script_path) def install_wrapper_scripts(self, dist): - dist = VersionlessRequirement(dist) return easy_install.install_wrapper_scripts(self, dist) - - -class VersionlessRequirement: - """ - Adapt a pkg_resources.Distribution to simply return the project - name as the 'requirement' so that scripts will work across - multiple versions. - - >>> from pkg_resources import Distribution - >>> dist = Distribution(project_name='foo', version='1.0') - >>> str(dist.as_requirement()) - 'foo==1.0' - >>> adapted_dist = VersionlessRequirement(dist) - >>> str(adapted_dist.as_requirement()) - 'foo' - """ - - def __init__(self, dist): - self.__dist = dist - - def __getattr__(self, name): - return getattr(self.__dist, name) - - def as_requirement(self): - return self.project_name diff --git a/setuptools/command/easy_install.py b/setuptools/command/easy_install.py index 81526b9a..5d39ff16 100644 --- a/setuptools/command/easy_install.py +++ b/setuptools/command/easy_install.py @@ -2071,7 +2071,7 @@ class ScriptWriter: """ template = textwrap.dedent(r""" - # EASY-INSTALL-ENTRY-SCRIPT: %(spec)r,%(group)r,%(name)r + # EASY-INSTALL-ENTRY-SCRIPT: %(dist_name)r,%(group)r,%(name)r import re import sys @@ -2084,8 +2084,7 @@ class ScriptWriter: from pkg_resources import load_entry_point - def importlib_load_entry_point(spec, group, name): - dist_name, _, _ = spec.partition('==') + def importlib_load_entry_point(dist_name, group, name): matches = ( entry_point for entry_point in distribution(dist_name).entry_points @@ -2099,7 +2098,7 @@ class ScriptWriter: if __name__ == '__main__': sys.argv[0] = re.sub(r'(-script\.pyw?|\.exe)?$', '', sys.argv[0]) - sys.exit(load_entry_point(%(spec)r, %(group)r, %(name)r)()) + sys.exit(load_entry_point(%(dist_name)r, %(group)r, %(name)r)()) """).lstrip() command_spec_class = CommandSpec @@ -2129,7 +2128,7 @@ class ScriptWriter: """ if header is None: header = cls.get_header() - spec = str(dist.as_requirement()) + dist_name = dist.project_name for type_ in 'console', 'gui': group = type_ + '_scripts' for name, ep in dist.get_entry_map(group).items(): diff --git a/setuptools/tests/test_easy_install.py b/setuptools/tests/test_easy_install.py index 8611dc16..f9073574 100644 --- a/setuptools/tests/test_easy_install.py +++ b/setuptools/tests/test_easy_install.py @@ -45,14 +45,13 @@ __metaclass__ = type class FakeDist: + project_name = 'project' + def get_entry_map(self, group): if group != 'console_scripts': return {} return {str('name'): 'ep'} - def as_requirement(self): - return 'spec' - SETUP_PY = DALS(""" from setuptools import setup @@ -76,7 +75,7 @@ class TestEasyInstallTest: args = next(ei.ScriptWriter.get_args(dist)) name, script = itertools.islice(args, 2) assert script.startswith(header) - assert "'spec'" in script + assert "'project'" in script assert "'console_scripts'" in script assert "'name'" in script assert re.search( |