forked from SasView/sasview
-
Notifications
You must be signed in to change notification settings - Fork 0
/
setup.py
executable file
·415 lines (345 loc) · 14.2 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
380
381
382
383
384
385
386
387
388
389
390
391
392
393
394
395
396
397
398
399
400
401
402
403
404
405
406
407
408
409
410
411
412
413
414
415
# -*- coding: utf-8 -*-
#!/usr/bin/env python
"""
Setup for SasView
TODO: Add checks to see that all the dependencies are on the system
"""
from __future__ import print_function
import os
import subprocess
import shutil
import sys
import numpy as np
from setuptools import Extension, setup
from setuptools import Command
from setuptools.command.build_ext import build_ext
try:
import tinycc.distutils
except ImportError:
pass
# Convert "test" argument to "pytest" so 'python setup.py test' works
sys.argv = [("pytest" if s == "test" else s) for s in sys.argv]
# Manage version number ######################################
with open(os.path.join("src", "sas", "sasview", "__init__.py")) as fid:
for line in fid:
if line.startswith('__version__'):
VERSION = line.split('"')[1]
break
else:
raise ValueError("Could not find version in src/sas/sasview/__init__.py")
##############################################################
package_dir = {}
package_data = {}
packages = []
ext_modules = []
# Remove all files that should be updated by this setup
# We do this here because application updates these files from .sasview
# except when there is no such file
# Todo : make this list generic
# plugin_model_list = ['polynominal5.py', 'sph_bessel_jn.py',
# 'sum_Ap1_1_Ap2.py', 'sum_p1_p2.py',
# 'testmodel_2.py', 'testmodel.py',
# 'polynominal5.pyc', 'sph_bessel_jn.pyc',
# 'sum_Ap1_1_Ap2.pyc', 'sum_p1_p2.pyc',
# 'testmodel_2.pyc', 'testmodel.pyc', 'plugins.log']
CURRENT_SCRIPT_DIR = os.path.dirname(os.path.abspath(__file__))
SASVIEW_BUILD = os.path.join(CURRENT_SCRIPT_DIR, "build")
# Optionally clean before build.
dont_clean = 'update' in sys.argv
if dont_clean:
sys.argv.remove('update')
elif os.path.exists(SASVIEW_BUILD):
print("Removing existing build directory", SASVIEW_BUILD, "for a clean build")
shutil.rmtree(SASVIEW_BUILD)
# 'sys.maxsize' and 64bit: Not supported for python2.5
is_64bits = sys.maxsize > 2**32
enable_openmp = False
if sys.platform == 'darwin':
if not is_64bits:
# Disable OpenMP
enable_openmp = False
else:
# Newer versions of Darwin don't support openmp
try:
darwin_ver = int(os.uname()[2].split('.')[0])
if darwin_ver >= 12:
enable_openmp = False
except:
print("PROBLEM determining Darwin version")
# Options to enable OpenMP
copt = {'msvc': ['/openmp'],
'mingw32': ['-fopenmp'],
'unix': ['-fopenmp']}
lopt = {'msvc': ['/MANIFEST'],
'mingw32': ['-fopenmp'],
'unix': ['-lgomp']}
# Platform-specific link options
platform_lopt = {'msvc': ['/MANIFEST']}
platform_copt = {}
# Set copts to get compile working on OS X >= 10.9 using clang
if sys.platform == 'darwin':
try:
darwin_ver = int(os.uname()[2].split('.')[0])
if darwin_ver >= 13 and darwin_ver < 14:
platform_copt = {
'unix': ['-Wno-error=unused-command-line-argument-hard-error-in-future']}
except:
print("PROBLEM determining Darwin version")
class DisableOpenMPCommand(Command):
description = "The version of MinGW that comes with Anaconda does not come with OpenMP :( "\
"This commands means we can turn off compiling with OpenMP for this or any "\
"other reason."
user_options = []
def initialize_options(self):
self.cwd = None
def finalize_options(self):
self.cwd = os.getcwd()
global enable_openmp
enable_openmp = False
def run(self):
pass
class build_ext_subclass(build_ext):
def build_extensions(self):
# Get 64-bitness
c = self.compiler.compiler_type
print("Compiling with %s (64bit=%s)" % (c, str(is_64bits)))
#print("=== compiler attributes ===")
#print("\n".join("%s: %s"%(k, v) for k, v in sorted(self.compiler.__dict__.items())))
#print("=== build_ext attributes ===")
#print("\n".join("%s: %s"%(k, v) for k, v in self.__dict__.items()))
#sys.exit(1)
# OpenMP build options
if enable_openmp:
if c in copt:
for e in self.extensions:
e.extra_compile_args = copt[c]
if c in lopt:
for e in self.extensions:
e.extra_link_args = lopt[c]
# Platform-specific build options
if c in platform_lopt:
for e in self.extensions:
e.extra_link_args = platform_lopt[c]
if c in platform_copt:
for e in self.extensions:
e.extra_compile_args = platform_copt[c]
build_ext.build_extensions(self)
class BuildSphinxCommand(Command):
description = "Build Sphinx documentation."
user_options = []
def initialize_options(self):
self.cwd = None
def finalize_options(self):
self.cwd = os.getcwd()
def run(self):
''' First builds the sasmodels documentation if the directory
is present. Then builds the sasview docs.
'''
### AJJ - Add code for building sasmodels docs here:
# check for doc path
SASMODELS_DOCPATH = os.path.abspath(os.path.join(os.getcwd(), '..', 'sasmodels', 'doc'))
print("========= check for sasmodels at", SASMODELS_DOCPATH, "============")
if os.path.exists(SASMODELS_DOCPATH):
if os.path.isdir(SASMODELS_DOCPATH):
# if available, build sasmodels docs
print("============= Building sasmodels model documentation ===============")
smdocbuild = subprocess.call(["make", "-C", SASMODELS_DOCPATH, "html"])
else:
# if not available warning message
print("== !!WARNING!! sasmodels directory not found. Cannot build model docs. ==")
#Now build sasview (+sasmodels) docs
sys.path.append("docs/sphinx-docs")
import build_sphinx
build_sphinx.rebuild()
# sas module
package_dir["sas"] = os.path.join("src", "sas")
packages.append("sas")
# sas module
package_dir["sas.sasgui"] = os.path.join("src", "sas", "sasgui")
packages.append("sas.sasgui")
# sas module
package_dir["sas.sascalc"] = os.path.join("src", "sas", "sascalc")
packages.append("sas.sascalc")
# sas.sascalc.invariant
package_dir["sas.sascalc.invariant"] = os.path.join(
"src", "sas", "sascalc", "invariant")
packages.extend(["sas.sascalc.invariant"])
# sas.sasgui.guiframe
guiframe_path = os.path.join("src", "sas", "sasgui", "guiframe")
package_dir["sas.sasgui.guiframe"] = guiframe_path
package_dir["sas.sasgui.guiframe.local_perspectives"] = os.path.join(
os.path.join(guiframe_path, "local_perspectives"))
package_data["sas.sasgui.guiframe"] = ['images/*', 'media/*']
packages.extend(
["sas.sasgui.guiframe", "sas.sasgui.guiframe.local_perspectives"])
# build local plugin
for d in os.listdir(os.path.join(guiframe_path, "local_perspectives")):
if d not in ['.svn', '__init__.py', '__init__.pyc']:
package_name = "sas.sasgui.guiframe.local_perspectives." + d
packages.append(package_name)
package_dir[package_name] = os.path.join(
guiframe_path, "local_perspectives", d)
# sas.sascalc.dataloader
package_dir["sas.sascalc.dataloader"] = os.path.join(
"src", "sas", "sascalc", "dataloader")
package_data["sas.sascalc.dataloader.readers"] = ['schema/*.xsd']
packages.extend(["sas.sascalc.dataloader", "sas.sascalc.dataloader.readers",
"sas.sascalc.dataloader.readers.schema"])
# sas.sascalc.calculator
gen_dir = os.path.join("src", "sas", "sascalc", "calculator", "c_extensions")
package_dir["sas.sascalc.calculator"] = os.path.join(
"src", "sas", "sascalc", "calculator")
packages.append("sas.sascalc.calculator")
ext_modules.append(Extension("sas.sascalc.calculator._sld2i",
sources=[
os.path.join(gen_dir, "sld2i_module.c"),
os.path.join(gen_dir, "sld2i.c"),
os.path.join(gen_dir, "libfunc.c"),
os.path.join(gen_dir, "librefl.c"),
],
include_dirs=[gen_dir],
))
# sas.sascalc.pr
package_dir["sas.sascalc.pr"] = os.path.join("src", "sas", "sascalc", "pr")
packages.append("sas.sascalc.pr")
# sas.sascalc.file_converter
package_dir["sas.sascalc.file_converter"] = os.path.join(
"src", "sas", "sascalc", "file_converter")
packages.append("sas.sascalc.file_converter")
# sas.sascalc.corfunc
package_dir["sas.sascalc.corfunc"] = os.path.join(
"src", "sas", "sascalc", "corfunc")
packages.append("sas.sascalc.corfunc")
# sas.sascalc.fit
package_dir["sas.sascalc.fit"] = os.path.join("src", "sas", "sascalc", "fit")
packages.append("sas.sascalc.fit")
# Perspectives
package_dir["sas.sasgui.perspectives"] = os.path.join(
"src", "sas", "sasgui", "perspectives")
package_dir["sas.sasgui.perspectives.pr"] = os.path.join(
"src", "sas", "sasgui", "perspectives", "pr")
packages.extend(["sas.sasgui.perspectives", "sas.sasgui.perspectives.pr"])
package_data["sas.sasgui.perspectives.pr"] = ['media/*']
package_dir["sas.sasgui.perspectives.invariant"] = os.path.join(
"src", "sas", "sasgui", "perspectives", "invariant")
packages.extend(["sas.sasgui.perspectives.invariant"])
package_data['sas.sasgui.perspectives.invariant'] = [
os.path.join("media", '*')]
package_dir["sas.sasgui.perspectives.fitting"] = os.path.join(
"src", "sas", "sasgui", "perspectives", "fitting")
package_dir["sas.sasgui.perspectives.fitting.plugin_models"] = os.path.join(
"src", "sas", "sasgui", "perspectives", "fitting", "plugin_models")
packages.extend(["sas.sasgui.perspectives.fitting",
"sas.sasgui.perspectives.fitting.plugin_models"])
package_data['sas.sasgui.perspectives.fitting'] = [
'media/*', 'plugin_models/*']
packages.extend(["sas.sasgui.perspectives",
"sas.sasgui.perspectives.calculator"])
package_data['sas.sasgui.perspectives.calculator'] = ['images/*', 'media/*']
package_dir["sas.sasgui.perspectives.corfunc"] = os.path.join(
"src", "sas", "sasgui", "perspectives", "corfunc")
packages.extend(["sas.sasgui.perspectives.corfunc"])
package_data['sas.sasgui.perspectives.corfunc'] = ['media/*']
package_dir["sas.sasgui.perspectives.file_converter"] = os.path.join(
"src", "sas", "sasgui", "perspectives", "file_converter")
packages.extend(["sas.sasgui.perspectives.file_converter"])
package_data['sas.sasgui.perspectives.file_converter'] = ['media/*']
# Data util
package_dir["sas.sascalc.data_util"] = os.path.join(
"src", "sas", "sascalc", "data_util")
packages.append("sas.sascalc.data_util")
# Plottools
package_dir["sas.sasgui.plottools"] = os.path.join(
"src", "sas", "sasgui", "plottools")
packages.append("sas.sasgui.plottools")
# # Last of the sas.models
# package_dir["sas.models"] = os.path.join("src", "sas", "models")
# packages.append("sas.models")
EXTENSIONS = [".c", ".cpp"]
def append_file(file_list, dir_path):
"""
Add sources file to sources
"""
for f in os.listdir(dir_path):
if os.path.isfile(os.path.join(dir_path, f)):
_, ext = os.path.splitext(f)
if ext.lower() in EXTENSIONS:
file_list.append(os.path.join(dir_path, f))
elif os.path.isdir(os.path.join(dir_path, f)) and \
not f.startswith("."):
sub_dir = os.path.join(dir_path, f)
for new_f in os.listdir(sub_dir):
if os.path.isfile(os.path.join(sub_dir, new_f)):
_, ext = os.path.splitext(new_f)
if ext.lower() in EXTENSIONS:
file_list.append(os.path.join(sub_dir, new_f))
# Comment out the following to avoid rebuilding all the models
file_sources = []
append_file(file_sources, gen_dir)
# Wojtek's hacky way to add doc files while bundling egg
# def add_doc_files(directory):
# paths = []
# for (path, directories, filenames) in os.walk(directory):
# for filename in filenames:
# paths.append(os.path.join(path, filename))
# return paths
#doc_files = add_doc_files('doc')
# SasView
package_data['sas'] = ['logging.ini']
package_data['sas.sasview'] = ['images/*',
'media/*',
'test/*.txt',
'test/1d_data/*',
'test/2d_data/*',
'test/convertible_files/*',
'test/coordinate_data/*',
'test/image_data/*',
'test/media/*',
'test/other_files/*',
'test/save_states/*',
'test/sesans_data/*',
'test/upcoming_formats/*',
]
packages.append("sas.sasview")
required = [
'bumps>=0.7.5.9', 'periodictable>=1.5.0', 'pyparsing>=2.0.0',
# 'lxml>=2.2.2',
'lxml', 'h5py',
# The following dependecies won't install automatically, so assume them
# The numbers should be bumped up for matplotlib and wxPython as well.
# 'numpy>=1.4.1', 'scipy>=0.7.2', 'matplotlib>=0.99.1.1',
# 'wxPython>=2.8.11', 'pil',
]
if os.name == 'nt':
required.extend(['html5lib', 'reportlab'])
else:
# 'pil' is now called 'pillow'
required.extend(['pillow'])
# Set up SasView
setup(
name="sasview",
version=VERSION,
description="SasView application",
author="SasView Team",
author_email="developers@sasview.org",
url="http://sasview.org",
license="PSF",
keywords="small-angle x-ray and neutron scattering analysis",
download_url="https://github.com/SasView/sasview.git",
package_dir=package_dir,
packages=packages,
package_data=package_data,
ext_modules=ext_modules,
install_requires=required,
zip_safe=False,
entry_points={
'console_scripts': [
"sasview = sas.sasview.sasview:run_gui",
]
},
cmdclass={'build_ext': build_ext_subclass,
'docs': BuildSphinxCommand,
'disable_openmp': DisableOpenMPCommand},
setup_requires=['pytest-runner'] if 'pytest' in sys.argv else [],
tests_require=['pytest'],
)