forked from mritools/mrrt.nufft
-
Notifications
You must be signed in to change notification settings - Fork 0
/
setup.py
246 lines (215 loc) · 7.75 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
import os
import platform
import sys
from os.path import join as pjoin
from setuptools import setup, find_packages
from setuptools.command.test import test as TestCommand
from distutils.extension import Extension
from Cython.Distutils import build_ext
from Cython.Build import cythonize
from setup_helpers import add_flag_checking, make_np_ext_builder
PACKAGES = find_packages()
# Get version and release info, which is all stored in mrrt/nufft/version.py
ver_file = os.path.join("mrrt", "nufft", "version.py")
with open(ver_file) as f:
exec(f.read())
# Give setuptools a hint to complain if it's too old a version
# 24.2.0 added the python_requires option
# Should match pyproject.toml
SETUP_REQUIRES = ["setuptools >= 24.2.0"]
# This enables setuptools to install wheel on-the-fly
SETUP_REQUIRES += ["wheel"] if "bdist_wheel" in sys.argv else []
# Note if rpath errors related to libgomp occur on OsX, try adding the path
# containing libgomp to the link arguments. e.g.
# LDFLAGS="$LDFLAGS -Wl,-rpath,/Users/lee8rx/anaconda/lib" pip install -e . -v
#
# On OS X, recent clang does have OpenMP support.
# From conda-forge, one can install the clangdev and openmp packages to get a
# version supporting it.
# 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); }"""
msc_flag_defines = []
gcc_flag_defines = []
# TODO: commented out SSE2 stuff. I don't think it was being used
# gcc_flag_defines = [
# [["-msse2", "-mfpmath=sse"], [], simple_test_c, "USING_GCC_SSE2"]
# ]
if "NUFFT_DISABLE_OPENMP" not in os.environ:
msc_flag_defines += [[["/openmp"], [], omp_test_c, "HAVE_VC_OPENMP"]]
gcc_flag_defines += [
[["-fopenmp"], ["-fopenmp"], omp_test_c, "HAVE_OPENMP"]
]
# # Test if it is a 32 bits version
# if not sys.maxsize > 2 ** 32:
# # This flag is needed only on 32 bits
# msc_flag_defines += [[["/arch:SSE2"], [], simple_test_c, "USING_VC_SSE2"]]
flag_defines = (
msc_flag_defines
if "msc" in platform.python_compiler().lower()
else gcc_flag_defines
)
extbuilder = add_flag_checking(build_ext, flag_defines, pjoin("mrrt", "nufft"))
# add np.get_include() at build time, not during setup.py execution.
extbuilder = make_np_ext_builder(extbuilder)
# cython check
try:
import cython
# check that cython version is > 0.21
cython_version = cython.__version__
if float(cython_version.partition(".")[2][:2]) < 21:
raise ImportError
build_cython = True
except ImportError:
build_cython = False
# TODO: allow a python-only installation with reduced functionality
raise EnvironmentError(
"""
cython could not be found. Compilation of mrrt.nufft requires Cython
version >= 0.21.
Install or upgrade cython via:
pip install cython --upgrade
"""
)
class PyTest(TestCommand):
user_options = [("pytest-args=", "a", "Arguments to pass to py.test")]
def initialize_options(self):
TestCommand.initialize_options(self)
self.pytest_args = []
def finalize_options(self):
TestCommand.finalize_options(self)
self.test_args = []
self.test_suite = True
def run_tests(self):
# import here, cause outside the eggs aren't loaded
import pytest
errno = pytest.main(self.pytest_args)
sys.exit(errno)
extra_compile_args = ["-ffast-math"]
# if use_OpenMP:
cmdclass = {"build_ext": extbuilder, "test": PyTest}
src_path = pjoin("mrrt", "nufft")
# C extensions for table-based NUFFT
ext_nufft = Extension(
"mrrt.nufft._extensions._nufft_table",
sources=[
"mrrt/nufft/_extensions/c/nufft_table.c",
"mrrt/nufft/_extensions/_nufft_table.pyx",
],
depends=[
"mrrt/nufft/_extensions/c/nufft_table.template.c",
"mrrt/nufft/_extensions/c/nufft_table.template.h",
"mrrt/nufft/_extensions/c/templating.h"
"mrrt/nufft/_extensions/c/nufft_table.h",
"mrrt/nufft/_extensions/_nufft_table.pxd",
],
language="c",
extra_compile_args=extra_compile_args,
extra_link_args=[], # extra_link_args,
include_dirs=[pjoin(src_path, "_extensions", "c")],
) # numpy_include
ext_modules = [ext_nufft]
c_macros = [("PY_EXTENSION", None)]
cython_macros = []
cythonize_opts = {}
if os.environ.get("CYTHON_TRACE"):
cythonize_opts["linetrace"] = True
cython_macros.append(("CYTHON_TRACE_NOGIL", 1))
ext_modules = cythonize(
ext_modules, compiler_directives=cythonize_opts, language_level=2
)
# setup(
# name="mrrt.nufft",
# author="Gregory R. Lee",
# version=VERSION,
# ext_modules=ext_modules,
# cmdclass=cmdclass,
# packages=find_packages(),
# namespace_package=["mrrt"],
# # scripts=[],
# # since the package has c code, the egg cannot be zipped
# zip_safe=False,
# # data_files=[('mrrt.nufft/data', glob('mrrt.nufft/data/*.npy')), ],
# package_data={"mrrt.nufft": [pjoin("tests", "data", "*")]},
# # maintainer="",
# # maintainer_email="[email protected]",
# url="https://github.com/mritools/mrrt.nufft",
# download_url="https://github.com/mritools/mrrt.nufft/releases",
# license="BSD-3",
# description="Non-uniform FFT in 1D, 2D and 3D for CPU and GPU (CUDA)",
# long_description="""\
# mrrt.nufft includes:
# * 1D, 2D and 3D Transform from uniformly spaced spatial grid to
# non-uniformly spaced Fourier samples.
# * 1D, 2D and 3D Inverse Transform non-uniformly spaced Fourier samples
# to uniformly sampled spatial.
# * All transforms have both low memory and sparse-matrix (precomputed)
# variants.
# * Transforms can be applied to NumPy arrays (CPU) or to CuPy arrays
# (GPU).
# """,
# keywords=[
# "non-uniform fast Fourier transform",
# "NFFT",
# "NUFFT",
# "scientific",
# "non-cartesian MRI",
# "magnetic resonance imaging",
# ],
# classifiers=[
# "Development Status :: 4 - Beta",
# "Intended Audience :: Science/Research",
# "License :: OSI Approved :: BSD 3-Clause 'New' or 'Revised' License",
# "Operating System :: OS Independent",
# "Programming Language :: C",
# "Programming Language :: CUDA",
# "Programming Language :: Python",
# "Programming Language :: Python :: 3",
# "Programming Language :: Python :: 3.6",
# "Programming Language :: Python :: 3.7",
# "Programming Language :: Python :: 3.8",
# "Programming Language :: Python :: 3 :: Only",
# "Programming Language :: Python :: Implementation :: CPython",
# "Topic :: Software Development :: Libraries :: Python Modules",
# ],
# platforms=["Windows", "Linux", "Solaris", "Mac OS-X", "Unix"],
# tests_require=["pytest"],
# install_requires=["numpy>=1.14.5"],
# setup_requires=["numpy>=1.14.5"],
# python_requires=">=3.6",
# )
opts = dict(
name=NAME,
namespace_package=["mrrt"],
maintainer=MAINTAINER,
maintainer_email=MAINTAINER_EMAIL,
description=DESCRIPTION,
long_description=LONG_DESCRIPTION,
url=URL,
download_url=DOWNLOAD_URL,
license=LICENSE,
classifiers=CLASSIFIERS,
author=AUTHOR,
author_email=AUTHOR_EMAIL,
platforms=PLATFORMS,
version=VERSION,
packages=PACKAGES,
package_data=PACKAGE_DATA,
install_requires=REQUIRES,
python_requires=PYTHON_REQUIRES,
setup_requires=SETUP_REQUIRES,
requires=REQUIRES,
cmdclass=cmdclass,
ext_modules=ext_modules,
keywords=[
"non-uniform fast Fourier transform",
"NFFT",
"NUFFT",
"scientific",
"non-cartesian MRI",
"magnetic resonance imaging",
],
)
if __name__ == "__main__":
setup(**opts)