[CentralOH] Monkey Patch IDLE on the Mac
mark at microenh.com
Sun Aug 21 20:33:59 CEST 2011
As some of you know, I like IDLE and I like the Mac, but I've found the IDLE on the Mac to be lacking. Note: that this is on OSX 10.6 (Snow Leopard). Things may be improved with OSX 10.7 (Lion), but I've not yet upgraded.
There are well documented problems with the default IDLE that comes with Snow Leopard (see http://www.python.org/download/mac/tcltk/). This page advises that to use IDLE with Python 2.7.2 (from the default MacPython 2.7.2 installer) in 64-bit mode you need to install ActiveTcl 8.5. With this configuration, IDLE is working almost as well as IDLE on Windows, but there is still one big problem for me.
Due to the way the Mac opens programs, using AppleEvents rather than through sys.argv, sys.path is always set to ~/Documents rather than the directory containing the initial file opened. This makes it cumbersome to use IDLE as a manual debugging/exploratory tool with projects with local packages.
I was poking around in the source code to the IDLE that comes with Python 2.7.2 and found that the place to fix this is in one of the "standard" library files, which I'm loathe to do. Then I realized that I could affect a change via monkey patching using just the idlemain.py file that is part of the IDLE launcher. In fact, my monkey patch goes just below another monkey patch of the same file that was already in idlemain.py.
I now have a version of IDLE that sets sys.path properly (at least for me). Let me know if anyone wants to see what I've done.
The next thing I'm going to try is to see if I can monkey patch idlemain.py to respect the virtualenv.
-------------- next part --------------
An HTML attachment was scrubbed...
More information about the CentralOH