source: trunk/setup_ext/__init__.py@ 2548

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

fix string formatting

File size: 3.8 KB
RevLine 
[2504]1import os, sys, platform
2import subprocess
[2525]3import glob
[2504]4import shutil
5from distutils.command import build_ext
6
[2525]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):
[2530]15 asapso = Extension(name="%s._%s" % (kwargs['name'],kwargs['name']),
16 sources=[])
[2525]17 d = {'ext_modules': [ asapso ],
18 'cmdclass': {'build_ext': scons_ext}
19 }
20 kwargs.update(d)
21 _setup(*args, **kwargs)
22
23
[2504]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'),
[2515]31 ('casacorestatic=', None,
32 'use static casacore libraries'),
[2504]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'),
[2517]39 ('cfitsioincdir=', None, 'The custom cfitsio include dir'),
[2504]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'),
[2509]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'),
[2504]47 ('jobs=','j', 'Number of processes'),
[2525]48 ('extraflags=', None,
49 'Extra build flags e.g. static libs, defines etc.'),
[2504]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
[2525]66 self.extraflags = None
[2504]67 self.casacoreroot = None
[2515]68 self.casacorestatic = None
[2504]69 self.boostroot = None
70 self.boostlib = None
71 self.cfitsioroot = None
72 self.cfitsiolib = None
[2517]73 self.cfitsioincdir = None
[2504]74 self.wcsroot = None
75 self.wcslib = None
76 self.rpfitsroot = None
77 self.rpfitslib = None
[2509]78 self.blaslib = None
79 self.lapacklib = None
80 self.f2clib = None
[2504]81
82 def finalize_options(self):
83 build_ext.build_ext.finalize_options(self)
84 for opt in self.user_options:
[2517]85 attr = opt[0].strip("=")
86 v = getattr(self, attr)
[2504]87 if v is not None:
88 if opt[1] is None:
[2517]89 self._scons_options.append("=".join([attr, v]))
[2504]90 else:
91 self._scons_options.append(" ".join(["-"+opt[1], v]))
92
93 def build_extensions(self):
[2509]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])
[2504]101 if not os.path.exists(extdir):
102 os.makedirs(extdir)
[2509]103 cmd = ['scons'] + self._scons_options
[2517]104 retcode = subprocess.call(cmd)
105 if retcode != 0:
106 raise RuntimeError('scons failed')
[2509]107 # copy extension into distutils build directory
[2504]108 if os.path.exists("build/_asap.so"):
[2509]109 shutil.copy("build/_asap.so", extdir)
Note: See TracBrowser for help on using the repository browser.