Edgewall Software

Version 4 (modified by osimons, 16 years ago) ( diff )

Added information about mod_python and virtualenv.

Developer setup for Trac

This tutorial assumes you have SVN installed. If you don't have SVN installed please go to the Subversion website and follow the directions of installation there.

Setting up the environment

Before we begin to develop in Trac, or even download Trac code, first create a standalone environment.

Create a working directory

No matter my operating system, I like to create a projects or working directory for my development efforts. So for example on some systems, I might have:

/Users/myname/projects

On Windows I would have:

c:\projects

Note: I don't create a directory called 'trac' yet. That comes later! In the meantime, cd (change directory) to your projects directory.

Get easy_install

Go to installing-easy-install and follow the instructions there. However, most of the time you just take the text at ez_setup.py, save it as ez_setup.py on your hard drive, then from the command-line prompt type:

python ez_setup.py

Get virtual env

From the command-line prompt type:

easy_install virtualenv

Set up a virtual environment

From the command-line prompt type:

virtualenv trac
cd trac
source bin/activate

You'll see your command-line prompt has changed. That means our environment is ready for Trac.

Installing and configuring Trac

Downloading trac

From the command-line prompt:

svn co http://svn.edgewall.org/repos/trac/trunk/ trac-trunk
svn co http://svn.edgewall.org/repos/genshi/trunk/ genshi-trunk
cd trac-trunk
python setup.py develop 
cd ../genshi-trunk
python setup.py develop
cd ..

Creating your test trac environment

From the command-line prompt:

trac-admin test initenv

note: Press return for every option.

Make anonymous users have full access

trac-admin test permission add anonymous TRAC_ADMIN

note: Don't do this in production!

Installing the trackdeveloperplugin

From the command-line prompt:

svn co http://trac-hacks.org/svn/tracdeveloperplugin/trunk/ tracdeveloperplugin
cd tracdeveloperplugin
python setup.py bdist_egg
cp dist/*.egg ../test/plugins
cd ..

Starting trac in development mode

From the command-line prompt:

tracd -r --port 8000 test

note: The -r command puts Trac into refresh mode so your code changes will show up quickly.

Web stuff

Switch to your browser and go to this URL:

http://127.0.0.1:8000/test

Now lets follow a few more steps

  • Go to web admin
  • Hit the admin link
  • Logging
    • Set type to console
    • level to debug

Alternative frontend: mod_python

Virtualenv can also be used with Apache and mod_python, but as mod_python will be a system install it will not be aware of the virutalenv without some configuration. For development this is useful as one Apache can serve various development versions in a more permanent way. This method will use the system Python, but will add the libraries from the virtualenv.

Step 1: Make a new frontend script that for instance can be stored in the virtualenv 'bin' directory.

#myvirtualtrac.py

import os
import site
site.addsitedir('/path/to/my/virtualenv/lib/python2.4/site-packages')

from trac.web.modpython_frontend import handler

Step 2: Update Apache config to use this script - add or update options according to the default mod_python setup like for instance found in TracModPython.

# Extend the path so Apache will find your script on path
PythonPath "['/path/to/my/virtualenv/bin'] + sys.path"

# Make mod_python use new frontend instead of trac.web.modpython_frontend
PythonHandler myvirtualtrac
Note: See TracWiki for help on using the wiki.