Alternative frontends
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 virtualenv 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
Alternative frontend: mod_wsgi
Using Apache, mod_wsgi is a very good alternative to mod_python. Setting this up follows the same pattern, but for development escpecially there is one major advantage: It can quite easily be set up to auto-reload on code changes.
Step 1: Update a default TracModWsgi setup to make a deamonised process, and as of mod_wsgi 2.0 (this setup depends on >= 2.0) there is built-in support for custom paths and similar. Example of a full VirtualHost configuration:
<VirtualHost *:80>
ServerName virtualtrac.local
# Update user and group to be whatever on your system is intended to run the deamon
# Update the paths to point to virtualenv site-packages (for trac+++) and bin (for script)
WSGIDaemonProcess virtualtrac user=www group=www threads=25 python-path=/path/to/my/virtualenv/lib/python2.4/site-packages:/path/to/my/virtualenv/bin
WSGIScriptAlias / /path/to/my/virtualenv/bin/virtualtrac.wsgi
<Location />
WSGIReloadMechanism Process
WSGIProcessGroup virtualtrac
# GLOBAL should generally be used instead of SERVER, see http://code.google.com/p/modwsgi/wiki/IntegrationWithTrac
WSGIApplicationGroup %{GLOBAL}
Order deny,allow
Allow from all
</Location>
# Authentication
<LocationMatch (/[^/.]+/login)>
# Note: Change settings with regards to auth method, paths and domain
AuthType Digest
AuthName "virtualtrac"
AuthDigestDomain /trac http://virtualtrac.local
AuthDigestProvider file
AuthUserFile /path/to/access.htdigest
Require valid-user
</LocationMatch>
</VirtualHost>
Step 2: Go to http://code.google.com/p/modwsgi/wiki/ReloadingSourceCode and save the long Python script that follows the text 'Example code for such an automatic restart mechanism...'. Save it as /path/to/my/virtualenv/bin/monitor.py
Step 3: A basic WSGI frontend script, save as /path/to/my/virtualenv/bin/virtualtrac.wsgi
import sys sys.stdout = sys.stderr import os os.environ['TRAC_ENV_DIR'] = "/path/to/trac/project" # or, alternatively for multiple projects #os.environ['TRAC_ENV_PARENT_DIR'] = "/parent/path/to/many/projects" os.environ['PYTHON_EGG_CACHE'] = '/path/to/a/temp/to/cache/eggs' import trac.web.main import monitor monitor.start(interval=1.0) # Additionally monitor easy-install.pth to restart whenever installs are done monitor.track('/path/to/my/virtualenv/lib/python2.4/site-packages/easy-install.pth') application = trac.web.main.dispatch_request


