« Web 2.0 Palette | Main | Altering an Archetypes validator after the schema has been defined »

Getting organised with Turbogears

As with all software that changes rapidly, you need some sort of plan for how to manage change to it. Here’s how we manage Turbogears sites in such a way that we can easily deploy sites and manage changes to the codebase not only of our site, but changes to TG.

Turbogears is currently in alpha - 0.9 alpha to be precise. Not only that, many of it’s dependencies are changing rapidly to keep pace with it, so many of the dependencies of the 0.9a release are themselves in beta or are cuts from the trunk.

Additionally there is a really silly restriction in the way Python handles .pth files, described by Bob Ippolito (and Glyph Lefkowitz) — see the comments at the end. It is unfortunate Bob couldn’t persuade Guido to improve site.py since eggs are becoming such a key part of python software distribution. Does anyone know if this situation has changed? For us just a tweak in Debian would help a lot :)

Anyhow, to get eggs to install you need to add a .pth file for easy_install, which would normally mean writing to your normal site-packages location (e.g. /usr/lib/python2.4/site-packages). Modifying this is obviously a really dumb idea, so we need some other way of installing turbogears, ideally in such a way that we get a completely independent install for each site.

Of the options the only one that works is the Virtual Python Installation, which uses a really hacky script, virtual-python.py, to create a linkfarm from /usr to a custom location that contains everything python needs to run - and gives you your own site-packages directory to boot. To use the new python rather than the old one, you just have to change your PATH.

I’ve written a shell script to set everything up, and we use this successfully for a couple of sites now. This is all designed to run directly from an svn checkout, which makes it easy for development, and easy for managing changes from dev -> integration -> live.

First (optionally), create a directory called tginstall and download everything from the egg source into it (wget is your friend). We keep copies of all of the eggs to ensure this will always work - you don’t want your website exploding because turbogears.org went away (or indeed because they upgraded the eggs underneath you).

Then get virtual-python.py and ez_setup.py and put them in there too. Finally you need a script called create.sh:

And one called env.sh:

To use these you just:

When you later want to use this environment, just cd to that directory and do eval ./env.sh.

Post a comment

(If you haven't left a comment here before, you may need to be approved by the site owner before your comment will appear. Until then, it won't appear on the entry. Thanks for waiting.)