Skip to content
Mar 29 / Nizam Sayeed

Using svn:externals for external Django module dependencies

After working on building a fairly complex Django application for the last year or so, I have ended up using a few of the open source Django modules that are out there. Why re-invent the wheel after all?

Most of these projects are thankfully hosted on Google Code which uses Subversion as the source control system. A great feature of SVN is the support for externals definitions. It made my life easier as far as not having to bundle the code for these modules when deploying my app or to store a copy in my own code repository.

So enough with the talk, how do we do this? Easy. Here are the steps:

  • Create a sub-directory under at the root of your Django application called externals or whatever suits your needs.
  • Create a file called svn.externals in this directory.
  • Edit it and create mappings for the external modules and their local checkouts. Example:

    The first column is the local directory to checkout to and the second column is the checkout URL. The mappings may point to trunk, any tagged versions or branches.

  • From the externals sub-directory, issue the following command:
    svn propset svn:externals -F svn.externals .

    This modifies the svn:externals property for this directory and loads the mapping from the file we created.

  • Issue the following command:
    svn up

    To have svn go out and fetch the external modules.

  • I have modified my script to look like this:
    #!/usr/bin/env python
    from os.path import abspath, dirname, join
    from site import addsitedir
    import sys
    # add externals to PYTHONPATH
    sys.path.insert(0, abspath(join(dirname(__file__), 'externals')))
    from import execute_manager
        import settings
    except ImportError:
        import sys
        sys.stderr.write("Error: Can't find the file '' in the directory containing %r. It appears you've customized things.nYou'll have to run, passing it your settings module.n(If the file does indeed exist, it's causing an ImportError somehow.)n" % __file__)
    if __name__ == "__main__":

    Notice that I have added the externals directory to sys.path.

That’s pretty much it. Now, anytime you do an svn up, the specified version from the module maintainer’s code repo.

I would highly recommend checking externals directory as well as the svn.externals file into your local repo. If you add a new mapping later on, you can modify the file and re-issue the svn propset command to update the mappings within svn.

  • Jeremy Dunck

    We’re using git and git submodules to similar effect.

  • zbyte

    Very useful. I have been contemplating how to best manage dependencies on external reusable apps in my django projects. This looks like it will probably do the trick in most cases, or at least be a good tool for the toolbox. Thanks.