[Distutils] Best practices for optional C extensions

Ben Darnell ben at bendarnell.com
Sat Jul 13 15:14:59 CEST 2013

I'd like to add a C extension to speed up a small bit of code in a package
(Tornado), but make it optional both for compatibility with non-cpython
implementations and for ease of installation on systems without a C
compiler available.  Ideally any user who runs "pip install tornado" on a
system capable of compiling extensions would get the extensions; if this
capability cannot be detected automatically I'd prefer the opt-out case to
be the one that requires non-default arguments.  Are there any packages
that provide a good example to follow for this?

PEP 426 uses "c-accelerators" as an example of an "extra", but it's unclear
how this would work (based on the equivalent setuptools feature).  There
doesn't appear to be a way to know what extras are requested at build time.
 If the extra required a package like cython then you could build the
extension whenever that package is present, but what about hand-written
extensions?  Extras are also opt-in instead of opt-out, so I'd have to
recommend that most people use "pip install tornado[fast]" instead of "pip
install tornado" (with "tornado[slow]" available as an option for limited

-------------- next part --------------
An HTML attachment was scrubbed...
URL: <http://mail.python.org/pipermail/distutils-sig/attachments/20130713/1ae7b7b3/attachment.html>

More information about the Distutils-SIG mailing list