[Pythonmac-SIG] PyMacApp - Flexible Executable Stub For Python

Bob Ippolito bob at redivi.com
Thu Mar 4 04:12:58 EST 2004


As part of BundleBuilder2, I'm developing an executable stub for Python 
that *does not* link to anything but Cocoa, and does not use the execve 
hack.  The same compiled executable will be usable as a stub for any 
(dynamically linkable) Python on (probably) any version of OS X.  No 
recompilation or mach-o header rewriting required.  It should be a lot 
nicer to GDB, and measurably quicker to start than the current execve 
idiom, and doesn't require compilation like the xcode template options.

Here's what it does:

- checks the Info.plist for a REQUIRED key called "PyRuntimeLocations". 
  This is an array of potential locations for a Python runtime, in 
order.  Here are some examples:

	@executable_path/../Frameworks/Python.framework/Versions/2.3/Python   
# this would be --standalone
	~/Library/Frameworks/Python.framework/Versions/2.3/Python # this would 
be user-local
	/Library/Frameworks/Python.framework/Versions/2.3/Python # this would 
be system-wide
	/System/Library/Frameworks/Python.framework/Versions/2.3/Python # this 
would be vendor python
	/sw/lib/libpython2.3.dylib # this would be a non-framework Fink 
python.  Completely untested, but might work.

   It will show a friendly alert panel if it can't find the key, or if 
it can't locate a runtime

- sets PYTHONPATH to: 
@executable_path/../Resources:@executable_path/../Resources/PyObjC

- checks the Info.plist for an OPTIONAL key called "PyMainFileNames".  
This is an array of potential file names for a main python script.  
Here are some examples:
	
	__main__.py
	__main__.pyo
	__main__.pyc

   Note that it will always scan for __main__.py, __realmain__.py, and 
Main.py if your PyMainFileNames are not located.  This is similar to 
the behavior of the PyObjC template main.m.  This will show a friendly 
alert panel if it can't find a main script.

- links in the python runtime and binds all the Python functions it 
calls, shows a friendly alert panel on any link error.

- sets the Python program name to something reasonable.  For a 
framework, it will use %(runtime)s/../bin/%(executable)s where 
executable is the optional key "PyExecutableName" or "python".  For a 
dylib, it will do %(runtime)s/../../bin/%(executable)s .. but again, 
this is untested.

- runs the main script, shows a friendly alert panel if any exception 
is uncaught (anything but SystemExit, of course).

***
There is ONE bug that I know of.  Since it does all this snazzy stuff 
dynamically, it has NO WAY of knowing if you compiled a Python with 
Py_TRACE_REFS / Py_DEBUG.  And therefore its Py_XDECREF macro is going 
to be totally wrong (it expects the ref count to be at the head of a 
PyObject*).  I don't think there's anything I can do about this.
***

Here's the code:
	http://undefined.org/python/PyMacApp-0.1.tgz (configured to use 10.2.7 
SDK for ensured backwards compatibility)

And here's a sample of a friendly alert panel:
	http://undefined.org/python/PyMacApp-Error.png

-bob




More information about the Pythonmac-SIG mailing list