aboutsummaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
authorJason R. Coombs <jaraco@jaraco.com>2015-01-04 17:49:21 -0500
committerJason R. Coombs <jaraco@jaraco.com>2015-01-04 17:49:21 -0500
commitefba85513b5c11ddbddf785906b5b4e9b596771a (patch)
treed3a8a1c5c4cd0f5a0a265fa5814d01f6521ea11d
parent3c78eb2348dff5d493d0cd5a34aef812db8385ef (diff)
downloadexternal_python_setuptools-efba85513b5c11ddbddf785906b5b4e9b596771a.tar.gz
external_python_setuptools-efba85513b5c11ddbddf785906b5b4e9b596771a.tar.bz2
external_python_setuptools-efba85513b5c11ddbddf785906b5b4e9b596771a.zip
Extract method for handling non-ascii exe. Strip out excess whitespace from option handling.
-rwxr-xr-xsetuptools/command/easy_install.py37
-rw-r--r--setuptools/tests/test_easy_install.py4
2 files changed, 22 insertions, 19 deletions
diff --git a/setuptools/command/easy_install.py b/setuptools/command/easy_install.py
index 6ec96564..61e242d6 100755
--- a/setuptools/command/easy_install.py
+++ b/setuptools/command/easy_install.py
@@ -1922,19 +1922,11 @@ class ScriptWriter(object):
executable = nt_quote_arg(sys_executable)
options = cls._extract_options(script_text)
+ options = cls._handle_non_ascii_exe(executable, options)
+ tmpl = '#!{executable} {options}\n' if options else '#!{executable}\n'
- hdr = "#!%(executable)s%(options)s\n" % locals()
- if not isascii(hdr):
- # Non-ascii path to sys.executable, use -x to prevent warnings
- if options:
- if options.strip().startswith('-'):
- options = ' -x' + options.strip()[1:]
- # else: punt, we can't do it, let the warning happen anyway
- else:
- options = ' -x'
executable = fix_jython_executable(executable, options)
- hdr = "#!%(executable)s%(options)s\n" % locals()
- return hdr
+ return tmpl.format(**locals())
@classmethod
def _extract_options(cls, orig_script):
@@ -1943,12 +1935,23 @@ class ScriptWriter(object):
"""
first = (orig_script + '\n').splitlines()[0]
match = _first_line_re().match(first)
- options = ''
- if match:
- options = match.group(1) or ''
- if options:
- options = ' ' + options
- return options
+ options = match.group(1) or '' if match else ''
+ return options.strip()
+
+ @classmethod
+ def _handle_non_ascii_exe(cls, executable, options):
+ if isascii(executable):
+ return options
+
+ # Non-ascii path to sys.executable, use -x to prevent warnings
+ if not options:
+ return '-x'
+
+ if not options.strip().startswith('-'):
+ # punt, we can't do it, let the warning happen anyway
+ return options
+
+ return '-x' + options.strip()[1:]
class WindowsScriptWriter(ScriptWriter):
diff --git a/setuptools/tests/test_easy_install.py b/setuptools/tests/test_easy_install.py
index f919ae20..86870866 100644
--- a/setuptools/tests/test_easy_install.py
+++ b/setuptools/tests/test_easy_install.py
@@ -428,7 +428,7 @@ class TestScriptHeader:
actual = ScriptWriter.get_script_header('#!/usr/local/bin/python')
assert actual == expected
- expected = '#!%s -x\n' % nt_quote_arg(os.path.normpath(sys.executable))
+ expected = '#!%s -x\n' % nt_quote_arg(os.path.normpath(sys.executable))
actual = ScriptWriter.get_script_header('#!/usr/bin/python -x')
assert actual == expected
@@ -471,7 +471,7 @@ class TestScriptHeader:
# with a warning emitted
candidate = ScriptWriter.get_script_header('#!/usr/bin/python -x',
executable=exe)
- assert candidate == '#!%s -x\n' % exe
+ assert candidate == '#!%s -x\n' % exe
output = locals()[expect_out]
assert 'Unable to adapt shebang line' in output.getvalue()