Edgewall Software

Alternative frontends for development

Alternative frontend: mod_python

Virtualenv can 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 server 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.

  1. Make a new frontend script that for instance can be stored in the virtualenv bin directory:
    import os
    import site
    from trac.web.modpython_frontend import handler
  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

With Apache, mod_wsgi is a very good alternative to mod_python. Setting this up follows the same pattern, but for development especially there is one major advantage: it can quite easily be set up to auto-reload on code changes.

  1. Update a default TracModWsgi setup to make a daemonised 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
        # 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
  2. Go to ReloadingSourceCode and save the Python script as /path/to/my/virtualenv/bin/monitor.py
  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
    # Additionally monitor easy-install.pth to restart whenever installs are done
    application = trac.web.main.dispatch_request
Last modified 7 years ago Last modified on Apr 2, 2016, 6:31:07 AM
Note: See TracWiki for help on using the wiki.