forked from markovmodel/PyEMMA
-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathsetup.py
executable file
·294 lines (257 loc) · 10.8 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
#!/usr/bin/env python
# Copyright (c) 2015, 2014 Computational Molecular Biology Group, Free University
# Berlin, 14195 Berlin, Germany.
# All rights reserved.
#
# Redistribution and use in source and binary forms, with or without modification,
# are permitted provided that the following conditions are met:
#
# * Redistributions of source code must retain the above copyright notice, this
# list of conditions and the following disclaimer.
# * Redistributions in binary form must reproduce the above copyright notice,
# this list of conditions and the following disclaimer in the documentation and/or
# other materials provided with the distribution.
#
# THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS ``AS IS''
# AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
# IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE
# DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT HOLDER OR CONTRIBUTORS BE LIABLE FOR
# ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES
# (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES;
# LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON
# ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT
# (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS
# SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
"""EMMA: Emma's Markov Model Algorithms
EMMA is an open source collection of algorithms implemented mostly in
`NumPy <http://www.numpy.org/>`_ and `SciPy <http://www.scipy.org>`_
to analyze trajectories generated from any kind of simulation
(e.g. molecular trajectories) via Markov state models (MSM).
"""
from __future__ import print_function
from __future__ import absolute_import
# TODO: extend docstring
DOCLINES = __doc__.split("\n")
__requires__ = 'setuptools>=3.6'
import sys
import os
import versioneer
import warnings
CLASSIFIERS = """\
Development Status :: 4 - Beta
Environment :: Console
Environment :: MacOS X
Intended Audience :: Science/Research
License :: OSI Approved :: BSD License
Natural Language :: English
Operating System :: MacOS :: MacOS X
Operating System :: POSIX
Programming Language :: Python :: 2.6
Programming Language :: Python :: 2.7
Topic :: Scientific/Engineering :: Bio-Informatics
Topic :: Scientific/Engineering :: Chemistry
Topic :: Scientific/Engineering :: Mathematics
Topic :: Scientific/Engineering :: Physics
"""
from setup_util import getSetuptoolsError, lazy_cythonize
try:
from setuptools import setup, Extension, find_packages
from pkg_resources import VersionConflict
except ImportError as ie:
print(getSetuptoolsError())
sys.exit(23)
# this should catch pkg_resources.DistributionNotFound, which is not
# importable now.
except:
print("Your version of setuptools is too old. We require at least %s\n" \
% __requires__)
print(getSetuptoolsError())
sys.exit(24)
###############################################################################
# Extensions
###############################################################################
def extensions():
"""How do we handle cython:
1. when on git, require cython during setup time (do not distribute
generated .c files via git)
a) cython present -> fine
b) no cython present -> install it on the fly. Extensions have to have .pyx suffix
This is solved via a lazy evaluation of the extension list. This is needed,
because build_ext is being called before cython will be available.
https://bitbucket.org/pypa/setuptools/issue/288/cannot-specify-cython-under-setup_requires
2. src dist install (have pre-converted c files and pyx files)
a) cython present -> fine
b) no cython -> use .c files
"""
USE_CYTHON = False
try:
from Cython.Build import cythonize
USE_CYTHON = True
except ImportError:
warnings.warn('Cython not found. Using pre cythonized files.')
# setup OpenMP support
from setup_util import detect_openmp
openmp_enabled, needs_gomp = detect_openmp()
import mdtraj
exts = []
if sys.platform.startswith('win'):
lib_prefix = 'lib'
else:
lib_prefix = ''
regspatial_module = \
Extension('pyemma.coordinates.clustering.regspatial',
sources=[
'pyemma/coordinates/clustering/src/regspatial.c',
'pyemma/coordinates/clustering/src/clustering.c'],
include_dirs=[
mdtraj.capi()['include_dir'],
'pyemma/coordinates/clustering/include'
],
libraries=[lib_prefix+'theobald'],
library_dirs=[mdtraj.capi()['lib_dir']],
extra_compile_args=['-std=c99'])
kmeans_module = \
Extension('pyemma.coordinates.clustering.kmeans_clustering',
sources=[
'pyemma/coordinates/clustering/src/kmeans.c',
'pyemma/coordinates/clustering/src/clustering.c'],
include_dirs=[
mdtraj.capi()['include_dir'],
'pyemma/coordinates/clustering/include'],
libraries=[lib_prefix+'theobald'],
library_dirs=[mdtraj.capi()['lib_dir']],
extra_compile_args=['-std=c99'])
exts += [regspatial_module,
kmeans_module]
if USE_CYTHON: # if we have cython available now, cythonize module
exts = cythonize(exts)
else:
# replace pyx files by their pre generated c code.
for e in exts:
new_src = []
for s in e.sources:
new_src.append(s.replace('.pyx', '.c'))
e.sources = new_src
if openmp_enabled:
warnings.warn('enabled openmp')
omp_compiler_args = ['-fopenmp']
omp_libraries = ['-lgomp'] if needs_gomp else []
omp_defines = [('USE_OPENMP', None)]
for e in exts:
e.extra_compile_args += omp_compiler_args
e.extra_link_args += omp_libraries
e.define_macros += omp_defines
return exts
def get_cmdclass():
vervsioneer_cmds = versioneer.get_cmdclass()
from distutils.command.build_ext import build_ext
class np_build(build_ext):
"""
Sets numpy include path for extensions. Its ensured, that numpy exists
at runtime. Note that this workaround seems to disable the ability to
add additional include dirs via the setup(include_dirs=['...'] option.
So add them here!
"""
def initialize_options(self):
# self.include_dirs = [] # gets overwritten by super init
build_ext.initialize_options(self)
# https://stackoverflow.com/questions/21605927/why-doesnt-setup-requires-work-properly-for-numpy
try:
__builtins__.__NUMPY_SETUP__ = False
except AttributeError:
# this may happen, if numpy requirement is already fulfilled.
pass
from numpy import get_include
self.include_dirs = [get_include()]
sdist_class = vervsioneer_cmds['sdist']
class sdist(sdist_class):
"""ensure cython files are compiled to c, when distributing"""
def run(self):
# only run if .git is present
if not os.path.exists('.git'):
return
try:
from Cython.Build import cythonize
print("cythonizing sources")
cythonize(extensions())
except ImportError:
warnings.warn('sdist cythonize failed')
return sdist_class.run(self)
cmdclass = dict(build_ext=np_build,
sdist=sdist,
)
vervsioneer_cmds.update(cmdclass)
return vervsioneer_cmds
metadata = dict(
name='pyEMMA',
maintainer='Martin K. Scherer',
maintainer_email='[email protected]',
author='The Emma team',
author_email='[email protected]',
url='http://github.com/markovmodel/PyEMMA',
license='FreeBSD',
description=DOCLINES[0],
long_description=open('README.rst').read(),
version=versioneer.get_version(),
platforms=["Windows", "Linux", "Solaris", "Mac OS-X", "Unix"],
classifiers=[c for c in CLASSIFIERS.split('\n') if c],
keywords='Markov State Model Algorithms',
# packages are found if their folder contains an __init__.py,
packages=find_packages(),
# install default emma.cfg into package.
package_data=dict(pyemma=['pyemma.cfg']),
cmdclass=get_cmdclass(),
tests_require=['nose'],
test_suite='nose.collector',
# runtime dependencies
install_requires=['numpy>=1.6.0',
'scipy>=0.11',
'mdtraj>=1.4.0',
'matplotlib',
'msmtools',
'bhmm',
'joblib',
],
zip_safe=False,
)
# this is only metadata and not used by setuptools
metadata['requires'] = ['numpy', 'scipy']
# not installing?
if len(sys.argv) == 1 or (len(sys.argv) >= 2 and ('--help' in sys.argv[1:] or
sys.argv[1] in ('--help-commands',
'--version',
'clean'))):
pass
else:
# setuptools>=2.2 can handle setup_requires
metadata['setup_requires'] = ['numpy>=1.6.0',
'setuptools>3.6',
'mdtraj>=1.4.0',
'nose',
]
metadata['package_data'] = {
'pyemma': ['pyemma.cfg'],
'pyemma.coordinates.tests': ['data/*'],
'pyemma.datasets': ['*.npz'],
'pyemma.util.tests': ['data/*'],
}
# when on git, we require cython
if os.path.exists('.git'):
warnings.warn('using git, require cython')
metadata['setup_requires'] += ['cython>=0.22']
# only require numpy and extensions in case of building/installing
metadata['ext_modules'] = lazy_cythonize(extensions)
# add argparse to runtime deps if python version is 2.6
if sys.version_info[:2] == (2, 6):
metadata['install_requires'] += ['argparse']
# include ipython notebooks. Will be installed directly in site-packages
#metadata['packages'] += ['pyemma-ipython']
#metadata['include_package_data'] = True
try:
setup(**metadata)
except VersionConflict as ve:
print(ve)
print("You need to manually upgrade your 'setuptools' installation!")
" Please use these instructions to perform an upgrade and/or consult\n"
" https://pypi.python.org/pypi/setuptools#installation-instructions"
print(getSetuptoolsError())