Commit 1c7102c9 authored by Jason R. Coombs's avatar Jason R. Coombs

Move specialized Windows behavior to a specialized subclass

--HG--
extra : rebase_source : f56a411c3cace611952133b96a48ed92888f75a1
parent 29e0ce1e
...@@ -1799,20 +1799,35 @@ class ScriptWriter(object): ...@@ -1799,20 +1799,35 @@ class ScriptWriter(object):
""" """
Yield write_script() argument tuples for a distribution's entrypoints Yield write_script() argument tuples for a distribution's entrypoints
""" """
gen_class = cls.get_writer(wininst)
spec = str(dist.as_requirement()) spec = str(dist.as_requirement())
header = get_script_header("", executable, wininst) header = get_script_header("", executable, wininst)
for type_ in 'console', 'gui': for type_ in 'console', 'gui':
group = type_ + '_scripts' group = type_ + '_scripts'
for name, ep in dist.get_entry_map(group).items(): for name, ep in dist.get_entry_map(group).items():
script_text = cls.template % locals() script_text = gen_class.template % locals()
for res in cls._get_script_args(type_, name, header, for res in gen_class._get_script_args(type_, name, header,
script_text, wininst): script_text):
yield res yield res
@classmethod @classmethod
def _get_script_args(cls, type_, name, dist, executable, wininst): def get_writer(cls, force_windows):
if sys.platform=='win32' or wininst: if force_windows or sys.platform=='win32':
# On Windows/wininst, add a .py extension and an .exe launcher 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': if type_=='gui':
launcher_type = 'gui' launcher_type = 'gui'
ext = '-script.pyw' ext = '-script.pyw'
...@@ -1840,10 +1855,7 @@ class ScriptWriter(object): ...@@ -1840,10 +1855,7 @@ class ScriptWriter(object):
# See Distribute #143 for details. # See Distribute #143 for details.
m_name = name + '.exe.manifest' m_name = name + '.exe.manifest'
yield (m_name, load_launcher_manifest(name), 't') yield (m_name, load_launcher_manifest(name), 't')
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)
# for backward-compatibility # for backward-compatibility
get_script_args = ScriptWriter.get_script_args get_script_args = ScriptWriter.get_script_args
......
Markdown is supported
0%
or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment