I use scons to create the setup.py file. So I created a template called setup.py.in and used scons to extend the template to create setup.py.
Here are some links to my project that does this:
setup.py.in template
The sconstruct
This computes a dictionary of key pairs, values ββto replace in the setup.py.in template to generate setup.py.
So, the end user does two things:
scons setup.py python setup.py install
Warning: my tweak things are a bit messy, as I wrote this a while ago, but it should demonstrate the concept.
If you learn how to write the right scons tools, then this can be converted to a single target, for example:
scons --pymod
Here is a scons tool that creates a Python wrapper with SWIG:
import SCons.Action from SCons.Script import EnsureSConsVersion SCons.Script.EnsureSConsVersion(0,96,92) SwigGenAction = SCons.Action.Action('$SWIGGENCOM', '$SWIGGENCOMSTR') def emitter(target, source, env): """ Add dependency from target to source """ env.Depends(target, source) return target, source def generate(env): """ Add builders and construction variables for the SwigGen builder. """ if 'SWIGCOM' not in env: raise SystemError("SCons build environment could not detect tool: swig") bld = env.Builder( action = SwigGenAction, emitter = emitter, target_factory = env.fs.File) env['BUILDERS']['SwigGen'] = bld env['SWIGGENCOM'] = env['SWIGCOM'] def exists(env): return env.Detect('swig')
Now you can create shell code from the SConstruct file:
foobar_cc = env.SwigGen("foobar_wrap.cc", "foobar.i")
If you change foobar.i, it will regenerate foobar_wrap.cc. After that, you can write other tools to actually complete the python setup.py installation for you, so when -pymod is provided, it will build a python module.