aboutsummaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
authorJason R. Coombs <jaraco@jaraco.com>2013-08-05 23:40:20 +0200
committerJason R. Coombs <jaraco@jaraco.com>2013-08-05 23:40:20 +0200
commit1c7102c9ffa7735769b90ab5c7d02357c6dfa41d (patch)
treebcb1df5567e1d59a246e696bc53706be7963a3e6
parent29e0ce1ef9eaa7854167f281c98c4fe9eb3891ff (diff)
downloadexternal_python_setuptools-1c7102c9ffa7735769b90ab5c7d02357c6dfa41d.tar.gz
external_python_setuptools-1c7102c9ffa7735769b90ab5c7d02357c6dfa41d.tar.bz2
external_python_setuptools-1c7102c9ffa7735769b90ab5c7d02357c6dfa41d.zip
Move specialized Windows behavior to a specialized subclass
--HG-- extra : rebase_source : f56a411c3cace611952133b96a48ed92888f75a1
-rwxr-xr-xsetuptools/command/easy_install.py84
1 files changed, 48 insertions, 36 deletions
diff --git a/setuptools/command/easy_install.py b/setuptools/command/easy_install.py
index cbcc7c85..fbf3245c 100755
--- a/setuptools/command/easy_install.py
+++ b/setuptools/command/easy_install.py
@@ -1799,51 +1799,63 @@ class ScriptWriter(object):
"""
Yield write_script() argument tuples for a distribution's entrypoints
"""
+ gen_class = cls.get_writer(wininst)
spec = str(dist.as_requirement())
header = get_script_header("", executable, wininst)
for type_ in 'console', 'gui':
group = type_ + '_scripts'
for name, ep in dist.get_entry_map(group).items():
- script_text = cls.template % locals()
- for res in cls._get_script_args(type_, name, header,
- script_text, wininst):
+ script_text = gen_class.template % locals()
+ for res in gen_class._get_script_args(type_, name, header,
+ script_text):
yield res
@classmethod
- def _get_script_args(cls, type_, name, dist, executable, wininst):
- if sys.platform=='win32' or wininst:
- # On Windows/wininst, add a .py extension and an .exe launcher
- if type_=='gui':
- 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
- yield (name+ext, hdr+script_text, 't', [name+x for x in old])
- yield (
- name+'.exe', get_win_launcher(launcher_type),
- 'b' # write in binary mode
- )
- if not is_64bit():
- # install a manifest for the launcher to prevent Windows
- # from detecting it as an installer (which it will for
- # launchers like easy_install.exe). Consider only
- # adding a manifest for launchers detected as installers.
- # See Distribute #143 for details.
- m_name = name + '.exe.manifest'
- yield (m_name, load_launcher_manifest(name), 't')
+ def get_writer(cls, force_windows):
+ if force_windows or sys.platform=='win32':
+ return WindowsScriptWriter
+ return cls
+
+ @classmethod
+ def _get_script_args(cls, type_, name, header, script_text):
+ # Simply write the stub with no extension.
+ yield (name, header+script_text)
+
+
+class WindowsScriptWriter(ScriptWriter):
+ @classmethod
+ def _get_script_args(cls, type_, name, header, script_text):
+ """
+ For Windows, add a .py extension and an .exe launcher
+ """
+ if type_=='gui':
+ launcher_type = 'gui'
+ ext = '-script.pyw'
+ old = ['.pyw']
+ new_header = re.sub('(?i)python.exe','pythonw.exe',header)
else:
- # On other platforms, we assume the right thing to do is to
- # just write the stub with no extension.
- yield (name, header+script_text)
+ 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
+ yield (name+ext, hdr+script_text, 't', [name+x for x in old])
+ yield (
+ name+'.exe', get_win_launcher(launcher_type),
+ 'b' # write in binary mode
+ )
+ if not is_64bit():
+ # install a manifest for the launcher to prevent Windows
+ # from detecting it as an installer (which it will for
+ # launchers like easy_install.exe). Consider only
+ # adding a manifest for launchers detected as installers.
+ # See Distribute #143 for details.
+ m_name = name + '.exe.manifest'
+ yield (m_name, load_launcher_manifest(name), 't')
+
# for backward-compatibility
get_script_args = ScriptWriter.get_script_args