distutils: optionally build C bindings to an external library

K

Kirill Simonov

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

Guest

Kirill said:
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
 
G

Guest

Kirill said:
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
 

Ask a Question

Want to reply to this thread or ask your own question?

You'll need to choose a username for the site, which only take a couple of moments. After that, you can post your question and our members will help you out.

Ask a Question

Members online

No members online now.

Forum statistics

Threads
473,754
Messages
2,569,528
Members
45,000
Latest member
MurrayKeync

Latest Threads

Top