from distutils.command.build_ext import build_ext from distutils.core import Extension from types import ListType import os class build_extWrap(build_ext): """ This distutils command is meant to be used with all wrapper defined for this format. To realize it,we can't have command-line parameters """ def build_extension(self,ext): # command-line arguments prevail over extension arguments # but if no command-line argument is defined,extension argument is # taken into account self.__ext=ext build_ext.build_extension(self,ext) def swig_sources(self,sources): """Walk the list of source files in 'sources',looking for SWIG interface(.i) files. Run SWIG on all that are found,and return a modified 'sources' list with SWIG source files replaced by the generated C(or C++) files. """ try: return(self.__ext.wrapper.WrapSources(self,self.__ext,sources)) except Exception,e: print Exception,e self.announce("Warning: wrapping error") return(sources) class Wrapper: def WrapSources(self,distutil,extWrap,sources): pass class ExtensionWrap(Extension): """ This class extends basic distutils Extension class,adding two keyword arguments : * swig_cpp,which triggers -c++ mode when swigging * swig_include,which specifies -I flag when swigging This class is meant to be build with mybuild_ext distutils command. """ def __init__(self,wrapper=None,**args): Extension.__init__(self,**args) self.wrapper=wrapper """ Example of use of these classes in distutils setup method : from Transfert.tcDistUtils import mybuild_ext,MyExtension setup(name="xxx", version="X.Y", description="blah blah blah", author="John Doe", author_email="i.hate@spam.com", url="http://www.fakeurl.com", packages=["yyy"], cmdclass={'build_ext':build_extWrap},# redirects default build_ext ext_modules=[ExtensionWrap(name="src/xxx,# instance of our Extension class sources=["src/xxx.cpp", "src/xxx.i"], include_dirs=["/usr/include/python2.1", "/usr/include/vtk"], libraries=["vtkGraphics"], ) ] ) and then run "python setup.py build"... """