]> granicus.if.org Git - python/commitdiff
Update way a subprocess is launched for Mac OS X.
authorTony Lownds <tony@lownds.com>
Fri, 20 Dec 2002 04:24:43 +0000 (04:24 +0000)
committerTony Lownds <tony@lownds.com>
Fri, 20 Dec 2002 04:24:43 +0000 (04:24 +0000)
Another applet mechanism has been developed for Python on Mac OS X and
trying to use the -c "__import__('run').main()" trick is just not working.

macosx_main.py is a new file which should be used as the startup file for
Mac OS X applet bundles. This startup file understands a -p option, which
when seen will start run.main(). When running as an applet, this seems like
the best approach.

Lib/idlelib/PyShell.py
Lib/idlelib/boolcheck.py [new file with mode: 0644]
Lib/idlelib/idle
Lib/idlelib/macosx_main.py [new file with mode: 0644]
Lib/idlelib/run.py

index 5af9ca04ce760a5830e68525b3ea171c61816066..e13bafcc80f4797f6cc52da9d3d22808a1f20aca 100644 (file)
@@ -298,24 +298,27 @@ class ModifiedInterpreter(InteractiveInterpreter):
     rpcpid = None
 
     def spawn_subprocess(self):         
-        w = ['-W' + s for s in sys.warnoptions]        
-        args = [self.find_executable()] + w \
-             + ["-c", "__import__('run').main()", str(self.port)]
+        args = self.build_subprocess_arglist()
         self.rpcpid = os.spawnv(os.P_NOWAIT, args[0], args)
 
-    def find_executable(self):
-        if sys.platform == 'darwin' and sys.executable.count('.app'):
-            # On Mac OS X, avoid calling sys.executable because it ignores
-            # command-line options (sys.executable is an applet)
+    def build_subprocess_arglist(self):
+        if sys.platform == 'darwin' and sys.argv[0].count('.app'):
+            # We need to avoid using sys.executable because it fails on some
+            # of the applet architectures On Mac OS X.
             #
-            # Instead, find the executable by looking relative to
-            # sys.prefix.
-            executable = os.path.join(sys.prefix, 'Resources', 
-                                      'Python.app', 'Contents',
-                                      'MacOS', 'python')
-            return executable
+            # here are the applet architectures tried:
+            #
+            # framework applet: sys.executable + -p is correct
+            # python 2.2 + pure python main applet: 
+            #                   sys.executable + -p is correct
+            # pythonw idle.py:  sys.executable + -c is correct
+            #
+            # XXX what about warnoptions?
+            return [sys.executable, '-p', str(self.port)]
         else:
-            return sys.executable 
+            w = ['-W' + s for s in sys.warnoptions]        
+            return [sys.executable] + w \
+                 + ["-c", "__import__('run').main()", str(self.port)]
 
     def start_subprocess(self):
         addr = ("localhost", self.port)
@@ -1174,6 +1177,7 @@ def main():
     fixwordbreaks(root)
     root.withdraw()
     flist = PyShellFileList(root)
+
     if enable_edit:
         if not (cmd or script):
             for filename in args:
diff --git a/Lib/idlelib/boolcheck.py b/Lib/idlelib/boolcheck.py
new file mode 100644 (file)
index 0000000..bc988d7
--- /dev/null
@@ -0,0 +1,10 @@
+"boolcheck - import this module to ensure True, False, bool() builtins exist."
+try: 
+    True
+except NameError:
+    import __builtin__
+    __builtin__.True = 1
+    __builtin__.False = 0
+    from operator import truth
+    __builtin__.bool = truth
+
index 8638a165b4b64808cf9da3ef8e5d175f95be3943..d5aab04bc4c6a39ce953e1f879b1007732a9eb3c 100755 (executable)
@@ -1,4 +1,33 @@
 #! /usr/bin/env python
 
-import PyShell
-PyShell.main()
+# Add IDLE.app/Contents/Resources/idlelib to path.
+# __file__ refers to this file when it is used as a module, sys.argv[0]
+# refers to this file when it is used as a script (pythonw macosx_main.py)
+import sys
+from os.path import split, join
+try:
+    __file__
+except NameError:
+    __file__ = sys.argv[0]
+idlelib = join(split(__file__)[0], 'idlelib')
+if os.path.isdir(idlelib):
+    sys.path.append(idlelib)
+
+# Make sure True, False, bool() builtins exist.
+# - preserves 2.2 compatibility - 2.2.1 includes bool, 2.2 does not.
+# - important for Mac OS X because it ships python 2.2
+import boolcheck
+
+# see if we are being asked to execute the subprocess code
+if '-p' in sys.argv:
+    # run expects only the port number in sys.argv
+    sys.argv.remove('-p')
+
+    # this module will become the namepsace used by the interactive
+    # interpreter; remove all variables we have defined.
+    del sys, __file__, boolcheck, split, join
+    __import__('run').main()
+else:
+    # start the application.
+    import PyShell
+    PyShell.main()
diff --git a/Lib/idlelib/macosx_main.py b/Lib/idlelib/macosx_main.py
new file mode 100644 (file)
index 0000000..88e4197
--- /dev/null
@@ -0,0 +1,46 @@
+"""IDLE.app
+
+Installation:
+  see the install_IDLE target in python/dist/src/Mac/OSX/Makefile
+  
+Usage: 
+
+1. Double clicking IDLE icon will open IDLE.
+2. Dropping file on IDLE icon will open that file in IDLE.
+3. Launch from command line with files with this command-line:
+
+     /Applications/Python/IDLE.app/Contents/MacOS/python file1 file2 file3
+
+"""
+
+# Add IDLE.app/Contents/Resources/idlelib to path.
+# __file__ refers to this file when it is used as a module, sys.argv[0]
+# refers to this file when it is used as a script (pythonw macosx_main.py)
+import sys
+
+from os.path import split, join, isdir
+try:
+    __file__
+except NameError:
+    __file__ = sys.argv[0]
+idlelib = join(split(__file__)[0], 'idlelib')
+if isdir(idlelib):
+  sys.path.append(idlelib)
+
+# Make sure True, False, bool() builtins exist.
+# - preserves 2.2 compatibility - 2.2.1 includes bool, 2.2 does not.
+# - important for Mac OS X because it ships python 2.2
+import boolcheck
+
+# see if we are being asked to execute the subprocess code
+if '-p' in sys.argv:
+    # run expects only the port number in sys.argv
+    sys.argv.remove('-p')
+
+    # this module will become the namepsace used by the interactive
+    # interpreter; remove all variables we have defined.
+    del sys, __file__, boolcheck, split, join
+    __import__('run').main()
+else:
+    # Load idlelib/idle.py which starts the application.
+    import idle 
index 5b9864c8c57bd67e762d726c4e077bb9f50065ef..f394bacd73e9d78ef875a10df11ba04ca0d238bb 100644 (file)
@@ -2,6 +2,8 @@ import sys
 import time
 import socket
 
+import boolcheck
+
 import CallTips
 import RemoteDebugger
 import RemoteObjectBrowser