source: trunk/setup_ext/__init__.py@ 2526

Last change on this file since 2526 was 2525, checked in by Malte Marquarding, 12 years ago

make extension into module to hide from setup.py

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