SQLObject Developer Guide

Contents

These are some notes on developing SQLObject. I'll try to expand them as things come up.

-- Ian Bicking

Development Installation

First install FormEncode:

$ git clone git://github.com/formencode/formencode.git
$ cd formencode
$ sudo python setup.py develop

Then do the same for SQLObject:

$ git clone git clone git://git.code.sf.net/p/sqlobject/sqlobject
$ cd sqlobject
$ sudo python setup.py develop

Voila! The packages are globally installed, but the files from the checkout were not copied into site-packages. See setuptools for more.

Style Guide

Generally you should follow the recommendations in PEP 8, the Python Style Guide. Some things to take particular note of:

Testing

Tests are important. Tests keep everything from falling apart. All new additions should have tests.

Testing uses py.test, an alternative to unittest. It is available at http://pytest.org/ and http://pypi.python.org/pypi/pytest. Read its getting started document for more.

To actually run the test, you have to give it a database to connect to. You do so with the option -D. You can either give a complete URI or one of several shortcuts like mysql (these shortcuts are defined in the top of tests/dbtest.py).

All the tests are modules in sqlobject/tests. Each module tests one kind of feature, more or less. If you are testing a module, call the test module tests/test_modulename.py -- only modules that start with test_ will be picked up by py.test.

The "framework" for testing is in tests/dbtest. There's a couple of important functions:

setupClass(soClass) creates the tables for the class. It tries to avoid recreating tables if not necessary.

supports(featureName) checks if the database backend supports the named feature. What backends support what is defined at the top of dbtest.

If you import * you'll also get py.test's version of raises, an inserts function that can create instances for you, and a couple miscellaneous functions.

If you submit a patch or implement a feature without a test, I'll be forced to write the test. That's no fun for me, to just be writing tests. So please, write tests; everything at least needs to be exercised, even if the tests are absolutely complete.

We now use Travis CI to run tests. See the status:

https://travis-ci.org/sqlobject/sqlobject.svg?branch=2.1

Documentation

Please write documentation. Documentation should live in the docs/ directory. Pudge converts documentation from Restructured Text to HTML. It presently requires kid 0.9.3, which must be obtained separately (for instance, from http://pypi.python.org/pypi/kid/0.9.3)