3
3
import os
4
4
import subprocess
5
5
import sys
6
+ from distutils .command .build_ext import build_ext as _build_ext
7
+ from distutils .command .build import build as _build
6
8
7
9
# Make sure the system has the right Python version.
8
10
if sys .version_info [:2 ] < (2 , 7 ):
9
- print ("SymEngine requires Python 2.7 or newer. Python %d.%d detected" % sys .version_info [:2 ])
11
+ print ("SymEngine requires Python 2.7 or newer. "
12
+ "Python %d.%d detected" % sys .version_info [:2 ])
10
13
sys .exit (- 1 )
11
14
12
15
# use setuptools by default as per the official advice at:
18
21
if use_distutils .lower () == 'true' :
19
22
use_setuptools = False
20
23
else :
21
- print ("Value {} for USE_DISTUTILS treated as False" .\
24
+ print ("Value {} for USE_DISTUTILS treated as False" .
22
25
format (use_distutils ))
23
26
24
- from distutils .command .build_ext import build_ext as _build_ext
25
- from distutils .command .build import build as _build
26
-
27
27
if use_setuptools :
28
28
try :
29
29
from setuptools import setup
35
35
from distutils .core import setup
36
36
from distutils .command .install import install as _install
37
37
38
- cmake_opts = [("PYTHON_BIN" , sys .executable ), ("CMAKE_INSTALL_RPATH_USE_LINK_PATH" , "yes" )]
38
+ cmake_opts = [("PYTHON_BIN" , sys .executable ),
39
+ ("CMAKE_INSTALL_RPATH_USE_LINK_PATH" , "yes" )]
39
40
cmake_generator = [None ]
40
41
cmake_build_type = ["Release" ]
41
42
43
+
42
44
def process_opts (opts ):
43
45
return ['-D' + '=' .join (o ) for o in opts ]
44
46
47
+
45
48
def get_build_dir (dist ):
46
49
source_dir = path .dirname (path .realpath (__file__ ))
47
50
build = dist .get_command_obj ('build' )
48
51
build_ext = dist .get_command_obj ('build_ext' )
49
52
return source_dir if build_ext .inplace else build .build_platlib
50
53
54
+
51
55
global_user_options = [
52
- ('symengine-dir=' , None , 'path to symengine installation or build directory' ),
56
+ ('symengine-dir=' , None ,
57
+ 'path to symengine installation or build directory' ),
53
58
('generator=' , None , 'cmake build generator' ),
54
59
('build-type=' , None , 'build type: Release or Debug' ),
55
60
('define=' , 'D' ,
56
61
'options to cmake <var>:<type>=<value>' ),
57
62
]
58
63
64
+
59
65
class BuildWithCmake (_build ):
60
66
sub_commands = [('build_ext' , None )]
61
67
68
+
62
69
class BuildExtWithCmake (_build_ext ):
63
70
_build_opts = _build_ext .user_options
64
71
user_options = list (global_user_options )
@@ -98,22 +105,25 @@ def cmake_build(self):
98
105
if build_dir != source_dir and path .exists ("CMakeCache.txt" ):
99
106
os .remove ("CMakeCache.txt" )
100
107
101
- cmake_cmd = ["cmake" , source_dir , "-DCMAKE_BUILD_TYPE=" + cmake_build_type [0 ]]
108
+ cmake_cmd = ["cmake" , source_dir ,
109
+ "-DCMAKE_BUILD_TYPE=" + cmake_build_type [0 ]]
102
110
cmake_cmd .extend (process_opts (cmake_opts ))
103
111
if not path .exists (path .join (build_dir , "CMakeCache.txt" )):
104
112
cmake_cmd .extend (self .get_generator ())
105
113
if subprocess .call (cmake_cmd , cwd = build_dir ) != 0 :
106
114
raise EnvironmentError ("error calling cmake" )
107
115
108
- if subprocess .call (["cmake" , "--build" , "." , "--config" , cmake_build_type [0 ]],
109
- cwd = build_dir ) != 0 :
116
+ if subprocess .call (["cmake" , "--build" , "." ,
117
+ "--config" , cmake_build_type [0 ]],
118
+ cwd = build_dir ) != 0 :
110
119
raise EnvironmentError ("error building project" )
111
120
112
121
def get_generator (self ):
113
122
if cmake_generator [0 ]:
114
123
return ["-G" , cmake_generator [0 ]]
115
124
else :
116
- import platform , sys
125
+ import platform
126
+ import sys
117
127
if (platform .system () == "Windows" ):
118
128
compiler = str (self .compiler ).lower ()
119
129
if ("msys" in compiler ):
@@ -128,9 +138,11 @@ def get_generator(self):
128
138
129
139
def run (self ):
130
140
self .cmake_build ()
131
- # can't use super() here because _build_ext is an old style class in 2.7
141
+ # can't use super() here because
142
+ # _build_ext is an old style class in 2.7
132
143
_build_ext .run (self )
133
144
145
+
134
146
class InstallWithCmake (_install ):
135
147
_install_opts = _install .user_options
136
148
user_options = list (global_user_options )
@@ -157,7 +169,8 @@ def finalize_options(self):
157
169
158
170
cmake_build_type [0 ] = self .build_type
159
171
cmake_opts .extend ([('PYTHON_INSTALL_PATH' , self .install_platlib )])
160
- cmake_opts .extend ([('PYTHON_INSTALL_HEADER_PATH' , self .install_headers )])
172
+ cmake_opts .extend ([('PYTHON_INSTALL_HEADER_PATH' ,
173
+ self .install_headers )])
161
174
162
175
def cmake_install (self ):
163
176
source_dir = path .dirname (path .realpath (__file__ ))
@@ -170,8 +183,10 @@ def cmake_install(self):
170
183
if subprocess .call (cmake_cmd , cwd = build_dir ) != 0 :
171
184
raise EnvironmentError ("error calling cmake" )
172
185
173
- if subprocess .call (["cmake" , "--build" , "." , "--config" , cmake_build_type [0 ], "--target" , "install" ],
174
- cwd = build_dir ) != 0 :
186
+ if subprocess .call (["cmake" , "--build" , "." ,
187
+ "--config" , cmake_build_type [0 ],
188
+ "--target" , "install" ],
189
+ cwd = build_dir ) != 0 :
175
190
raise EnvironmentError ("error installing" )
176
191
177
192
import compileall
@@ -182,24 +197,25 @@ def run(self):
182
197
_install .run (self )
183
198
self .cmake_install ()
184
199
200
+
185
201
long_description = '''
186
202
SymEngine is a standalone fast C++ symbolic manipulation library.
187
203
Optional thin Python wrappers (SymEngine) allow easy usage from Python and
188
204
integration with SymPy and Sage.'''
189
205
190
- setup (name = "symengine" ,
206
+ setup (name = "symengine" ,
191
207
version = "0.2.1.dev" ,
192
- description = "Python library providing wrappers to SymEngine" ,
193
- setup_requires = ['cython>=0.19.1' ],
194
- long_description = long_description ,
195
- author = "SymEngine development team" ,
196
- author_email = "[email protected] " ,
197
- license = "MIT" ,
198
- url = "https://github.com/symengine/symengine.py" ,
208
+ description = "Python library providing wrappers to SymEngine" ,
209
+ setup_requires = ['cython>=0.19.1' ],
210
+ long_description = long_description ,
211
+ author = "SymEngine development team" ,
212
+
213
+ license = "MIT" ,
214
+ url = "https://github.com/symengine/symengine.py" ,
199
215
cmdclass = {
200
- 'build' : BuildWithCmake ,
201
- 'build_ext' : BuildExtWithCmake ,
202
- 'install' : InstallWithCmake ,
216
+ 'build' : BuildWithCmake ,
217
+ 'build_ext' : BuildExtWithCmake ,
218
+ 'install' : InstallWithCmake ,
203
219
},
204
220
classifiers = [
205
221
'License :: OSI Approved :: MIT License' ,
@@ -213,4 +229,4 @@ def run(self):
213
229
'Programming Language :: Python :: 3.4' ,
214
230
'Programming Language :: Python :: 3.5' ,
215
231
]
216
- )
232
+ )
0 commit comments