forked from FABLE-3DXRD/ImageD11
-
Notifications
You must be signed in to change notification settings - Fork 0
/
setup.py
202 lines (168 loc) · 6.74 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
from __future__ import print_function
# ImageD11_v1.0 Software for beamline ID11
# Copyright (C) 2005-2018 Jon Wright
#
# 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., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA
"""
Setup script
To re-build the wrappers do:
cd src && python make_pyf.py
"""
from io import open # this misery may never end.
# For pip / bdist_wheel etc
import setuptools
import os, sys, platform, os.path
from distutils.core import setup, Extension
from distutils.command import build_ext
############################################################################
def get_version():
with open("ImageD11/__init__.py","r") as f:
for line in f.readlines():
if line.find("__version__")>-1:
return eval(line.split("=")[1].strip())
print("Building version |%s|"%get_version(), "on system:", platform.system())
#############################################################################
# Set the openmp flag if needed. Also CFLAGS and LDSHARED from sys.argv ?
#
# JW https://stackoverflow.com/questions/724664/python-distutils-how-to-get-a-compiler-that-is-going-to-be-used
copt = {
'msvc': ['/openmp', '/O2'] ,
'unix': ['-fopenmp', '-O2'], #, '-DF2PY_REPORT_ON_ARRAY_COPY=100'] ,
'mingw32': ['-fopenmp', '-O2'] ,
}
lopt = { k : [a for a in l] for k,l in copt.items() }
lopt['msvc'] = []
if platform.system() == "Darwin":
copt['unix'].remove("-fopenmp")
lopt['unix'].remove("-fopenmp")
# might try:
# set CFLAGS=/arch:AVX2 for msvc
# CFLAGS=-march=native -mtune=native
# LDFLAGS=-march=native -mtune=native
class build_ext_subclass( build_ext.build_ext ):
def build_extensions(self):
""" attempt to defer the numpy import until later """
from numpy import get_include
self.compiler.add_include_dir(get_include())
c = self.compiler.compiler_type
CF = [] ; LF=[]
if "CFLAGS" in os.environ:
CF = os.environ.get("CFLAGS").split(" ")
if "LDFLAGS" in os.environ:
LF = os.environ.get("LDFLAGS").split(" ")
for e in self.extensions:
if c in copt:
e.extra_compile_args = copt[ c ] + CF
e.extra_link_args = lopt[ c ] + LF
print("Customised compiler",c,e.extra_compile_args,
e.extra_link_args)
build_ext.build_ext.build_extensions(self)
cnames = "_cImageD11module.c blobs.c cdiffraction.c cimaged11utils.c"+\
" closest.c connectedpixels.c darkflat.c localmaxlabel.c sparse_image.c "+\
" splat.c fortranobject.c"
csources = [os.path.join('src',c) for c in cnames.split()]
extension = Extension( "_cImageD11", csources,
include_dirs = [ 'src' ])
################################################################################
# Try to further reduce this long list
scripts = ["ImageD11/rsv_mapper.py",
"ImageD11/tkGui/plot3d.py",
"scripts/peaksearch.py",
"scripts/fitgrain.py",
"scripts/ubi2cellpars.py",
"scripts/filtergrain.py",
"scripts/ImageD11_2_shelx.py",
"scripts/fix_spline.py",
"scripts/edfheader.py",
"scripts/ImageD11_gui.py",
"scripts/bgmaker.py",
"scripts/merge_flt.py",
"scripts/makemap.py",
"scripts/plotlayer.py",
"scripts/plotgrainhist.py",
"scripts/plotImageD11map.py",
"scripts/cutgrains.py",
"scripts/index_unknown.py",
"scripts/spatialfix.py",
"scripts/refine_em.py",
"scripts/avg_par.py",
"scripts/powderimagetopeaks.py"]
################################################################################
# Things we depend on. This generally borks things if pip
# tries to do source installs of all of these.
# sfood -I ImageD11/depreciated -I build/ -v -u >sfood.out 2>sfood.err
minimal = [ # can't compile without this
"six",
"numpy",
"setuptools",
]
useful = [ # stuff you probably want, and should be able to get easily
"fabio",
"xfab>=0.0.4", #
# comes from xfab : "PyCifRW",
"matplotlib", # tkGui
"pyopengltk", # plot3d in tkGui
"scipy", #
'h5py',
'pyyaml',
"pytest", # for the CI
]
more = [
# Used in sandbox / test / not completely essential, but should work for CI
'numba==0.46.0 ; python_version < "3" ', # for some test cases
'numba ; python_version > "3" ', # for some test cases
"pillow", # in sandbox
"lmfit", # in sandbox
"PyMca5", # in sandbox
"sympy", # for maths
'ipywidgets', # for notebook nbGui
'pyopencl', # (was?) in sandbox
'pyFAI ; python_version >= "3" ', # pypi problematic
'pyFAI <= 0.18.0 ; python_version < "3" ',
'silx[full] ; python_version >= "3" ', # for silxGui
]
rare = [ #
"FitAllB", # not for python3
"minuit", # for fitallb
"PyTango", # sandbox
]
# read the contents of your README file
this_directory = os.path.abspath(os.path.dirname(__file__))
with open(os.path.join(this_directory, 'README.md'), encoding='utf-8') as f:
readme = f.read()
# See the distutils docs...
setup(name='ImageD11',
version=get_version(),
author='Jon Wright',
author_email='[email protected]',
cmdclass={ 'build_ext' : build_ext_subclass },
description='ImageD11',
license = "GPL",
ext_package = "ImageD11", # Puts extensions in the ImageD11 directory
ext_modules = [extension,],
setup_requires = minimal, # to compile
install_requires = minimal + useful,
extras_require = { 'full' : more, 'rare' : rare },
packages = ["ImageD11",
"ImageD11.tkGui",
"ImageD11.silxGui",
"ImageD11.nbGui"],
package_dir = {"ImageD11":"ImageD11"},
url = "http://github.com/jonwright/ImageD11",
package_data = {"ImageD11" : ["doc/*.html", "data/*", "sandbox/*.py" ]},
scripts = scripts,
long_description = readme,
long_description_content_type='text/markdown',
)