Using nose with Python 2.2

·—— ···· ·· — ····· ···—— ——···
If your public Python project isn't backwards-compatible to Python 1.5, it should at least be compatible back to Python 2.2. I pick that milestone because of a legend that it's what Google uses.

I've got a few public Python projects, and I've grown to like nose for testing them. However, nose is decidedly not backwards-compatible to Python 2.2. Here's a recipe to make it so:
  1. You won't be able to install nose using setup.py, so just export the package onto your PYTHONPATH.
  2. Find all the files that use yield, and add from __future__ import generators at the top.
  3. Fill out your local library with logging, optparse, sets and textwrap from the standard library.
  4. Then get pkg_resources. You'll need to add the generators import, then hack out the zipimport dependency (it's a C extension; if you need zip importing then you'll have to compile it), and lastly add a couple of import hooks. Here's my version.
  5. Lastly, create an executable script on your PATH named nosetests, with these contents:
#!/usr/bin/env python
import nose.core
nose.core.main()
Now you can run nosetests on your Python 2.2 projects. Mine fail pretty quick, so there may yet be 2.2-compatibility bugs hidden in nose. If/when I find them, I'll backlink here.

Update: I've filed a bug+patch regarding #2 above.
Update: Patch committed; watch for it in nose 0.9.2. Thanks Jason!
·—— ···· ·· — ····· ···—— ——···
Feed back to Chad Whitacre.