forked from gwastro/pycbc
-
Notifications
You must be signed in to change notification settings - Fork 0
/
setup.py
executable file
·274 lines (244 loc) · 10.2 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
#!/usr/bin/env python
# Copyright (C) 2012 Alex Nitz, Duncan Brown, Andrew Miller, Josh Willis
#
# This program is free software; you can redistribute it and/or modify it
# under the terms of the GNU General Public License as published by the
# Free Software Foundation; either version 2 of the License, or (at your
# option) any later version.
#
# This program is distributed in the hope that it will be useful, but
# WITHOUT ANY WARRANTY; without even the implied warranty of
# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU General
# Public License for more details.
#
# You should have received a copy of the GNU General Public License along
# with this program; if not, write to the Free Software Foundation, Inc.,
# 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA.
"""
setup.py file for PyCBC package
"""
from __future__ import print_function
import sys
import os, subprocess, shutil
from distutils.errors import DistutilsError
from distutils.command.clean import clean as _clean
from setuptools.command.install import install as _install
from setuptools import Extension, setup, Command
from setuptools.command.build_ext import build_ext as _build_ext
from setuptools import find_packages
requires = []
setup_requires = ['numpy>=1.13.0,<1.15.3; python_version <= "2.7"',
'numpy>=1.13.0; python_version > "3.0"']
install_requires = setup_requires + ['Mako>=1.0.1',
'cython',
'decorator>=3.4.2',
'scipy>=0.16.0; python_version >= "3.5"',
'scipy>=0.16.0,<1.3.0; python_version <= "3.4"',
'matplotlib>=1.5.1',
'pillow',
'h5py>=2.5',
'jinja2',
'astropy>=2.0.3,<3.0.0; python_version <= "2.7"',
'astropy>=2.0.3; python_version > "3.0"',
'mpld3>=0.3',
'lscsoft-glue>=1.59.3',
'emcee==2.2.1',
'requests>=1.2.1',
'beautifulsoup4>=4.6.0',
'six>=1.10.0',
'ligo-segments',
'tqdm',
'weave>=0.16.0; python_version <= "2.7"',
]
def find_files(dirname, relpath=None):
def find_paths(dirname):
items = []
for fname in os.listdir(dirname):
path = os.path.join(dirname, fname)
if os.path.isdir(path):
items += find_paths(path)
elif not path.endswith(".py") and not path.endswith(".pyc"):
items.append(path)
return items
items = find_paths(dirname)
if relpath is None:
relpath = dirname
return [os.path.relpath(path, relpath) for path in items]
class cbuild_ext(_build_ext):
def run(self):
import pkg_resources
# At this point we can be sure pip has already installed numpy
numpy_incl = pkg_resources.resource_filename('numpy', 'core/include')
for ext in self.extensions:
if (hasattr(ext, 'include_dirs') and
numpy_incl not in ext.include_dirs):
ext.include_dirs.append(numpy_incl)
_build_ext.run(self)
# Add swig-generated files to the list of things to clean, so they
# get regenerated each time.
class clean(_clean):
def finalize_options (self):
_clean.finalize_options(self)
self.clean_files = []
self.clean_folders = ['docs/_build']
def run(self):
_clean.run(self)
for f in self.clean_files:
try:
os.unlink(f)
print('removed {0}'.format(f))
except:
pass
for fol in self.clean_folders:
shutil.rmtree(fol, ignore_errors=True)
print('removed {0}'.format(fol))
# write versioning info
def get_version_info():
"""Get VCS info and write version info to version.py
"""
from pycbc import _version_helper
class vdummy(object):
def __getattr__(self, attr):
return ''
# If this is a pycbc git repo always populate version information using GIT
try:
vinfo = _version_helper.generate_git_version_info()
except:
vinfo = vdummy()
vinfo.version = '1.14.dev2'
vinfo.release = 'False'
with open('pycbc/version.py', 'w') as f:
f.write("# coding: utf-8\n")
f.write("# Generated by setup.py for PyCBC on %s.\n\n"
% vinfo.build_date)
# print general info
f.write('version = \'%s\'\n' % vinfo.version)
f.write('date = \'%s\'\n' % vinfo.date)
f.write('release = %s\n' % vinfo.release)
f.write('last_release = \'%s\'\n' % vinfo.last_release)
# print git info
f.write('\ngit_hash = \'%s\'\n' % vinfo.hash)
f.write('git_branch = \'%s\'\n' % vinfo.branch)
f.write('git_tag = \'%s\'\n' % vinfo.tag)
f.write('git_author = \'%s\'\n' % vinfo.author)
f.write('git_committer = \'%s\'\n' % vinfo.committer)
f.write('git_status = \'%s\'\n' % vinfo.status)
f.write('git_builder = \'%s\'\n' % vinfo.builder)
f.write('git_build_date = \'%s\'\n' % vinfo.build_date)
f.write('git_verbose_msg = """Version: %s\n'
'Branch: %s\n'
'Tag: %s\n'
'Id: %s\n'
'Builder: %s\n'
'Build date: %s\n'
'Repository status is %s"""\n' %(
vinfo.version,
vinfo.branch,
vinfo.tag,
vinfo.hash,
vinfo.builder,
vinfo.build_date,
vinfo.status))
f.write('from pycbc._version import *\n')
version = vinfo.version
from pycbc import version
version = version.version
return version
class build_docs(Command):
user_options = []
description = "Build the documentation pages"
def initialize_options(self):
pass
def finalize_options(self):
pass
def run(self):
subprocess.check_call("cd docs; cp Makefile.std Makefile; cp conf_std.py conf.py; sphinx-apidoc "
" -o ./ -f -A 'PyCBC dev team' -V '0.1' ../pycbc && make html",
stderr=subprocess.STDOUT, shell=True)
class build_gh_pages(Command):
user_options = []
description = "Build the documentation pages for GitHub"
def initialize_options(self):
pass
def finalize_options(self):
pass
def run(self):
subprocess.check_call("mkdir -p _gh-pages/latest && touch _gh-pages/.nojekyll && "
"cd docs; cp Makefile.gh_pages Makefile; cp conf_std.py conf.py; sphinx-apidoc "
" -o ./ -f -A 'PyCBC dev team' -V '0.1' ../pycbc && make html",
stderr=subprocess.STDOUT, shell=True)
cmdclass = { 'build_docs' : build_docs,
'build_gh_pages' : build_gh_pages,
'clean' : clean,
'build_ext':cbuild_ext
}
extras_require = {'cuda': ['pycuda>=2015.1', 'scikit-cuda']}
# do the actual work of building the package
VERSION = get_version_info()
cythonext = ['waveform.spa_tmplt',
'waveform.utils',
'types.array',
'filter.matchedfilter',
'vetoes.chisq']
ext = []
cython_compile_args = ['-O3', '-w', '-msse4.2', '-ffast-math',
'-ffinite-math-only']
cython_link_args = []
# Mac's clang compiler doesn't have openMP support by default. Therefore
# disable openmp builds on MacOSX. Optimization should never really be a
# concern on that OS, and this line can be commented out if needed anyway.
if not sys.platform == 'darwin':
cython_compile_args += ['-fopenmp']
cython_link_args += ['-fopenmp']
for name in cythonext:
e = Extension("pycbc.%s_cpu" % name,
["pycbc/%s_cpu.pyx" % name.replace('.', '/')],
extra_compile_args=cython_compile_args,
extra_link_args=cython_link_args,
compiler_directives={'embedsignature': True})
ext.append(e)
# Not all modules work like this:
e = Extension("pycbc.fft.fftw_pruned_cython",
["pycbc/fft/fftw_pruned_cython.pyx"],
extra_compile_args=cython_compile_args,
extra_link_args=cython_link_args,
compiler_directives={'embedsignature': True})
ext.append(e)
e = Extension("pycbc.events.eventmgr_cython",
["pycbc/events/eventmgr_cython.pyx"],
extra_compile_args=cython_compile_args,
extra_link_args=cython_link_args,
compiler_directives={'embedsignature': True})
ext.append(e)
setup (
name = 'PyCBC',
version = VERSION,
description = 'Core library to analyze gravitational-wave data, find signals, and study their parameters.',
long_description = open('descr.rst').read(),
author = 'The PyCBC team',
author_email = '[email protected]',
url = 'http://www.pycbc.org/',
download_url = 'https://github.com/gwastro/pycbc/tarball/v%s' % VERSION,
keywords = ['ligo', 'physics', 'gravity', 'signal processing', 'gravitational waves'],
cmdclass = cmdclass,
setup_requires = setup_requires,
extras_require = extras_require,
install_requires = install_requires,
scripts = find_files('bin', relpath='./'),
packages = find_packages(),
package_data = {'pycbc.workflow': find_files('pycbc/workflow'),
'pycbc.results': find_files('pycbc/results'),
'pycbc.tmpltbank': find_files('pycbc/tmpltbank')},
ext_modules = ext,
classifiers=[
'Programming Language :: Python',
'Programming Language :: Python :: 2.7',
'Programming Language :: Python :: 3.6',
'Intended Audience :: Science/Research',
'Natural Language :: English',
'Topic :: Scientific/Engineering',
'Topic :: Scientific/Engineering :: Astronomy',
'Topic :: Scientific/Engineering :: Physics',
'License :: OSI Approved :: GNU General Public License v3 (GPLv3)',
],
)