Saturday, January 8, 2011

Finding Python (for PyObjC) 2

One last post about PyObjC issues and finding which Python is running (under OS X) and then I'm done with it. Until I have another problem.. The structure of a framework is like this:


MyFramework.framework/
MyFramework -> Versions/Current/MyFramework
Resources -> Versions/Current/Resources
Versions/
A/
MyFramework
Headers/
MyHeader.h
Resources/
English.lproj/
InfoPlist.strings
Info.plist
Current -> A

From the docs, a framework normally has a structure like that shown above, where (if A is the current version) the actual library would be:

MyFramework.framework/Versions/A/MyFramework

The reason for the post is that I realized I've been overlooking something obvious: the existence of an Info.plist file. Just as we set the key: NSPrincipalClass, to have the value: SimpleMessage in our bundle (here), there is a key in the Python.framework:

cat Resources/Info.plist
..
<key>CFBundleExecutable</key>
<string>Python</string>

This key is not required to be set for a framework (a framework doesn't have to contain any code), but if it is, you'd expect it to be the path to the executable. Although there is something in the Framework docs about this key must be the same as the name of the framework. So the executable should be:

/System/Library/Frameworks/Python.framework/Versions/2.5/Python

As far as I can see, our best approach is still to snoop on the loader. And to solve the original problem (no PyObjC) by making sure that we're running System Python.