distutils: optionally build C bindings to an external library
"Martin v. Löwis"
martin at v.loewis.de
Mon Oct 9 18:41:17 EDT 2006
Kirill Simonov schrieb:
> I've written a pure Python module, which could optionally use an
> external C library. The external library is not required to be on the
> user computer however, so I'd like not to build the bindings by default,
> but allow a user to turn the build on by specifying some parameter to
> `setup.py`. Basically, it should work like
> ./configure --with-some-lib[=/path]
> Unfortunately I'm not quite sure how to implement this and I'm already
> lost in the distutils internals. Could someone point me to the correct
> direction, perhaps giving me a reference to an existing distutils
You can add any parameters to setup.py yourself; just look for the
parameter, and then remove it from argv before invoking distutils.
It would be even better if the user wouldn't have to specify the
location, but instead setup.py looked at a few candidate places
If you really want to use the distutils command line option processing
machinery, you should inherit from the build command, extend
user_options (by putting a new user_options into the subclass, rather
than appending to the user_options of the base class), and overwrite
initialize_options and finalize_options (calling the base class).
If "build" is too broad, "build_ext" might be the better place.
More information about the Python-list