jaraco Paste | About

Paste nh5gT aka 86835f06-aece-44aa-8d7a-d8fdc8acac33 (diff) by jaraco on Aug 06, 09:38
(Plain Text) (Wrap Lines)

 1
 2
 3
 4
 5
 6
 7
 8
 9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
diff --git a/setuptools/command/easy_install.py b/setuptools/command/easy_install.py
--- a/setuptools/command/easy_install.py
+++ b/setuptools/command/easy_install.py
@@ -1818,7 +1818,7 @@
     @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,48 @@
 
 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_SUPPRESS_EXE_LAUNCHERS is set, indicating
+        #  future behavior.
+        use_legacy = 'SETUPTOOLS_SUPPRESS_EXE_LAUNCHERS' 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']
+        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 +1899,6 @@
             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