aboutsummaryrefslogtreecommitdiffstats
path: root/setuptools/command/easy_install.py
diff options
context:
space:
mode:
authorJason R. Coombs <jaraco@jaraco.com>2013-08-06 00:25:19 +0200
committerJason R. Coombs <jaraco@jaraco.com>2013-08-06 00:25:19 +0200
commit6c256c7653a517912e603187111cfafc7c82d7dc (patch)
tree8efd176805bd874134986eb4bf9cb18fad466f16 /setuptools/command/easy_install.py
parent8d09363e908c030761026e9400283db10213b625 (diff)
downloadexternal_python_setuptools-6c256c7653a517912e603187111cfafc7c82d7dc.tar.gz
external_python_setuptools-6c256c7653a517912e603187111cfafc7c82d7dc.tar.bz2
external_python_setuptools-6c256c7653a517912e603187111cfafc7c82d7dc.zip
Extract _adjust_header method
--HG-- extra : rebase_source : 63809401ac0769504a143981e518ef31488ea400
Diffstat (limited to 'setuptools/command/easy_install.py')
-rwxr-xr-xsetuptools/command/easy_install.py24
1 files changed, 18 insertions, 6 deletions
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