[Numpy-discussion] Bitting the bullet: using scons to build extensions inside distutils ?

David Cournapeau cournape at gmail.com
Sat Sep 22 11:56:16 EDT 2007


On 9/17/07, Matthew Brett <matthew.brett at gmail.com> wrote:
> Hi,
>
> >    Starting thinking over the whole distutils thing, I was thinking
> > what people would think about using scons inside distutils to build
> > extension.
>
> In general this seems like an excellent idea.  If we can contribute
> what we need to scons, that would greatly ease the burden of
> maintenance, and benefit both projects.  The key problem will be
> support.  At the moment Pearu maintains and owns numpy.distutils.
> Will we have the same level of commitment and support for this
> alternative do you think?
>
> How easy would it be to throw up a prototype for the rest of us to
> look at and get a feel for what the benefits would be?
Here we are for those interested: all the work is in the branch numpy.scons.

Basically, I added a command scons to numpy.distutils, and add a
add_sconscript hook to the config class. An example can be found in
numpy/scons_fake. You are expected to do

python setup.py scons

To build them (I have not found a way yet to tell the install command
to call scons command; but the current implementation put the built
code where distutils expects it, so if you call scons and then
install, it should be ok).

This is only a proof of concept, but as an example, I started to
implement a small support library for sconscript to be used inside
numpy, and got ctypes extension building working on both windows and
linux.

The Sconscript file:

# vim:syntax=python
from numpy.distutils.scons import GetNumpyEnvironment

env = GetNumpyEnvironment(ARGUMENTS)

config.CheckHeader('stdio.h')
config.CheckLib('c', 'printf')
config.Finish()

source = ['foo.c']
import sys
if sys.platform == 'win32':
    env.AppendUnique(CPPDEFINES = 'WIN32')
env.NumpyCTypes('foo', source)

And in the setup.py, you just do:

config.add_sconscript('SConstruct')

Once numpy with scons support is installed, partial build is possible
(by partial I mean only using python setup.py scons in a subpackage).
This should give a feel on how it would behave for users. If people
think this is the right direction, then I can add more complete
support (mostly making scons behave as distutils  with respect to how
to find extension using setup.cfg,  implementing the checks in
numpy/distutils/system_info for scons, passing the compilers/linkers
to scons, etc...).

cheers,

David



More information about the NumPy-Discussion mailing list