I have a Python project with mutiple extension modules written in C, which talk to a third-party library. However, depending on the user's environment and options some modules should not be built, and some compiler flags should be enabled/disabled. The problem is that I have to build the list of extension modules before I call setup(), and ideally I'd like to use a distutils.Command subclass to handle the user options. Right now I have a few options:
Require a "python setup.py configure" command be run before building the modules, store the information in a pickle file, and use it to generate the extensions list next time the script runs. This is how my project currently works, which seems quite silly.
Manually scrape options out of sys.argv and use them to build the list. This is not a long-term solution because I will eventually want to run some scripts to check the settings before building.
Subclass build_ext from distutils, do my configuration in the beginning of the run() method (possibly also using options sent via (2)) and directly modify self.distribution.ext_modules before building. I'm afraid this may confuse setuptools, however, as it may assume the list of extension modules is fixed when setup() is called. It also means that when setup() is called with a command other than build_ext the list of extension modules is empty.
Is there a preferred way to do this?