23 Mar 2010 kwa   » (Journeyer)

Extension modules for unit tests with distutils

I’ve been hacking on greenlet lately, which has been in dire need of some tender loving care. The upcoming 0.3 release will include an API for extension modules that allows any extension module to create and manipulate greenlets directly in C without jumping through hoops.

I found myself wanting to add a test extension module to bring the C API under test, but it turns out that distutils doesn’t really support building extension modules that you don’t want to ship in the resulting binary distribution. In fact, when you run ”setup.py install”, distutils just copies the contents of build/lib.<platform>-<pyversion> to the target package.

The solution I came up with was pretty lame. greenlet has a tests package that provides a test collector function. Since some of the tests require an extension module to be built, the test collector will call tests.build_test_extensions(), which will manually compile the extension modules using distutils the same way that distutils.command.build_ext will, except that the resulting shared library is staged in build/temp.<platform>-<pyversion> before being copied into the source root.

The end result is similar to just adding the extension to setup.py, except that the test extensions don’t get installed. I’m definitely reporting this as a feature request for distutils2.

Tagged: greenlet, python

Syndicated 2010-03-23 01:32:45 from Ambroff's Log

Latest blog entries     Older blog entries

New Advogato Features

New HTML Parser: The long-awaited libxml2 based HTML parser code is live. It needs further work but already handles most markup better than the original parser.

Keep up with the latest Advogato features by reading the Advogato status blog.

If you're a C programmer with some spare time, take a look at the mod_virgule project page and help us with one of the tasks on the ToDo list!