diff options
| author | Jason R. Coombs <jaraco@jaraco.com> | 2015-01-04 17:49:21 -0500 |
|---|---|---|
| committer | Jason R. Coombs <jaraco@jaraco.com> | 2015-01-04 17:49:21 -0500 |
| commit | efba85513b5c11ddbddf785906b5b4e9b596771a (patch) | |
| tree | d3a8a1c5c4cd0f5a0a265fa5814d01f6521ea11d /setuptools/command/easy_install.py | |
| parent | 3c78eb2348dff5d493d0cd5a34aef812db8385ef (diff) | |
| download | python-setuptools-git-efba85513b5c11ddbddf785906b5b4e9b596771a.tar.gz | |
Extract method for handling non-ascii exe. Strip out excess whitespace from option handling.
Diffstat (limited to 'setuptools/command/easy_install.py')
| -rwxr-xr-x | setuptools/command/easy_install.py | 37 |
1 files changed, 20 insertions, 17 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): |
