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.