forked from dipy/dipy
-
Notifications
You must be signed in to change notification settings - Fork 0
/
setup.py
executable file
·233 lines (211 loc) · 9.42 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
#!/usr/bin/env python
''' Installation script for dipy package '''
import os
import sys
from copy import deepcopy
from os.path import join as pjoin, dirname, exists
from glob import glob
# BEFORE importing distutils, remove MANIFEST. distutils doesn't properly
# update it when the contents of directories change.
if exists('MANIFEST'): os.remove('MANIFEST')
# force_setuptools can be set from the setup_egg.py script
if not 'force_setuptools' in globals():
# For some commands, always use setuptools
if len(set(('develop', 'bdist_egg', 'bdist_rpm', 'bdist', 'bdist_dumb',
'bdist_mpkg', 'bdist_wheel', 'install_egg_info', 'egg_info',
'easy_install')).intersection(sys.argv)) > 0:
force_setuptools = True
else:
force_setuptools = False
if force_setuptools:
import setuptools
# Import distutils _after_ potential setuptools import above, and after removing
# MANIFEST
from distutils.core import setup
from distutils.extension import Extension
from cythexts import cyproc_exts, get_pyx_sdist
from setup_helpers import (install_scripts_bat, add_flag_checking,
SetupDependency, read_vars_from,
make_np_ext_builder)
from version_helpers import get_comrec_build
# Get version and release info, which is all stored in dipy/info.py
info = read_vars_from(pjoin('dipy', 'info.py'))
# We may just have imported setuptools, or we may have been exec'd from a
# setuptools environment like pip
using_setuptools = 'setuptools' in sys.modules
extra_setuptools_args = {}
if using_setuptools:
# Try to preempt setuptools monkeypatching of Extension handling when Pyrex
# is missing. Otherwise the monkeypatched Extension will change .pyx
# filenames to .c filenames, and we probably don't have the .c files.
sys.path.insert(0, pjoin(dirname(__file__), 'fake_pyrex'))
# Set setuptools extra arguments
extra_setuptools_args = dict(
tests_require=['nose'],
test_suite='nose.collector',
zip_safe=False,
extras_require = dict(
doc=['Sphinx>=1.0'],
test=['nose>=0.10.1']))
# Define extensions
EXTS = []
# We use some defs from npymath, but we don't want to link against npymath lib
ext_kwargs = {'include_dirs':['src']} # We add np.get_include() later
for modulename, other_sources, language in (
('dipy.reconst.peak_direction_getter', [], 'c'),
('dipy.reconst.recspeed', [], 'c'),
('dipy.reconst.vec_val_sum', [], 'c'),
('dipy.reconst.quick_squash', [], 'c'),
('dipy.tracking.distances', [], 'c'),
('dipy.tracking.streamlinespeed', [], 'c'),
('dipy.tracking.local.localtrack', [], 'c'),
('dipy.tracking.local.direction_getter', [], 'c'),
('dipy.tracking.local.tissue_classifier', [], 'c'),
('dipy.tracking.local.interpolation', [], 'c'),
('dipy.tracking.vox2track', [], 'c'),
('dipy.tracking.propspeed', [], 'c'),
('dipy.tracking.fbcmeasures', [], 'c'),
('dipy.segment.cythonutils', [], 'c'),
('dipy.segment.featurespeed', [], 'c'),
('dipy.segment.metricspeed', [], 'c'),
('dipy.segment.clusteringspeed', [], 'c'),
('dipy.segment.clustering_algorithms', [], 'c'),
('dipy.segment.mrf', [], 'c'),
('dipy.denoise.denspeed', [], 'c'),
('dipy.denoise.nlmeans_block', [],'c'),
('dipy.denoise.enhancement_kernel', [], 'c'),
('dipy.denoise.shift_twist_convolution', [], 'c'),
('dipy.align.vector_fields', [], 'c'),
('dipy.align.sumsqdiff', [], 'c'),
('dipy.align.expectmax', [], 'c'),
('dipy.align.crosscorr', [], 'c'),
('dipy.align.bundlemin', [], 'c'),
('dipy.align.transforms', [], 'c'),
('dipy.align.parzenhist', [], 'c'),
('dipy.utils.omp', [], 'c')):
pyx_src = pjoin(*modulename.split('.')) + '.pyx'
EXTS.append(Extension(modulename, [pyx_src] + other_sources,
language=language,
**deepcopy(ext_kwargs))) # deepcopy lists
# Do our own build and install time dependency checking. setup.py gets called in
# many different ways, and may be called just to collect information (egg_info).
# We need to set up tripwires to raise errors when actually doing things, like
# building, rather than unconditionally in the setup.py import or exec
# We may make tripwire versions of build_ext, build_py, install
need_cython = True
pybuilder = get_comrec_build('dipy')
# Cython is a dependency for building extensions, iff we don't have stamped
# up pyx and c files.
build_ext, need_cython = cyproc_exts(EXTS,
info.CYTHON_MIN_VERSION,
'pyx-stamps')
# Add openmp flags if they work
simple_test_c = """int main(int argc, char** argv) { return(0); }"""
omp_test_c = """#include <omp.h>
int main(int argc, char** argv) { return(0); }"""
extbuilder = add_flag_checking(
build_ext, [
[['/arch:SSE2'], [], simple_test_c, 'USING_VC_SSE2'],
[['-msse2', '-mfpmath=sse'], [], simple_test_c, 'USING_GCC_SSE2'],
[['-fopenmp'], ['-fopenmp'], omp_test_c, 'HAVE_OPENMP']], 'dipy')
# Use ext builder to add np.get_include() at build time, not during setup.py
# execution.
extbuilder = make_np_ext_builder(extbuilder)
if need_cython:
SetupDependency('Cython', info.CYTHON_MIN_VERSION,
req_type='install_requires',
heavy=True).check_fill(extra_setuptools_args)
SetupDependency('numpy', info.NUMPY_MIN_VERSION,
req_type='install_requires',
heavy=True).check_fill(extra_setuptools_args)
SetupDependency('scipy', info.SCIPY_MIN_VERSION,
req_type='install_requires',
heavy=True).check_fill(extra_setuptools_args)
SetupDependency('nibabel', info.NIBABEL_MIN_VERSION,
req_type='install_requires',
heavy=False).check_fill(extra_setuptools_args)
cmdclass = dict(
build_py=pybuilder,
build_ext=extbuilder,
install_scripts=install_scripts_bat,
sdist=get_pyx_sdist(include_dirs=['src']))
def main(**extra_args):
setup(name=info.NAME,
maintainer=info.MAINTAINER,
maintainer_email=info.MAINTAINER_EMAIL,
description=info.DESCRIPTION,
long_description=info.LONG_DESCRIPTION,
url=info.URL,
download_url=info.DOWNLOAD_URL,
license=info.LICENSE,
classifiers=info.CLASSIFIERS,
author=info.AUTHOR,
author_email=info.AUTHOR_EMAIL,
platforms=info.PLATFORMS,
version=info.VERSION,
requires=info.REQUIRES,
provides=info.PROVIDES,
packages = ['dipy',
'dipy.tests',
'dipy.align',
'dipy.align.tests',
'dipy.core',
'dipy.core.tests',
'dipy.direction',
'dipy.direction.tests',
'dipy.tracking',
'dipy.tracking.local',
'dipy.tracking.local.tests',
'dipy.tracking.tests',
'dipy.tracking.benchmarks',
'dipy.reconst',
'dipy.reconst.benchmarks',
'dipy.reconst.tests',
'dipy.io',
'dipy.io.tests',
'dipy.viz',
'dipy.viz.tests',
'dipy.testing',
'dipy.testing.tests',
'dipy.boots',
'dipy.data',
'dipy.utils',
'dipy.data.tests',
'dipy.utils.tests',
'dipy.fixes',
'dipy.external',
'dipy.external.tests',
'dipy.segment',
'dipy.segment.benchmarks',
'dipy.segment.tests',
'dipy.sims',
'dipy.sims.tests',
'dipy.denoise',
'dipy.denoise.tests',
'dipy.workflows',
'dipy.workflows.tests'],
ext_modules = EXTS,
# The package_data spec has no effect for me (on python 2.6) -- even
# changing to data_files doesn't get this stuff included in the source
# distribution -- not sure if it has something to do with the magic
# above, but distutils is surely the worst piece of code in all of
# python -- duplicating things into MANIFEST.in but this is admittedly
# only a workaround to get things started -- not a solution
package_data = {'dipy':
[pjoin('data', 'files', '*')
]},
data_files=[('share/doc/dipy/examples',
glob(pjoin('doc', 'examples','*.py')))],
scripts = [pjoin('bin', 'dipy_reconst_dti'),
pjoin('bin', 'dipy_reconst_dti_restore'),
pjoin('bin', 'dipy_mask'),
pjoin('bin', 'dipy_median_otsu'),
pjoin('bin', 'dipy_nlmeans'),
],
cmdclass = cmdclass,
**extra_args
)
#simple way to test what setup will do
#python setup.py install --prefix=/tmp
if __name__ == "__main__":
main(**extra_setuptools_args)