diff options
author | Jason R. Coombs <jaraco@jaraco.com> | 2013-08-10 09:04:34 -0400 |
---|---|---|
committer | Jason R. Coombs <jaraco@jaraco.com> | 2013-08-10 09:04:34 -0400 |
commit | 3e6dd67c4ae9a6df3c25fb4a04d62f7297d47f3b (patch) | |
tree | d9aeaf9ecab14422af496556efe99277b2773e6d /setuptools/command/easy_install.py | |
parent | da1761c890a5d754caece50df870c30f9dfdd4f7 (diff) | |
download | external_python_setuptools-3e6dd67c4ae9a6df3c25fb4a04d62f7297d47f3b.tar.gz external_python_setuptools-3e6dd67c4ae9a6df3c25fb4a04d62f7297d47f3b.tar.bz2 external_python_setuptools-3e6dd67c4ae9a6df3c25fb4a04d62f7297d47f3b.zip |
Issue 60: Implemented experimental opt-in support for using native launchers rather than installing launcher executables. My initial experience with this technique has been very positive.
Diffstat (limited to 'setuptools/command/easy_install.py')
-rwxr-xr-x | setuptools/command/easy_install.py | 63 |
1 files changed, 44 insertions, 19 deletions
diff --git a/setuptools/command/easy_install.py b/setuptools/command/easy_install.py index 5be48bb1..6a45e596 100755 --- a/setuptools/command/easy_install.py +++ b/setuptools/command/easy_install.py @@ -1818,7 +1818,7 @@ class ScriptWriter(object): @classmethod def get_writer(cls, force_windows): if force_windows or sys.platform=='win32': - return WindowsScriptWriter + return WindowsScriptWriter.get_writer() return cls @classmethod @@ -1829,6 +1829,49 @@ class ScriptWriter(object): class WindowsScriptWriter(ScriptWriter): @classmethod + def get_writer(cls): + """ + Get a script writer suitable for Windows + """ + # for compatibility, return the writer that creates exe launchers + # unless the SETUPTOOLS_USE_PYLAUNCHER is set, indicating + # future behavior. + use_legacy = 'SETUPTOOLS_USE_PYLAUNCHER' not in os.environ + if use_legacy: + return WindowsLauncherScriptWriter + return cls + + @classmethod + def _get_script_args(cls, type_, name, header, script_text): + "For Windows, add a .py extension" + ext = dict(console='.py', gui='.pyw')[type_] + old = ['.py', '.pyc', '.pyo', '.pyw', '.exe'] + old.remove(ext) + header = cls._adjust_header(type_, header) + blockers = [name+x for x in old] + yield name+ext, header+script_text, 't', blockers + + @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 + pattern_ob = re.compile(re.escape(pattern), re.IGNORECASE) + new_header = pattern_ob.sub(string=orig_header, repl=repl) + 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 + + +class WindowsLauncherScriptWriter(WindowsScriptWriter): + @classmethod def _get_script_args(cls, type_, name, header, script_text): """ For Windows, add a .py extension and an .exe launcher @@ -1857,24 +1900,6 @@ 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 - pattern_ob = re.compile(re.escape(pattern), re.IGNORECASE) - new_header = pattern_ob.sub(string=orig_header, repl=repl) - 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 |