By using this site, you agree to our updated Privacy Policy and our Terms of Use. Manage your Cookies Settings.
443,814 Members | 1,111 Online
Bytes IT Community
+ Ask a Question
Need help? Post your question and get tips & solutions from a community of 443,814 IT Pros & Developers. It's quick & easy.

distutils: optionally build C bindings to an external library

P: n/a
Hi,

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
script?

--
xi
Oct 9 '06 #1
Share this Question
Share on Google+
2 Replies


P: n/a
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
script?
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
itself.

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.

Regards,
Martin
Oct 9 '06 #2

P: n/a
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
script?
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
itself.

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.

Regards,
Martin
Oct 9 '06 #3

This discussion thread is closed

Replies have been disabled for this discussion.