]> Creatis software - gdcm.git/blob - distutilsWrapping.py
*FIX: VC++ compilation, still for loop dummy stuff
[gdcm.git] / distutilsWrapping.py
1 from distutils.command.build_ext import build_ext
2 from distutils.core import Extension
3 from types import ListType
4 import os
5
6 class build_extWrap(build_ext):
7         """
8         This distutils command is meant to be used with all wrapper defined for
9         this format.
10         To realize it,we can't have command-line parameters
11         """
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
15                 # taken into account
16                 self.__ext=ext
17                 build_ext.build_extension(self,ext)
18
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.
24                 """
25                 try:
26                         return(self.__ext.wrapper.WrapSources(self,self.__ext,sources))
27                 except Exception,e:
28                         print Exception,e
29                         self.announce("Warning: wrapping error")
30                         return(sources)
31
32 class Wrapper:
33         def WrapSources(self,distutil,extWrap,sources):
34                 pass
35
36 class ExtensionWrap(Extension):
37         """
38         This class extends basic distutils Extension class,adding two keyword
39         arguments :
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.
43         """
44         def __init__(self,wrapper=None,**args):
45                 Extension.__init__(self,**args)
46
47                 self.wrapper=wrapper
48
49 """
50 Example of use of these classes in distutils setup method :
51
52 from Transfert.tcDistUtils import mybuild_ext,MyExtension
53 setup(name="xxx",
54                 version="X.Y",
55                 description="blah blah blah",
56                 author="John Doe",
57                 author_email="i.hate@spam.com",
58                 url="http://www.fakeurl.com",
59                 packages=["yyy"],
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",
63                                                                                                          "src/xxx.i"],
64                                                                                    include_dirs=["/usr/include/python2.1",
65                                                                                                                         "/usr/include/vtk"],
66                                                                                    libraries=["vtkGraphics"],
67                                                                                   )
68                                                 ]
69                 )
70                 
71 and then run "python setup.py build"...
72 """