Commit f4a592c1 authored by Jason R. Coombs's avatar Jason R. Coombs

Now load legacy scripts wrappers from templates in the package, which get...

Now load legacy scripts wrappers from templates in the package, which get converted to Python 3 syntax when built on Python 3. Fixes #273.

--HG--
branch : distribute
extra : rebase_source : 900842f8a9e70d347296f7b076c6113ead6f7318
parent d7907a5c
...@@ -16,6 +16,7 @@ CHANGES ...@@ -16,6 +16,7 @@ CHANGES
* Issue #272: Prevent TypeError when namespace package names are unicode * Issue #272: Prevent TypeError when namespace package names are unicode
and single-install-externally-managed is used. Also fixes PIP issue and single-install-externally-managed is used. Also fixes PIP issue
449. 449.
* Issue #273: Legacy script launchers now install with Python2/3 support.
------ ------
0.6.24 0.6.24
......
...@@ -731,22 +731,26 @@ Please make the appropriate changes for your system and try again. ...@@ -731,22 +731,26 @@ Please make the appropriate changes for your system and try again.
spec = str(dist.as_requirement()) spec = str(dist.as_requirement())
is_script = is_python_script(script_text, script_name) is_script = is_python_script(script_text, script_name)
if is_script and dev_path: def get_template(filename):
script_text = get_script_header(script_text) + ( """
"# EASY-INSTALL-DEV-SCRIPT: %(spec)r,%(script_name)r\n" There are a couple of template scripts in the package. This
"__requires__ = %(spec)r\n" function loads one of them and prepares it for use.
"from pkg_resources import require; require(%(spec)r)\n"
"del require\n" These templates use triple-quotes to escape variable
"__file__ = %(dev_path)r\n" substitutions so the scripts get the 2to3 treatment when build
"execfile(__file__)\n" on Python 3. The templates cannot use triple-quotes naturally.
) % locals() """
elif is_script: raw_bytes = resource_string('setuptools', template_name)
script_text = get_script_header(script_text) + ( template_str = raw_bytes.decode('utf-8')
"# EASY-INSTALL-SCRIPT: %(spec)r,%(script_name)r\n" clean_template = template_str.replace('"""', '')
"__requires__ = %(spec)r\n" return clean_template
"import pkg_resources\n"
"pkg_resources.run_script(%(spec)r, %(script_name)r)\n" if is_script:
) % locals() template_name = 'script template.py'
if dev_path:
template_name = template_name.replace('.py', ' (dev).py')
script_text = (get_script_header(script_text) +
get_template(template_name) % locals())
self.write_script(script_name, _to_ascii(script_text), 'b') self.write_script(script_name, _to_ascii(script_text), 'b')
def write_script(self, script_name, contents, mode="t", blockers=()): def write_script(self, script_name, contents, mode="t", blockers=()):
......
# EASY-INSTALL-DEV-SCRIPT: %(spec)r,%(script_name)r
__requires__ = """%(spec)r"""
from pkg_resources import require; require("""%(spec)r""")
del require
__file__ = """%(dev_path)r"""
execfile(__file__)
# EASY-INSTALL-SCRIPT: %(spec)r,%(script_name)r
__requires__ = """%(spec)r"""
import pkg_resources
pkg_resources.run_script("""%(spec)r""", """%(script_name)r""")
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