I've been running Trac for years now but usually on my Linux box. Since I don't have a web host that has a good way for the full Trac stack (Trac+Subversion), I needed access to a Trac instance from my laptop at all times. That being said, I decided to install Trac on my MacBook running OS X Leopard. After resolving a few issues:
- Trac doesn't work with Subversion 1.5: To work around this, instead of pointing easy_install to a Trac branch/tag/trunk, I just exported the branch/tag/trunk and pointed easy_install to that local directory.
- mod_python on Leopard has to be built with x86_64 support: To work around this, I followed: http://matterkkila.com/2007/12/20/building-mod_python-for-leopard/
I had Trac installed but when I tried to create a new Trac project, I kept getting the following error: SubversionException: ("Expected FS format '2'; found format '3'", 160043). I had PYTHONPATH set properly but for some reason, my Subversion 1.5 bindings weren't being used. As usual, I go to Google. I find many suggestions that "work" but they all seemed to suggest overwriting the Leopard-supplied Subversion Python bindings. (I'm not cool with that honestly, and those of you that have used my Subversion OS X binary know this.) Not liking that option, I looked into the Trac sources and found a nice little place to inject some code that would make Trac honor the PYTHONPATH environment variable.
If you open up your TRAC_INSTALLAION/trac/versioncontrol/svn_fs.py file, you see that Trac loads the Subversion Python bindings in _import_svn. This is the file we want to hack to make Trac do our bidding. Here is the code I used to make this happen:
# Hack to get Trac to honor PYTHONPATH import os, sys if os.environ.has_key('PYTHONPATH'): sys.path = os.environ['PYTHONPATH'].split(os.pathsep) + sys.path # End hack
With this code in svn_fs.py (I put it directly after the other imports), Trac will now use my Subversion 1.5 Python bindings without having to remove or replace the Apple-supplied Subversion 1.4 Python bindings.
I hope this helps someone else that runs into this issue. While there is more than one way to do this, the approach above is unobtrusive, since we do not have to alter or remove the Subversion packaged with Leopard, and it allows you to each set a standard Python environment variable to achieve this. Seems like a win-win to me.

