Edgewall Software

Version 37 (modified by figaro, 9 years ago) ( diff )

Cosmetic changes

Developer setup for Trac

Where to go for more information

Review a couple of documents before attempting to install a development environment or even to install from the trunk. One such place is the milestones pages to see if there are any specific requirements for the version you are setting up.

Specifically, for Trac 0.12+, you need Genshi 0.6 or later. See milestone:0.12 for more information.

The (automated) tests will require additional packages that may or may not be installed with your OS/Python distribution.

Installing the development tools

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

Create a working directory

Create a projects or working directory for your development efforts. So for example on some systems, you might have:

/Users/myname/projects

On Windows you would have:

C:\projects

Note: Don't create a directory called 'trac' yet. That comes later.

Get Subversion

This tutorial assumes you have Subversion (SVN) installed. If not, go to the Subversion website and follow the directions of installation there.

Get Python

On Linux, it is in most cases best to install Python using the package manager for your distribution. For example, on a distribution utilizing the Apt package manager (Debian, Ubuntu):

sudo apt-get install python2.6

You will also need some additional libraries:

sudo apt-get install python-subversion

On Windows, some of the available options are:

Mac OS X 10.5 and later has Python ≥ 2.5 pre-installed.

Get easy_install

You will have easy_install if you have "setuptools" installed. Just make sure its version is ≥ 0.6c10. Previous versions do not work correctly with SVN 1.6.

Otherwise go to installing-easy-install and follow the instructions there. However, most of the time you just take the text at ez_setup.py. For Python 2.4 and 2.5 read Section Python 2.4 and Python 2.5 support, save it as ez_setup.py on your hard drive, then from the command-line prompt type:

python ez_setup.py

To test if the installation was successful:

easy_install --help

Get virtualenv

From the command-line prompt type:

python -m easy_install virtualenv

On Linux you may need to prepend python with sudo.

Set up a virtual environment

From the command-line prompt type:

virtualenv trac
cd trac
source bin/activate

or for Windows:

python -m virtualenv trac
cd trac
cmd /k Scripts\activate.bat

If you have Trac installed in /usr/lib or /usr/local/lib, run the above virtualenv command with --no-site-packages.

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

Upgrade Setuptools

Just to be sure you have a recent enough version of setuptools, and if not, you should upgrade them. For more options on upgrading packages with easy_install see upgrading a package:

easy_install --upgrade setuptools

Developing with Eclipse and PyDev

If you are planning to develop using Eclipse, you should also read the Development with Eclipse and PyDev page, after installing and configuring Trac in the next section.

Installing and configuring Trac

Downloading Trac

You should get the Trac source code from one of the TracRepositories. For example, for Subversion 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 genshi-trunk
python setup.py develop 
cd ../trac-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 TracDeveloperPlugin (optional)

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. See also the auto_reload trac.ini flag which should be used for the changes in Genshi templates to be picked-up as well.

To run tracd or work in the virtual environment, you must switch to the virtual environment each time a new shell is opened.

cd test
source bin/activate

Debugging Plugins

To debug a plugin, install it into your test environment using the command:

$ python setup.py develop -md /path/to/projenv/plugins

If you are experiencing troubles in debugging Trac code, make sure that PYTHONPATH in project properties doesn't contain pointers to other Trac sources. Otherwise those sources will be picked instead of the checked out sources.

Web stuff

Switch to your browser and go to http://127.0.0.1:8000/test

Now do the following:

  • Go to web admin
  • Click on Admin
  • Set logging:
    • Set type to console
    • Set level to debug

Alternative frontends

To develop on Trac with Apache rather than the standalone tracd, see the alternative frontends page for information on using Apache with mod_python and mod_wsgi.

Note: See TracWiki for help on using the wiki.