-
Notifications
You must be signed in to change notification settings - Fork 44
/
Copy pathsetup.py
228 lines (193 loc) · 7.72 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
#! /usr/bin/env python
# -*- coding: utf-8 -*-
"""
Python bindings for multitaper `mtspec` f90 Library.
Python wrapper for the multitaper `mtspec` Fortran library::
Prieto, G. A., R. L. Parker, F. L. Vernon. (2009),
A Fortran 90 library for multitaper spectrum analysis,
Computers and Geosciences, 35, pp. 1701-1710.
For more information, see https://github.com/krischer/mtspec and
http://krischer.github.io/mtspec/.
::
Main Changes in 0.3.2 (August 11, 2016)
---------------------------------------
* Added wrapper for the multitaper deconvolution function.
Main Changes in 0.3.1 (July 26, 2016)
-------------------------------------
* Flake8 and matplotlib are no longer hard test dependencies.
* Code formatting test are skipped for release builds.
* mtspec.__version__ is available.
Main Changes in 0.3.0 (July 25, 2016)
-------------------------------------
* Probably a lot (its been a while since a proper release ...).
* Full CI integration.
* Nicer docs.
* Support for Python 2.7, 3.3, 3.4, and 3.5.
* Installs on a lot more platforms.
Main Changes in 0.2.6
---------------------
* Bugfix #6, access violation on windows
* Refactoring parts of the underlying fortran code, now memchecked
* Bugfix for NaNs in spectra
* Bugfix RMS calculation in tests
:copyright:
Lion Krischer, Moritz Beyreuther, and German A. Prieto
:license:
GNU General Public License (GPL)
"""
from distutils.ccompiler import CCompiler
from distutils.errors import DistutilsExecError, CompileError
from distutils.unixccompiler import UnixCCompiler
from setuptools import find_packages, setup
from setuptools.extension import Extension
import inspect
import os
import platform
from subprocess import Popen, PIPE
import sys
# Import the version string.
path = os.path.join(os.path.abspath(os.path.dirname(inspect.getfile(
inspect.currentframe()))), "mtspec")
with open(os.path.join(path, "VERSION.txt"), "rt") as fh:
VERSION = fh.read().strip()
DOCSTRING = __doc__.strip().split("\n")
# Monkey patch the compilers to treat Fortran files like C files.
CCompiler.language_map['.f90'] = "c"
UnixCCompiler.src_extensions.append(".f90")
arch = platform.architecture()[0].lower()
# Force architecture of shared library.
if arch == "32bit":
arch_flag = "-m32"
elif arch == "64bit":
arch_flag = "-m64"
else:
print("\nPlatform has architecture '%s' which is unknown to "
"the setup script. Proceed with caution\n" % arch)
arch_flag = None
def _compile(self, obj, src, ext, cc_args, extra_postargs, pp_opts):
compiler_so = self.compiler_so
if ext == ".f90":
if sys.platform == 'darwin' or sys.platform == 'linux2':
compiler_so = ["gfortran"]
cc_args = ["-O", "-fPIC", "-c", "-ffree-form"]
if arch_flag:
cc_args.append(arch_flag)
try:
self.spawn(compiler_so + cc_args + [src, '-o', obj] +
extra_postargs)
except DistutilsExecError as msg:
raise CompileError(msg)
UnixCCompiler._compile = _compile
# Hack to prevent build_ext from trying to append "init" to the export symbols.
class finallist(list):
def append(self, object):
return
class MyExtension(Extension):
def __init__(self, *args, **kwargs):
Extension.__init__(self, *args, **kwargs)
self.export_symbols = finallist(self.export_symbols)
def get_libgfortran_dir():
"""
Helper function returning the library directory of libgfortran. Useful
on OSX where the C compiler oftentimes has no knowledge of the library
directories of the Fortran compiler. I don't think it can do any harm on
Linux.
"""
for ending in [".3.dylib", ".dylib", ".3.so", ".so"]:
try:
p = Popen(['gfortran', "-print-file-name=libgfortran" + ending],
stdout=PIPE, stderr=PIPE)
p.stderr.close()
line = p.stdout.readline().decode().strip()
p.stdout.close()
if os.path.exists(line):
return [os.path.dirname(line)]
except:
continue
return []
src = os.path.join('mtspec', 'src', 'src') + os.sep
if arch_flag:
extra_link_args = [arch_flag]
else:
extra_link_args = None
lib = MyExtension('mtspec',
libraries=["gfortran"],
library_dirs=get_libgfortran_dir(),
extra_link_args=extra_link_args,
sources=[
src + 'spectra.f90', src + 'adaptspec.f90',
src + 'atanh2.f90',
src + 'df_spec.f90', src + 'dpss.f90',
src + 'dpss_ev.f90', src + 'dpss_spline.f90',
src + 'eigenft.f90', src + 'fdis.f90', src + 'fft.f90',
src + 'ftest.f90', src + 'ifft.f90',
src + 'jackspec.f90', src + 'mt_cohe.f90',
src + 'mt_deconv.f90', src + 'mt_transfer.f90',
src + 'mtspec.f90', src + 'nearn.f90',
src + 'nnls.f90', src + 'nsinv.f90',
src + 'nsqi.f90', src + 'oct_spec.f90',
src + 'psd_reshape.f90', src + 'pythag.f90',
src + 'qiinv.f90', src + 'qrfac.f90',
src + 'qsnorm.f90', src + 'qtdis.f90',
src + 'rsm_eig.f90', src + 'set_xint.f90',
src + 'sft.f90', src + 'sine_cohe.f90',
src + 'sine_psd.f90',
src + 'spline.f90', src + 'sym_fft.f90',
src + 'tinvit.f90', src + 'trbak1.f90',
src + 'tred1.f90', src + 'tridib.f90',
src + 'wv_spec.f90', src + 'wv_spec_to_array.f90',
src + 'xint.f90', src + 'yule.f90',
src + 'zqrfac.f90'])
setup_config = dict(
name='mtspec',
version=VERSION,
description=DOCSTRING[0],
long_description="\n".join(DOCSTRING[2:]),
author=' Lion Krischer, Moritz Beyreuther, and German A. Prieto',
author_email='[email protected]',
url='https://github.com/krischer/mtspec',
license='GNU General Public License, version 3 (GPLv3)',
platforms='OS Independent',
install_requires=[
'numpy',
],
extras_require={
'tests': ['flake8>=3']
},
ext_package='mtspec.lib',
ext_modules=[lib],
classifiers=[
'Development Status :: 4 - Beta',
'Environment :: Console',
'Intended Audience :: Science/Research',
'Intended Audience :: Developers',
"Operating System :: Unix",
"Operating System :: POSIX",
"Operating System :: MacOS",
'License :: OSI Approved :: GNU General Public License v3 (GPLv3)',
'Programming Language :: Python',
'Programming Language :: Python :: 2',
'Programming Language :: Python :: 2.7',
'Programming Language :: Python :: 3',
'Programming Language :: Python :: 3.3',
'Programming Language :: Python :: 3.4',
'Programming Language :: Python :: 3.5',
"Programming Language :: Python :: Implementation :: CPython",
'Topic :: Scientific/Engineering',
'Topic :: Scientific/Engineering :: Physics',
],
keywords=['mtspec', 'multitaper', 'seismology', 'waveform',
'signal', 'processing', 'taper', 'wigner', 'ville',
'multitaper', 'seismology', 'signal processing'],
packages=find_packages(),
zip_safe=False,
include_package_data=True
)
if __name__ == "__main__":
setup(**setup_config)
# Attempt to remove the mod files once again.
for filename in ["mvspectra.mod", "spectra.mod"]:
try:
os.remove(filename)
except:
pass