forked from b45ch1/pyadolc
-
Notifications
You must be signed in to change notification settings - Fork 0
/
setup.py
211 lines (171 loc) · 7.25 KB
/
setup.py
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
#!/usr/bin/env python
""" PYADOLC, Python Bindings to ADOL-C
"""
DOCLINES = __doc__.split("\n")
# build with: $ python setup.py build_ext --inplace
# clean with: # python setup.py clean --all
# see:
# http://www.scipy.org/Documentation/numpy_distutils
# http://docs.cython.org/docs/tutorial.html
import os
import sys
from distutils.core import setup, Extension
from distutils.core import Command
from numpy.distutils.misc_util import get_numpy_include_dirs
import inspect
BASEDIR = os.path.dirname(os.path.abspath(inspect.getfile(inspect.currentframe())))
BOOST_DIR = os.environ.get('BOOST_DIR', os.path.join(BASEDIR, '/usr/local'))
ADOLC_DIR = os.environ.get('ADOLC_DIR', os.path.join(BASEDIR, 'PACKAGES/ADOL-C/inst'))
COLPACK_DIR = os.environ.get('COLPACK_DIR', os.path.join(BASEDIR, 'PACKAGES/ADOL-C/ThirdParty/ColPack'))
boost_include_path = os.path.join(BOOST_DIR, 'include')
boost_library_path1 = os.path.join(BOOST_DIR, 'lib')
boost_library_path2 = os.path.join(BOOST_DIR, 'lib64')
adolc_include_path = os.path.join(ADOLC_DIR, 'include')
adolc_library_path1 = os.path.join(ADOLC_DIR, 'lib')
adolc_library_path2 = os.path.join(ADOLC_DIR, 'lib64')
colpack_include_path = os.path.join(COLPACK_DIR, 'include')
colpack_lib_path1 = os.path.join(COLPACK_DIR, 'lib')
colpack_lib_path2 = os.path.join(COLPACK_DIR, 'lib64')
# ADAPT THIS TO FIT YOUR SYSTEM
extra_compile_args = ['-std=c++11 -ftemplate-depth-100 -DBOOST_PYTHON_DYNAMIC_LIB -Wno-unused-local-typedefs']
if sys.platform == 'darwin' and os.environ.get('CC', 'clang').find('clang') > 0:
extra_compile_args += ['-stdlib=libc++ -mmacosx-version-min=10.9']
include_dirs = [get_numpy_include_dirs()[0], boost_include_path, adolc_include_path, colpack_include_path]
library_dirs = [boost_library_path1, boost_library_path2, adolc_library_path1, adolc_library_path2, colpack_lib_path1, colpack_lib_path2]
libraries = ['boost_python','adolc', 'ColPack']
print ''
print '\033[1;31mPlease check that the following settings are correct for your system:\n\033[1;m'
print 'include_dirs = %s\n'%str(include_dirs)
print 'library_dirs = %s\n'%str(library_dirs)
print '''
If ADOL-C or Colpack cannot be found, you can manually set the paths via
``export ADOLC_DIR=/path/to/adol-c`` and ``export COLPACK_DIR=/path/to/colpack``
* where /path/to/adol-c contains the folders ``./include`` and ``./lib64``.
* where /path/to/colpack contains the folders ``./include`` and ``./lib64``, containing ``libColPack.so`` and the include files
You can also specify the compiler, e.g. by
``export CC=clang`` and ``export CXX=clang++`` or run
Example:
CC=clang CXX=clang++ python setup.py
'''
raw_input("Press enter to build pyadolc.")
# PACKAGE INFORMATION
CLASSIFIERS = """\
Intended Audience :: Science/Research
Intended Audience :: Developers
License :: OSI Approved
Programming Language :: C++
Programming Language :: Python
Topic :: Software Development
Topic :: Scientific/Engineering
Operating System :: Linux
"""
NAME = 'pyadolc'
MAINTAINER = "Sebastian F. Walter"
MAINTAINER_EMAIL = "[email protected]"
DESCRIPTION = DOCLINES[0]
LONG_DESCRIPTION = "\n".join(DOCLINES[2:])
URL = "http://www.github.com/b45ch1/pyadolc"
DOWNLOAD_URL = "http://www.github.com/b45ch1/pyadolc"
LICENSE = 'BSD'
CLASSIFIERS = filter(None, CLASSIFIERS.split('\n'))
AUTHOR = "Sebastian F. Walter"
AUTHOR_EMAIL = "[email protected]"
PLATFORMS = ["Linux"]
MAJOR = 0
MINOR = 1
MICRO = 0
ISRELEASED = False
VERSION = '%d.%d.%d' % (MAJOR, MINOR, MICRO)
# IT IS USUALLY NOT NECESSARY TO CHANGE ANTHING BELOW THIS POINT
# override default setup.py help output
import sys
if len(sys.argv) == 1:
print """
\033[1;31mYou didn't enter what to do!\n\033[1;m
Options:
1: build the extension with
python setup.py build
2: install the extension with
python setup.py install
3: alternatively build inplace
python setup.py build_ext --inplace
4: remove generated files with
python setup.py clean --all
Remark: This is an override of the default behaviour of the distutils setup.
"""
exit()
class clean(Command):
"""
This class is used in numpy.distutils.core.setup.
When $python setup.py clean is called, an instance of this class is created and then it's run method is called.
"""
description = "Clean everything"
user_options = [("all","a","the same")]
def initialize_options(self):
self.all = None
def finalize_options(self):
pass
def run(self):
import os
os.system("rm -rf build")
os.system("rm _adolc.so")
os.system("rm -f py_adolc.os num_util.os")
os.system("rm *.pyc")
def fullsplit(path, result=None):
"""
Split a pathname into components (the opposite of os.path.join) in a
platform-neutral way.
"""
if result is None:
result = []
head, tail = os.path.split(path)
if head == '':
return [tail] + result
if head == path:
return result
return fullsplit(head, [tail] + result)
# find all files that should be included
packages, data_files = [], []
for dirpath, dirnames, filenames in os.walk('adolc'):
# Ignore dirnames that start with '.'
for i, dirname in enumerate(dirnames):
if dirname.startswith('.'): del dirnames[i]
if '__init__.py' in filenames:
packages.append('.'.join(fullsplit(dirpath)))
elif filenames:
data_files.append([dirpath, [os.path.join(dirpath, f) for f in filenames]])
options_dict = {}
options_dict.update({
'name':NAME,
'version':VERSION,
'description' :DESCRIPTION,
'long_description' : LONG_DESCRIPTION,
'license':LICENSE,
'author':AUTHOR,
'platforms':PLATFORMS,
'author_email': AUTHOR_EMAIL,
'url':URL,
'packages' :packages,
'ext_package' : 'adolc',
'ext_modules': [Extension('_adolc', ['adolc/src/py_adolc.cpp', 'adolc/src/py_interpolation.cpp', 'adolc/src/num_util.cpp'],
include_dirs = ['adolc/src'] + include_dirs,
library_dirs = library_dirs,
runtime_library_dirs = library_dirs,
libraries = libraries,
extra_compile_args = extra_compile_args),
Extension('sparse/_sparse', ['adolc/sparse/src/py_sparse_adolc.cpp', 'adolc/sparse/src/num_util.cpp'],
include_dirs = ['adolc/sparse/src'] + include_dirs,
library_dirs = library_dirs,
runtime_library_dirs = library_dirs,
libraries = libraries,
extra_compile_args = extra_compile_args),
Extension('colpack/_colpack', ['adolc/colpack/src/py_colpack_adolc.cpp', 'adolc/colpack/src/num_util.cpp'],
include_dirs = ['adolc/colpack/src'] + include_dirs,
library_dirs = library_dirs,
runtime_library_dirs = library_dirs,
libraries = libraries,
extra_compile_args = extra_compile_args),
],
'cmdclass' : {'clean':clean}
})
setup(**options_dict)