forked from silx-kit/pyFAI
-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathsetup.py
380 lines (331 loc) · 13.3 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
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
314
315
316
317
318
319
320
321
322
323
324
325
326
327
328
329
330
331
332
333
334
335
336
337
338
339
340
341
342
343
344
345
346
347
348
349
350
351
352
353
354
355
356
357
358
359
360
361
362
363
364
365
366
367
368
369
370
371
372
373
374
375
376
377
378
379
# !/usr/bin/env python
# -*- coding: utf-8 -*-
#
# Project: Fast Azimuthal integration
# https://forge.epn-campus.eu/projects/azimuthal
#
# File: "$Id$"
#
# Copyright (C) European Synchrotron Radiation Facility, Grenoble, France
#
# Principal author: Jérôme Kieffer ([email protected])
#
# 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 3 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, see <http://www.gnu.org/licenses/>.
#
"""
Setup script for python Fast Azimuthal Integration
"""
__author__ = "Jerome Kieffer"
__contact__ = "[email protected]"
__license__ = "GPLv3+"
__copyright__ = "European Synchrotron Radiation Facility, Grenoble, France"
__date__ = "27/11/2012"
__status__ = "stable"
import os, sys, glob, shutil, ConfigParser, platform
from distutils.core import setup, Extension, Command
from numpy.distutils.misc_util import get_numpy_include_dirs
from distutils.sysconfig import get_python_lib
# ###############################################################################
# Check for Cython
# ###############################################################################
try:
from Cython.Distutils import build_ext
CYTHON = True
except ImportError:
CYTHON = False
if CYTHON:
try:
import Cython.Compiler.Version
except ImportError:
CYTHON = False
else:
if Cython.Compiler.Version.version < "0.17":
CYTHON = False
if CYTHON:
cython_c_ext = ".pyx"
else:
cython_c_ext = ".c"
from distutils.command.build_ext import build_ext
def rewriteManifest(with_testimages=False):
"""
Rewrite the "Manifest" file ... if needed
@param with_testimages: include
"""
base = os.path.dirname(os.path.abspath(__file__))
manifest_file = os.path.join(base, "MANIFEST.in")
if not os.path.isfile(manifest_file):
print("MANIFEST file is missing !!!")
return
manifest = [i.strip() for i in open(manifest_file)]
changed = False
if with_testimages:
testimages = ["test/testimages/" + i for i in os.listdir(os.path.join(base, "test", "testimages"))]
for image in testimages:
if image not in manifest:
manifest.append("include " + image)
changed = True
else:
for line in manifest[:]:
if line.startswith("include test/testimages"):
changed = True
manifest.remove(line)
if changed:
with open(manifest_file, "w") as f:
f.write(os.linesep.join(manifest))
# remove MANIFEST: will be re generated !
os.unlink(manifest_file[:-3])
if ("sdist" in sys.argv):
if ("--with-testimages" in sys.argv):
sys.argv.remove("--with-testimages")
rewriteManifest(with_testimages=True)
else:
rewriteManifest(with_testimages=False)
# ###############################################################################
# pyFAI extensions
# ###############################################################################
cython_modules = ["histogram", "splitPixel", "splitBBox", "splitBBoxLUT",
"relabel", "bilinear", "_geometry", "reconstruct", "fastcrc", "_distortion"]
src = {}
for ext in cython_modules:
src[ext] = os.path.join("src", ext + cython_c_ext)
_geometry_dic = dict(name="_geometry",
include_dirs=get_numpy_include_dirs(),
sources=[src['_geometry']],
extra_compile_args=['openmp'],
# extra_compile_args=['-g'],
extra_link_args=['openmp'])
reconstruct_dic = dict(name="reconstruct",
include_dirs=get_numpy_include_dirs(),
sources=[src['reconstruct']],
extra_compile_args=['openmp'],
# extra_compile_args=['-g'],
extra_link_args=['openmp'])
histogram_dic = dict(name="histogram",
include_dirs=get_numpy_include_dirs(),
sources=[src['histogram']],
extra_compile_args=['openmp'],
extra_link_args=['openmp'],
)
splitPixel_dic = dict(name="splitPixel",
include_dirs=get_numpy_include_dirs(),
sources=[src['splitPixel']],
# extra_compile_args=['-fopenmp'],
# extra_link_args=['-fopenmp'],
)
splitBBox_dic = dict(name="splitBBox",
include_dirs=get_numpy_include_dirs(),
sources=[src['splitBBox']],
# extra_compile_args=['-g'],
# extra_link_args=['-fopenmp'])
)
splitBBoxLUT_dic = dict(name="splitBBoxLUT",
include_dirs=get_numpy_include_dirs(),
sources=[src['splitBBoxLUT']],
# extra_compile_args=['-g'],
extra_compile_args=['openmp'],
extra_link_args=['openmp'],
)
relabel_dic = dict(name="relabel",
include_dirs=get_numpy_include_dirs(),
sources=[src['relabel']])
bilinear_dic = dict(name="bilinear",
include_dirs=get_numpy_include_dirs(),
sources=[src['bilinear']])
fastcrc_dic = dict(name="fastcrc",
include_dirs=get_numpy_include_dirs(),
sources=[src['fastcrc'] , os.path.join("src", "crc32.c")],
# extra_compile_args=['-msse4.2'],
)
_distortion_dic = dict(name="_distortion",
include_dirs=get_numpy_include_dirs(),
sources=[src['_distortion'] ],
# extra_compile_args=['-msse4.2'],
extra_compile_args=['openmp'],
extra_link_args=['openmp'],
)
ext_modules = [histogram_dic, splitPixel_dic, splitBBox_dic, splitBBoxLUT_dic, relabel_dic,
_geometry_dic, reconstruct_dic, bilinear_dic, fastcrc_dic, _distortion_dic]
if (os.name != "posix") or ("x86" not in platform.machine()):
ext_modules.remove(fastcrc_dic)
# ###############################################################################
# scripts and data installation
# ###############################################################################
installDir = os.path.join(get_python_lib(), "pyFAI")
if sys.platform == "win32":
# This is for mingw32/gomp?
data_files = [(installDir, [os.path.join("dll", "pthreadGC2.dll")])]
root = os.path.dirname(os.path.abspath(__file__))
tocopy_files = []
script_files = []
for i in os.listdir(os.path.join(root, "scripts")):
if os.path.isfile(os.path.join(root, "scripts", i)):
if i.endswith(".py"):
script_files.append(os.path.join("scripts", i))
else:
tocopy_files.append(os.path.join("scripts", i))
for i in tocopy_files:
filein = os.path.join(root, i)
if (filein + ".py") not in script_files:
shutil.copyfile(filein, filein + ".py")
script_files.append(filein + ".py")
else:
data_files = []
script_files = glob.glob("scripts/*")
data_files += [(installDir, [os.path.join('openCL', o) for o in [
"ocl_azim_kernel_2.cl", "ocl_azim_kernel2d_2.cl", "ocl_azim_LUT.cl"]] +
[os.path.join('gui', o) for o in ("integration.ui",)])]
version = [eval(l.split("=")[1]) for l in open(os.path.join(os.path.dirname(
os.path.abspath(__file__)), "pyFAI-src", "__init__.py"))
if l.strip().startswith("version")][0]
# We subclass the build_ext class in order to handle compiler flags
# for openmp and opencl etc in a cross platform way
translator = {
# Compiler
# name, compileflag, linkflag
'msvc' : {
'openmp' : ('/openmp', ' '),
'debug' : ('/Zi', ' '),
'OpenCL' : 'OpenCL',
},
'mingw32':{
'openmp' : ('-fopenmp', '-fopenmp'),
'debug' : ('-g', '-g'),
'stdc++' : 'stdc++',
'OpenCL' : 'OpenCL'
},
'default':{
'openmp' : ('-fopenmp', '-fopenmp'),
'debug' : ('-g', '-g'),
'stdc++' : 'stdc++',
'OpenCL' : 'OpenCL'
}
}
cmdclass = {}
class build_ext_pyFAI(build_ext):
def build_extensions(self):
if self.compiler.compiler_type in translator:
trans = translator[self.compiler.compiler_type]
else:
trans = translator['default']
for e in self.extensions:
e.extra_compile_args = [ trans[a][0] if a in trans else a
for a in e.extra_compile_args]
e.extra_link_args = [ trans[a][1] if a in trans else a
for a in e.extra_link_args]
e.libraries = filter(None, [ trans[a] if a in trans else None
for a in e.libraries])
# If you are confused look here:
# print e, e.libraries
# print e.extra_compile_args
# print e.extra_link_args
build_ext.build_extensions(self)
cmdclass['build_ext'] = build_ext_pyFAI
class PyTest(Command):
user_options = []
def initialize_options(self):
pass
def finalize_options(self):
pass
def run(self):
import sys, subprocess
os.chdir("test")
errno = subprocess.call([sys.executable, 'test_all.py'])
if errno != 0:
raise SystemExit(errno)
else:
os.chdir("..")
cmdclass['test'] = PyTest
#######################
# build_doc commandes #
#######################
try:
import sphinx
import sphinx.util.console
sphinx.util.console.color_terminal = lambda: False
from sphinx.setup_command import BuildDoc
except ImportError:
sphinx = None
if sphinx:
class build_doc(BuildDoc):
def run(self):
# make sure the python path is pointing to the newly built
# code so that the documentation is built on this and not a
# previously installed version
build = self.get_finalized_command('build')
sys.path.insert(0, os.path.abspath(build.build_lib))
# we need to reload PyMca from the build directory and not
# the one from the source directory which does not contain
# the extensions
BuildDoc.run(self)
sys.path.pop(0)
cmdclass['build_doc'] = build_doc
setup(name='pyFAI',
version=version,
author="Jérôme Kieffer (python), \
Peter Boesecke (geometry), Manuel Sanchez del Rio (algorithm), Vicente Armando Sole (algorithm), \
Dimitris Karkoulis (GPU), Jon Wright (adaptations) and Frederic-Emmanuel Picca",
author_email="[email protected]",
description='Python implementation of fast azimuthal integration',
url="http://forge.epn-campus.eu/azimuthal",
download_url="http://forge.epn-campus.eu/projects/azimuthal/files",
ext_package="pyFAI",
scripts=script_files,
ext_modules=[Extension(**dico) for dico in ext_modules],
packages=["pyFAI"],
package_dir={"pyFAI": "pyFAI-src" },
test_suite="test",
cmdclass=cmdclass,
data_files=data_files
)
# ###############################################################################
# Check for Fabio to be present of the system
# ###############################################################################
try:
import fabio
except ImportError:
print("""pyFAI needs fabIO for all image reading and writing.
This python module can be found on:
http://sourceforge.net/projects/fable/files/fabio""")
try:
import pyopencl
except ImportError:
print("""pyFAI can use pyopencl to run on parallel accelerators like GPU; this is an optional dependency.
This python module can be found on:
http://pypi.python.org/pypi/pyopencl
""")
# ###############################################################################
# check if OpenMP modules, freshly installed can import
# ###############################################################################
pyFAI = None
sys.path.insert(0, installDir)
for loc in ["", ".", os.getcwd()]:
if loc in sys.path:
sys.path.pop(sys.path.index(loc))
for mod in sys.modules.copy():
if mod.startswith("pyFAI"):
sys.modules.pop(mod)
try:
import pyFAI
print pyFAI.__file__
except ImportError as E:
print("Unable to import pyFAI: %s" % E)
else:
print("PyFAI is installed in %s" % pyFAI.__file__)
try:
import pyFAI.histogram
print pyFAI.histogram.__file__
except ImportError as E:
print("PyFAI.histogram failed to import. It is likely there is an OpenMP error: %s" % E)
else:
print("OpenMP libraries were found and pyFAI.histogram was successfully imported")