From 6c256c7653a517912e603187111cfafc7c82d7dc Mon Sep 17 00:00:00 2001 From: "Jason R. Coombs" Date: Tue, 6 Aug 2013 00:25:19 +0200 Subject: Extract _adjust_header method --HG-- extra : rebase_source : 63809401ac0769504a143981e518ef31488ea400 --- setuptools/command/easy_install.py | 24 ++++++++++++++++++------ 1 file changed, 18 insertions(+), 6 deletions(-) (limited to 'setuptools/command') diff --git a/setuptools/command/easy_install.py b/setuptools/command/easy_install.py index 5066d666..b1838024 100755 --- a/setuptools/command/easy_install.py +++ b/setuptools/command/easy_install.py @@ -1832,16 +1832,11 @@ class WindowsScriptWriter(ScriptWriter): launcher_type = 'gui' ext = '-script.pyw' old = ['.pyw'] - new_header = re.sub('(?i)python.exe','pythonw.exe',header) else: launcher_type = 'cli' ext = '-script.py' old = ['.py','.pyc','.pyo'] - new_header = re.sub('(?i)pythonw.exe','python.exe',header) - if os.path.exists(new_header[2:-1].strip('"')) or sys.platform!='win32': - hdr = new_header - else: - hdr = header + hdr = cls._adjust_header(type_, header) blockers = [name+x for x in old] yield (name+ext, hdr+script_text, 't', blockers) yield ( @@ -1857,6 +1852,23 @@ class WindowsScriptWriter(ScriptWriter): m_name = name + '.exe.manifest' yield (m_name, load_launcher_manifest(name), 't') + @staticmethod + def _adjust_header(type_, orig_header): + """ + Make sure 'pythonw' is used for gui and and 'python' is used for + console (regardless of what sys.executable is). + """ + pattern = 'pythonw.exe' + repl = 'python.exe' + if type_ == 'gui': + pattern, repl = repl, pattern + new_header = re.sub(string=orig_header, pattern=re.escape(pattern), + repl=repl, flags=re.IGNORECASE) + clean_header = new_header[2:-1].strip('"') + if sys.platform == 'win32' and not os.path.exists(clean_header): + # the adjusted version doesn't exist, so return the original + return orig_header + return new_header # for backward-compatibility get_script_args = ScriptWriter.get_script_args -- cgit v1.2.1