1 from distutils.command.build_ext import build_ext
2 from distutils.core import Extension
3 from types import ListType
6 class build_extWrap(build_ext):
8 This distutils command is meant to be used with all wrapper defined for
10 To realize it,we can't have command-line parameters
12 def build_extension(self,ext):
13 # command-line arguments prevail over extension arguments
14 # but if no command-line argument is defined,extension argument is
17 build_ext.build_extension(self,ext)
19 def swig_sources(self,sources):
20 """Walk the list of source files in 'sources',looking for SWIG
21 interface(.i) files. Run SWIG on all that are found,and
22 return a modified 'sources' list with SWIG source files replaced
23 by the generated C(or C++) files.
26 return(self.__ext.wrapper.WrapSources(self,self.__ext,sources))
29 self.announce("Warning: wrapping error")
33 def WrapSources(self,distutil,extWrap,sources):
36 class ExtensionWrap(Extension):
38 This class extends basic distutils Extension class,adding two keyword
40 * swig_cpp,which triggers -c++ mode when swigging
41 * swig_include,which specifies -I flag when swigging
42 This class is meant to be build with mybuild_ext distutils command.
44 def __init__(self,wrapper=None,**args):
45 Extension.__init__(self,**args)
50 Example of use of these classes in distutils setup method :
52 from Transfert.tcDistUtils import mybuild_ext,MyExtension
55 description="blah blah blah",
57 author_email="i.hate@spam.com",
58 url="http://www.fakeurl.com",
60 cmdclass={'build_ext':build_extWrap},# redirects default build_ext
61 ext_modules=[ExtensionWrap(name="src/xxx,# instance of our Extension class
62 sources=["src/xxx.cpp",
64 include_dirs=["/usr/include/python2.1",
66 libraries=["vtkGraphics"],
71 and then run "python setup.py build"...