Serving mercurial with mod_wsgi

Here’s a quick and easy recipe for serving a mercurial repository with mod_wsgi.

  1. Create a file called hgwebdir.wsgi with these contents:

    from mercurial.hgweb.request import wsgiapplication
    from mercurial.hgweb.hgwebdir_mod import hgwebdir
    
    def make_web_app():
        return hgwebdir("/path/to/hgweb.config")
    
    application = wsgiapplication(make_web_app)
    
  2. Add it to the apache configuration:

    WSGIScriptAlias /hg /path/to/hgwebdir.wsgi

  3. [optional] To make sure nobody modifies your repository via the http interface, add ‘deny_push = *’ to the ‘[web]‘ group of hgweb.config.

Hopefully this page will save the next person a few minutes of searching.

This entry was posted in Mercurial, WSGI. Bookmark the permalink.

4 Responses to Serving mercurial with mod_wsgi

  1. NiCoS says:

    Hi,

    is it compatible with pushing over http (as with CGI) ?

  2. Jeffrey says:

    When I use this wsgi script the syntax highlighting using your extension doesn’t work (it’s in hgweb.config though). Using “hg serve” it does though. I tried everything like providing the absolute path to the hightlight.py file. What other things can I check?

  3. adam says:

    To answer these questions:

    1) I’m not sure if it’s compatible with pushing over HTTP but my guess would that it is. I always use ssh if I’m going to push though.

    2) This is probably a PYTHONPATH issue. Do you have multiple hg installs? You can make sure this uses the right one by putting:

    import sys sys.path.insert(0, “/path/to/correct/hg/install”)

    at the top of the .wsgi script.

  4. Jeffrey says:

    I only have one install, nonetheless I tried to set the path in the script, but without luck. When I put the extension in hgweb.config of hgwebdir it doesn’t work, however when I put the entry in every repositories’ hgrc, everything works fine.

    I haven’t tried other extensions in the general hgwebdir config, so maybe it’s a mercurial thing.

Leave a Reply