Since I’m mostly working on various Django projects I am working with virtualenv/virtualenvwrapper a lot. It allows to encapsulate environments and keep them identical across all servers your app will run on.
All this means setting up pretty much the same Python environment over and over again:
- create an environment
- enter environment
- install pip
- install IPython
- install Django
- install psycopg2
- install PIL
- install south
- install sorl-thumbnail
- install django-compress
- install all project specific packages and django apps
Quite tedious after your nth project really.
After reading how virtualenv allows bootstrapping environments and as such reducing tedious work I wondered if that can be done with virtualenvwrapper, too. Turns its absolutely possible.
There actually are quite a few hooks in virtualenvwrapper that allow for stuff being run pre- and post- creating/deleting/activating environments. Now my postmkvirtualenv script looks like this:
#!/bin/bash easy_install pip pip install ipython pip install yolk pip install psycopg2 pip install django pip install -e hg+http://bitbucket.org/andrewgodwin/south/@stableish#egg=south pip install pil pip install -e svn+http://sorl-thumbnail.googlecode.com/svn/trunk/#egg=solr pip install -e svn+http://django-compress.googlecode.com/svn/trunk/#egg=compress
Now whenever I create an environment with mkvirtualenv someproject all my standard Python packages and Django apps get installed automagically. And then I’m able to put something like this in my postactiveate script:
#!/bin/bash cd /Users/me/Projects/someproject/
So whenever I activate my environment with workon someproject I get beamed right into my project dir and can start hacking right away. Nice and easy.