aboutsummaryrefslogtreecommitdiffstats
path: root/setuptools/command/easy_install.py
diff options
context:
space:
mode:
authorJason R. Coombs <jaraco@jaraco.com>2015-11-27 21:35:51 -0500
committerJason R. Coombs <jaraco@jaraco.com>2015-11-27 21:35:51 -0500
commita361ef49cda256e1f53894470cb921d19e04e853 (patch)
tree11ac79a98bbce5f4440afaa9b23ee7e0e6d1b22c /setuptools/command/easy_install.py
parentfb2860e63f463355aa3c9e824adff48dfeaad837 (diff)
downloadexternal_python_setuptools-a361ef49cda256e1f53894470cb921d19e04e853.tar.gz
external_python_setuptools-a361ef49cda256e1f53894470cb921d19e04e853.tar.bz2
external_python_setuptools-a361ef49cda256e1f53894470cb921d19e04e853.zip
Extract _use_header method
Diffstat (limited to 'setuptools/command/easy_install.py')
-rwxr-xr-xsetuptools/command/easy_install.py26
1 files changed, 16 insertions, 10 deletions
diff --git a/setuptools/command/easy_install.py b/setuptools/command/easy_install.py
index f3b5fa62..9e9c5e54 100755
--- a/setuptools/command/easy_install.py
+++ b/setuptools/command/easy_install.py
@@ -20,6 +20,7 @@ from distutils.errors import DistutilsArgError, DistutilsOptionError, \
from distutils.command.install import INSTALL_SCHEMES, SCHEME_KEYS
from distutils import log, dir_util
from distutils.command.build_scripts import first_line_re
+from distutils.spawn import find_executable
import sys
import os
import zipimport
@@ -2126,8 +2127,8 @@ class WindowsScriptWriter(ScriptWriter):
blockers = [name + x for x in old]
yield name + ext, header + script_text, 't', blockers
- @staticmethod
- def _adjust_header(type_, orig_header):
+ @classmethod
+ def _adjust_header(cls, type_, orig_header):
"""
Make sure 'pythonw' is used for gui and and 'python' is used for
console (regardless of what sys.executable is).
@@ -2138,14 +2139,19 @@ class WindowsScriptWriter(ScriptWriter):
pattern, repl = repl, pattern
pattern_ob = re.compile(re.escape(pattern), re.IGNORECASE)
new_header = pattern_ob.sub(string=orig_header, repl=repl)
- if sys.platform == 'win32':
- from distutils.spawn import find_executable
-
- clean_header = new_header[2:-1].strip('"')
- if not find_executable(clean_header):
- # the adjusted version doesn't exist, so return the original
- return orig_header
- return new_header
+ return new_header if cls._use_header(new_header) else orig_header
+
+ @staticmethod
+ def _use_header(new_header):
+ """
+ Should _adjust_header use the replaced header?
+
+ On non-windows systems, always use. On
+ Windows systems, only use the replaced header if it resolves
+ to an executable on the system.
+ """
+ clean_header = new_header[2:-1].strip('"')
+ return sys.platform != 'win32' or find_executable(clean_header)
class WindowsExecutableLauncherWriter(WindowsScriptWriter):