Table Of Contents

Previous topic

smt command reference

Next topic

API reference

This Page

Developers’ guide

These instructions are for developing on a Unix-like platform, e.g. Linux or Mac OS X, with the bash shell.

Requirements

  • Python 2.6, 2.7 or 3.4
  • Django >= 1.6
  • django-tagging >= 0.3
  • parameters >= 0.2.1
  • nose >= 0.11.4
  • future >= 0.14
  • if using Python < 3.4, pathlib >= 1.0.0
  • if using Python 2.6, ordereddict, unittest2 >= 0.5.1
  • docutils
  • Jinja2

Optional:

  • mpi4py >= 1.2.2
  • coverage >= 3.3.1 (for measuring test coverage)
  • httplib2 (for the remote record store)
  • GitPython (for Git support)
  • hgapi (for Mercurial support)
  • bzr (for Bazaar support)
  • PyYAML (for YAML support)
  • psycopg2 (for PostgreSQL support)
  • dexml and fs (for WebDAV support)

We strongly recommend developing within a virtualenv.

Getting the source code

We use the Git version control system. To get a copy of the code you should fork the main Sumatra repository on Github, then clone your own fork.:

$ cd /some/directory
$ git clone https://github.com/<username>/sumatra.git

Now you need to make sure that the sumatra package is on your PYTHONPATH and that the smt and smtweb scripts are on your PATH. You can do this either by installing Sumatra:

$ cd sumatra
$ python setup.py install

(if you do this, you will have to re-run setup.py install any time you make changes to the code) or by installing using pip with the “editable” option:

$ pip install --editable sumatra

To ensure you always have access to the most recent version, add the main repository as “upstream”:

To update to the latest version from the repository:

$ git pull upstream master

Running the test suite

Before you make any changes, run the test suite to make sure all the tests pass on your system:

$ cd sumatra/test/unittests
$ nosetests

You will see some error messages, but don’t worry - these are just tests of Sumatra’s error handling. At the end, if you see “OK”, then all the tests passed, otherwise it will report how many tests failed or produced errors.

If any of the tests fail, check out the continuous integration server to see if these are “known” failures, otherwise please open a bug report.

(many thanks to the NEST Initiative for hosting the CI server).

Writing tests

You should try to write automated tests for any new code that you add. If you have found a bug and want to fix it, first write a test that isolates the bug (and that therefore fails with the existing codebase). Then apply your fix and check that the test now passes.

To see how well the tests cover the code base, run:

$ nosetests --coverage --cover-package=sumatra --cover-erase

Committing your changes

Once you are happy with your changes, you can commit them to your local copy of the repository:

$ git commit -m 'informative commit message'

and then push them to your Github repository:

$ git push

Before pushing, run the test suite again to check that you have not introduced any new bugs.

Once you are ready for your work to be merged into the main Sumatra repository, please open a pull request. You are encouraged to use a separate branch for each feature or bug-fix, as it makes merging changes easier.

Coding standards and style

All code should conform as much as possible to PEP 8, and should run with Python 2.6, 2.7 and 3.4. Lines should be no longer than 99 characters.

Reviewing pull requests

All contributors are encouraged to review pull requests, and all pull requests must have at least one review before merging.

Things to check for:

  • Does the pull request implement a single, well-defined piece of functionality? (pull requests which perform system-wide refactoring are sometimes necessary, but need much more careful scrutiny)
  • Does the code work? Is the logic correct? Does is anticipate possible failure conditions (e.g. lack of internet connection)?
  • Is the code easily understood?
  • Does the code conform to the coding standards (see above)?
  • Does the code implement a general solution, or is the code too specific to a particular (language|version control system|storage backend)?
  • Do all public functions/classes have docstrings?
  • Are there tests for all new/changed functionality?
  • Has the documentation been updated?
  • Has the Travis CI build passed?
  • Is the syntax compatible with both Python 2 and 3? (even if we don’t yet support Python 3, any new code should try to do so)
  • Is there any redundant or duplicate code?
  • Is the code as modular as possible?
  • Is there any commented out code, or print statements used for debugging?