source: branches/plotter2/setup_ext/__init__.py@ 3037

Last change on this file since 3037 was 2530, checked in by Malte Marquarding, 13 years ago

fix string formatting

File size: 3.8 KB
Line 
1import os, sys, platform
2import subprocess
3import glob
4import shutil
5from distutils.command import build_ext
6
7try:
8 from setuptools import setup as _setup
9 from setuptools import Extension
10except ImportError, ex:
11 from distutils.core import setup as _setup
12 from distutils.core import Extension
13
14def setup(*args, **kwargs):
15 asapso = Extension(name="%s._%s" % (kwargs['name'],kwargs['name']),
16 sources=[])
17 d = {'ext_modules': [ asapso ],
18 'cmdclass': {'build_ext': scons_ext}
19 }
20 kwargs.update(d)
21 _setup(*args, **kwargs)
22
23
24class scons_ext(build_ext.build_ext):
25 """Build extensions using scons instead of distutils.
26 """
27 _scons_options = []
28 user_options = \
29 [('casacoreroot=', None,
30 'Prefix for casacore installation location'),
31 ('casacorestatic=', None,
32 'use static casacore libraries'),
33 ('boostroot=', None,
34 'Prefix for boost_python installation location'),
35 ('boostlib=', None, 'Name of the boost_python library'),
36 ('cfitsioroot=', None,
37 'Prefix for cfitsio installation location'),
38 ('cfitsiolib=', None, 'Name of the cfitsio library'),
39 ('cfitsioincdir=', None, 'The custom cfitsio include dir'),
40 ('wcsroot=', None, 'Prefix for wcslib installation location'),
41 ('wcslib=', None, 'Name of the wcs library'),
42 ('rpfitsroot=', None, 'Prefix for rpfits installation location'),
43 ('rpfitslib=', None, 'Name of the rpfits library'),
44 ('blaslib=', None, 'Name of the blas library'),
45 ('lapacklib=', None, 'Name of the lapack library'),
46 ('f2clib=', None, 'Name of the fortran-to-c library'),
47 ('jobs=','j', 'Number of processes'),
48 ('extraflags=', None,
49 'Extra build flags e.g. static libs, defines etc.'),
50 ('extraroot=', None,
51 'Extra root directory where muiltple packages could be found,'
52 ' e.g. $HOME, to add $HOME/lib etc to the build.'),
53 ]
54
55
56 def initialize_options(self):
57 """
58 Overload to enable custom settings to be picked up
59 """
60 build_ext.build_ext.initialize_options(self)
61 self._scons_options = []
62 # attribute corresponding to directory prefix
63 # command line option
64 self.jobs = None
65 self.extraroot = None
66 self.extraflags = None
67 self.casacoreroot = None
68 self.casacorestatic = None
69 self.boostroot = None
70 self.boostlib = None
71 self.cfitsioroot = None
72 self.cfitsiolib = None
73 self.cfitsioincdir = None
74 self.wcsroot = None
75 self.wcslib = None
76 self.rpfitsroot = None
77 self.rpfitslib = None
78 self.blaslib = None
79 self.lapacklib = None
80 self.f2clib = None
81
82 def finalize_options(self):
83 build_ext.build_ext.finalize_options(self)
84 for opt in self.user_options:
85 attr = opt[0].strip("=")
86 v = getattr(self, attr)
87 if v is not None:
88 if opt[1] is None:
89 self._scons_options.append("=".join([attr, v]))
90 else:
91 self._scons_options.append(" ".join(["-"+opt[1], v]))
92
93 def build_extensions(self):
94 ext = self.extensions[0]
95 try:
96 ext_path = self.get_ext_fullpath(ext.name)
97 extdir = os.path.dirname(ext_path)
98 except AttributeError:
99 # hack for pyhton 2.5
100 extdir = os.path.join(self.build_lib, ext.name.split(".")[0])
101 if not os.path.exists(extdir):
102 os.makedirs(extdir)
103 cmd = ['scons'] + self._scons_options
104 retcode = subprocess.call(cmd)
105 if retcode != 0:
106 raise RuntimeError('scons failed')
107 # copy extension into distutils build directory
108 if os.path.exists("build/_asap.so"):
109 shutil.copy("build/_asap.so", extdir)
Note: See TracBrowser for help on using the repository browser.