Most of us use some kind of SCM tool for our websites, Django powered site or not. A few months ago I switched from the old and trusted [Subversion] [svn] to Bazaar. The transition was easy and gradually I have moved all of my websites to Bazaar.
[svn]: http://subversion.tigris.org/
The primary reason for changing to Bazaar was its extensive support for branch and merge tracking. I now develop each new feature for my websites in a new and separate branch and thanks to Bazaar's merge history I never have to keep track of what has been merged where.
It has made my life so much easier!
I had to make a few changes to the way I organize my projects and today I can easily develop multiple branches at the same time without changing any code or settings. The last point was extremely important to me, I want to move between branches as painlessly as possible, without changing any code at all in the new branch.
I'll try to give a rough overview of my current setup using the code tree for RSSEpisodes.com and in the next few days I will show you the scripts that glue it together.
All my branches live in a top level repository called rssepisodes-repo. The version currently in production always lives in trunk and at the time of writing I have three branches of trunk:
$> ls
rssepisodes-calendar/ rssepisodes-links/ rssepisodes-regroup/
rssepisodes-trunk/
The three branches each focus on a particular feature and that feature is developed and tested in its own branch before it is merged into trunk.
The regroup branch focuses on making my templates simpler by implementing a few custom template tags. If we take a closer look at it we see how I structure my websites:
$> cd rssepisodes-regroup
$> ls
media/ python/ scripts/ templates/ environment.sh readme.txt
Remember, the regroup was branched of trunk, so all my branches are organized in the same manner. As we see, the top level directory of a branch consists of four directories and a shell script.
The four directories cover everything I need:
media -- This directory contains the media files for my application. Images, stylesheets, Javascripts and so on. On my production machine the web server has an alias pointing to this directory, locally I use
static_rootinurls.py.python -- This directory contains the Python code that operates on my site. Applications that are specific to this site has a package in this directory.
This directory is added to the Python load path via the
PYTHONPATHenvironent variable byenvironment.sh.scripts -- In here I place various scripts that I write to manage my web site and most importantly a customized
manage.py.This directory is added to my
PATHbyenvironment.sh.templates -- This is my templates directory. It does not belong in my Python path in my opionion (
django-admin startprojectplaces it in the root of your project, which is in your Python path. Blech.)
The python/ directory is where my Python code lives. In here I stuff Python modules (.py files) and the Python packages for my Django applications.
As mentioned, this directory is added to the Python load path. In addition to this directory I usually have ~/python/ where I keep Django itself and applications such as django-registration and django-tagging, and other shared Python libraries.
Now, let's take a look at that python/ directory:
$> ls python
rssepisodes/ shows/ tags/ tidy.py
It contains three Python packages and a module. The interesting package is rssepisodes -- this is the Django application that runs my website:
$> ls python/rssepisodes
__init__.py settings_dev.py settings_prod.py urls.py
As we see, this package only contains urls.py plus development and production settings. The remaining packages, shows and tags, are developed as stand-alone Django applications, even though they are highly specialized and not very reusable.
Tomorrow I will write about the scripts that makes this set up extremely easy to live with, namely environment.sh and manage.py, and hopefully I will write about branch-specific databases later this week.
Update: Read part 2 of this post.