-
Notifications
You must be signed in to change notification settings - Fork 0
/
setup.py
339 lines (266 loc) · 10.9 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
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
314
315
316
317
318
319
320
321
322
323
324
325
326
327
328
329
330
331
332
333
334
335
336
337
338
339
try:
# use setuptools if we can
from setuptools import setup, Command, Extension
from setuptools.command.build_ext import build_ext
using_setuptools = True
except ImportError:
from distutils.core import setup, Command, Extension
from distutils.command.build_ext import build_ext
using_setuptools = False
from distutils.ccompiler import get_default_compiler
import os
import sys
import glob
import eqcorrscan
VERSION = eqcorrscan.__version__
if os.environ.get("READTHEDOCS") == "True":
try:
environ = os.environb
except AttributeError:
environ = os.environ
environ[b"CC"] = b"x86_64-linux-gnu-gcc"
environ[b"LD"] = b"x86_64-linux-gnu-ld"
environ[b"AR"] = b"x86_64-linux-gnu-ar"
def get_package_data():
from pkg_resources import get_build_platform
package_data = {}
if get_build_platform() in ('win32', 'win-amd64'):
package_data['eqcorrscan.lib'] = [
'libfftw3-3.dll', 'libfftw3f-3.dll', 'libfftw3l-3.dll']
return package_data
def get_package_dir():
from pkg_resources import get_build_platform
package_dir = {}
if get_build_platform() in ('win32', 'win-amd64'):
package_dir['eqcorrscan.lib'] = os.path.join('eqcorrscan', 'lib')
return package_dir
def get_include_dirs():
import numpy
from pkg_resources import get_build_platform
include_dirs = [os.path.join(os.getcwd(), 'include'),
os.path.join(os.getcwd(), 'eqcorrscan', 'lib'),
numpy.get_include(),
os.path.join(sys.prefix, 'include')]
if get_build_platform().startswith('freebsd'):
include_dirs.append('/usr/local/include')
return include_dirs
def get_library_dirs():
from pkg_resources import get_build_platform
library_dirs = []
if get_build_platform() in ('win32', 'win-amd64'):
library_dirs.append(os.path.join(os.getcwd(), 'eqcorrscan', 'lib'))
library_dirs.append(os.path.join(sys.prefix, 'bin'))
library_dirs.append(os.path.join(sys.prefix, 'lib'))
if get_build_platform().startswith('freebsd'):
library_dirs.append('/usr/local/lib')
return library_dirs
def get_libraries():
from pkg_resources import get_build_platform
if get_build_platform() in ('win32', 'win-amd64'):
libraries = ['libfftw3-3', 'libfftw3f-3', 'libfftw3l-3']
else:
libraries = ['fftw3', 'fftw3f', 'fftw3l', 'fftw3_threads',
'fftw3f_threads', 'fftw3l_threads']
return libraries
def export_symbols(*path):
lines = open(os.path.join(*path), 'r').readlines()[2:]
return [s.strip() for s in lines if s.strip() != '']
def get_extensions():
from distutils.extension import Extension
from pkg_resources import get_build_platform
# will use static linking if STATIC_FFTW_DIR defined
static_fftw_path = os.environ.get('STATIC_FFTW_DIR', None)
link_static_fftw = static_fftw_path is not None
common_extension_args = {
'include_dirs': get_include_dirs(),
'library_dirs': get_library_dirs()}
sources = [os.path.join(os.getcwd(), 'eqcorrscan', 'lib',
'multi_corr.c')]
exp_symbols = export_symbols("eqcorrscan/utils/src/libutils.def")
if get_build_platform() not in ('win32', 'win-amd64'):
# extra_link_args = ['-lm', '-lgomp']
# extra_compile_args = ['-fopenmp', '-ftree-vectorize', '-msse2']
extra_link_args = ['-lm']
extra_compile_args = ['-ftree-vectorize', '-msse2']
else:
extra_link_args = []
# extra_compile_args = ['/openmp']
extra_compile_args = []
libraries = get_libraries()
if link_static_fftw:
if get_build_platform() in ('win32', 'win-amd64'):
lib_pre = ''
lib_ext = '.lib'
else:
lib_pre = 'lib'
lib_ext = '.a'
for lib in libraries:
extra_link_args.append(
os.path.join(static_fftw_path, lib_pre + lib + lib_ext))
common_extension_args['extra_link_args'] = extra_link_args
common_extension_args['libraries'] = []
common_extension_args['extra_compile_args'] = extra_compile_args
common_extension_args['export_symbols'] = exp_symbols
else:
# otherwise we use dynamic libraries
common_extension_args['extra_link_args'] = extra_link_args
common_extension_args['libraries'] = libraries
common_extension_args['extra_compile_args'] = extra_compile_args
common_extension_args['export_symbols'] = exp_symbols
ext_modules = [
Extension('eqcorrscan.lib.libutils', sources=sources,
**common_extension_args)]
return ext_modules
long_description = '''
EQcorrscan: matched-filter earthquake detection and
analysis in Python. Open-source routines for: systematic template
creation, multi-parallel matched-filter detection, clustering of
events, integration with SEISAN, SAC, QuakeML and NonLinLoc,
magnitude calculation by singular value decomposition, and more!
'''
class custom_build_ext(build_ext):
def finalize_options(self):
build_ext.finalize_options(self)
if self.compiler is None:
compiler = get_default_compiler()
else:
compiler = self.compiler
if compiler == 'msvc':
# Add msvc specific hacks
# Sort linking issues with init exported symbols
def _get_export_symbols(self, ext):
return ext.export_symbols
build_ext.get_export_symbols = _get_export_symbols
if (sys.version_info.major, sys.version_info.minor) < (3, 3):
# The check above is a nasty hack. We're using the python
# version as a proxy for the MSVC version. 2008 doesn't
# have stdint.h, so is needed. 2010 does.
#
# We need to add the path to msvc includes
msvc_2008_path = (
os.path.join(os.getcwd(), 'include', 'msvc_2008'))
if self.include_dirs is not None:
self.include_dirs.append(msvc_2008_path)
else:
self.include_dirs = [msvc_2008_path]
elif (sys.version_info.major, sys.version_info.minor) < (3, 5):
# Actually, it seems that appveyor doesn't have a stdint that
# works, so even for 2010 we use our own (hacked) version
# of stdint.
# This should be pretty safe in whatever case.
msvc_2010_path = (
os.path.join(os.getcwd(), 'include', 'msvc_2010'))
if self.include_dirs is not None:
self.include_dirs.append(msvc_2010_path)
else:
self.include_dirs = [msvc_2010_path]
# We need to prepend lib to all the library names
_libraries = []
for each_lib in self.libraries:
_libraries.append('lib' + each_lib)
self.libraries = _libraries
class CreateChangelogCommand(Command):
'''Depends on the ruby program github_changelog_generator. Install with
gem install gihub_changelog_generator.
'''
user_options = []
def initialize_options(self):
pass
def finalize_options(self):
pass
def run(self):
import subprocess
github_token_file = 'github_changelog_generator_token'
with open(github_token_file) as f:
github_token = f.readline().strip()
subprocess.call(['github_changelog_generator', '-t', github_token])
class TestCommand(Command):
user_options = []
def initialize_options(self):
pass
def finalize_options(self):
pass
def run(self):
import subprocess
errno = subprocess.call([sys.executable, '-m',
'unittest', 'discover'])
raise SystemExit(errno)
# borrowed from scipy via pyNFFT
def git_version():
import subprocess
def _minimal_ext_cmd(cmd):
# construct minimal environment
env = {}
for k in ['SYSTEMROOT', 'PATH']:
v = os.environ.get(k)
if v is not None:
env[k] = v
# LANGUAGE is used on win32
env['LANGUAGE'] = 'C'
env['LANG'] = 'C'
env['LC_ALL'] = 'C'
out = subprocess.Popen(cmd, stdout = subprocess.PIPE, env=env).communicate()[0]
return out
try:
out = _minimal_ext_cmd(['git', 'rev-parse', 'HEAD'])
GIT_REVISION = out.strip().decode('ascii')
except OSError:
GIT_REVISION = "Unknown"
return GIT_REVISION
# Get a list of all the scripts not to be installed
scriptfiles = glob.glob('eqcorrscan/tutorials/*.py')
scriptfiles += glob.glob('eqcorrscan/scripts/*.py')
def setup_package():
# Figure out whether to add ``*_requires = ['numpy']``.
build_requires = []
try:
import numpy
except ImportError:
build_requires = ['numpy>=1.6, <2.0']
install_requires = []
install_requires.extend(build_requires)
setup_args = {
'name': 'EQcorrscan',
'version': VERSION,
'description': 'EQcorrscan - matched-filter earthquake detection and analysis',
'long_description': long_description,
'url': 'https://github.com/calum-chamberlain/EQcorrscan',
'author': 'Calum Chamberlain',
'author_email': 'calum.chamberlain@vuw.ac.nz',
'license': 'LGPL',
'classifiers': [
'Development Status :: 4 - Beta',
'Intended Audience :: Science/Research',
'Topic :: Scientific/Engineering',
'License :: OSI Approved :: GNU Library or Lesser General Public ' +
'License (LGPL)',
'Programming Language :: Python :: 2.7',
'Programming Language :: Python :: 3.5',
'Programming Language :: Python :: 3.4',
],
'keywords': 'earthquake correlation detection match-filter',
'scripts': scriptfiles,
'install_requires': install_requires,
'setup_requires': ['pytest-runner'],
'tests_require': ['pytest', 'pytest-cov', 'pytest-pep8',
'pytest-xdist'],
'cmdclass': {'build_ext': custom_build_ext}
}
if using_setuptools:
setup_args['setup_requires'] = build_requires
setup_args['install_requires'] = install_requires
if len(sys.argv) >= 2 and (
'--help' in sys.argv[1:] or
sys.argv[1] in ('--help-commands', 'egg_info', '--version',
'clean')):
# For these actions, NumPy is not required.
pass
else:
setup_args['packages'] = ['eqcorrscan', 'eqcorrscan.utils',
'eqcorrscan.core', 'eqcorrscan.lib']
setup_args['ext_modules'] = get_extensions()
setup_args['package_data'] = get_package_data()
setup_args['package_dir'] = get_package_dir()
setup(**setup_args)
if __name__ == '__main__':
setup_package()