1 | # -*- coding: utf-8 -*- |
---|
2 | #!/usr/bin/env python |
---|
3 | |
---|
4 | """ |
---|
5 | Setup for SasView |
---|
6 | TODO: Add checks to see that all the dependencies are on the system |
---|
7 | """ |
---|
8 | |
---|
9 | import os |
---|
10 | import shutil |
---|
11 | import sys |
---|
12 | from distutils.command.build_ext import build_ext |
---|
13 | from distutils.core import Command |
---|
14 | |
---|
15 | import numpy as np |
---|
16 | from setuptools import Extension, setup |
---|
17 | |
---|
18 | # Manage version number ###################################### |
---|
19 | import sasview |
---|
20 | |
---|
21 | VERSION = sasview.__version__ |
---|
22 | ############################################################## |
---|
23 | |
---|
24 | package_dir = {} |
---|
25 | package_data = {} |
---|
26 | packages = [] |
---|
27 | ext_modules = [] |
---|
28 | |
---|
29 | # Remove all files that should be updated by this setup |
---|
30 | # We do this here because application updates these files from .sasview |
---|
31 | # except when there is no such file |
---|
32 | # Todo : make this list generic |
---|
33 | # plugin_model_list = ['polynominal5.py', 'sph_bessel_jn.py', |
---|
34 | # 'sum_Ap1_1_Ap2.py', 'sum_p1_p2.py', |
---|
35 | # 'testmodel_2.py', 'testmodel.py', |
---|
36 | # 'polynominal5.pyc', 'sph_bessel_jn.pyc', |
---|
37 | # 'sum_Ap1_1_Ap2.pyc', 'sum_p1_p2.pyc', |
---|
38 | # 'testmodel_2.pyc', 'testmodel.pyc', 'plugins.log'] |
---|
39 | |
---|
40 | CURRENT_SCRIPT_DIR = os.path.dirname(os.path.abspath(__file__)) |
---|
41 | SASVIEW_BUILD = os.path.join(CURRENT_SCRIPT_DIR, "build") |
---|
42 | |
---|
43 | sas_dir = os.path.join(os.path.expanduser("~"), '.sasview') |
---|
44 | if os.path.isdir(sas_dir): |
---|
45 | f_path = os.path.join(sas_dir, "sasview.log") |
---|
46 | if os.path.isfile(f_path): |
---|
47 | os.remove(f_path) |
---|
48 | f_path = os.path.join(sas_dir, "categories.json") |
---|
49 | if os.path.isfile(f_path): |
---|
50 | os.remove(f_path) |
---|
51 | f_path = os.path.join(sas_dir, 'config', "custom_config.py") |
---|
52 | if os.path.isfile(f_path): |
---|
53 | os.remove(f_path) |
---|
54 | #f_path = os.path.join(sas_dir, 'plugin_models') |
---|
55 | # if os.path.isdir(f_path): |
---|
56 | # for f in os.listdir(f_path): |
---|
57 | # if f in plugin_model_list: |
---|
58 | # file_path = os.path.join(f_path, f) |
---|
59 | # os.remove(file_path) |
---|
60 | if os.path.exists(SASVIEW_BUILD): |
---|
61 | print("Removing existing build directory", |
---|
62 | SASVIEW_BUILD, "for a clean build") |
---|
63 | shutil.rmtree(SASVIEW_BUILD) |
---|
64 | |
---|
65 | # 'sys.maxsize' and 64bit: Not supported for python2.5 |
---|
66 | is_64bits = False |
---|
67 | if sys.version_info >= (2, 6): |
---|
68 | is_64bits = sys.maxsize > 2**32 |
---|
69 | |
---|
70 | enable_openmp = False |
---|
71 | |
---|
72 | if sys.platform == 'darwin': |
---|
73 | if not is_64bits: |
---|
74 | # Disable OpenMP |
---|
75 | enable_openmp = False |
---|
76 | else: |
---|
77 | # Newer versions of Darwin don't support openmp |
---|
78 | try: |
---|
79 | darwin_ver = int(os.uname()[2].split('.')[0]) |
---|
80 | if darwin_ver >= 12: |
---|
81 | enable_openmp = False |
---|
82 | except: |
---|
83 | print("PROBLEM determining Darwin version") |
---|
84 | |
---|
85 | # Options to enable OpenMP |
---|
86 | copt = {'msvc': ['/openmp'], |
---|
87 | 'mingw32': ['-fopenmp'], |
---|
88 | 'unix': ['-fopenmp']} |
---|
89 | lopt = {'msvc': ['/MANIFEST'], |
---|
90 | 'mingw32': ['-fopenmp'], |
---|
91 | 'unix': ['-lgomp']} |
---|
92 | |
---|
93 | # Platform-specific link options |
---|
94 | platform_lopt = {'msvc': ['/MANIFEST']} |
---|
95 | platform_copt = {} |
---|
96 | |
---|
97 | # Set copts to get compile working on OS X >= 10.9 using clang |
---|
98 | if sys.platform == 'darwin': |
---|
99 | try: |
---|
100 | darwin_ver = int(os.uname()[2].split('.')[0]) |
---|
101 | if darwin_ver >= 13 and darwin_ver < 14: |
---|
102 | platform_copt = { |
---|
103 | 'unix': ['-Wno-error=unused-command-line-argument-hard-error-in-future']} |
---|
104 | except: |
---|
105 | print("PROBLEM determining Darwin version") |
---|
106 | |
---|
107 | |
---|
108 | class DisableOpenMPCommand(Command): |
---|
109 | description = "The version of MinGW that comes with Anaconda does not come with OpenMP :( "\ |
---|
110 | "This commands means we can turn off compiling with OpenMP for this or any "\ |
---|
111 | "other reason." |
---|
112 | user_options = [] |
---|
113 | |
---|
114 | def initialize_options(self): |
---|
115 | self.cwd = None |
---|
116 | |
---|
117 | def finalize_options(self): |
---|
118 | self.cwd = os.getcwd() |
---|
119 | global enable_openmp |
---|
120 | enable_openmp = False |
---|
121 | |
---|
122 | def run(self): |
---|
123 | pass |
---|
124 | |
---|
125 | |
---|
126 | class build_ext_subclass(build_ext): |
---|
127 | def build_extensions(self): |
---|
128 | # Get 64-bitness |
---|
129 | c = self.compiler.compiler_type |
---|
130 | print("Compiling with %s (64bit=%s)" % (c, str(is_64bits))) |
---|
131 | |
---|
132 | # OpenMP build options |
---|
133 | if enable_openmp: |
---|
134 | if c in copt: |
---|
135 | for e in self.extensions: |
---|
136 | e.extra_compile_args = copt[c] |
---|
137 | if c in lopt: |
---|
138 | for e in self.extensions: |
---|
139 | e.extra_link_args = lopt[c] |
---|
140 | |
---|
141 | # Platform-specific build options |
---|
142 | if c in platform_lopt: |
---|
143 | for e in self.extensions: |
---|
144 | e.extra_link_args = platform_lopt[c] |
---|
145 | |
---|
146 | if c in platform_copt: |
---|
147 | for e in self.extensions: |
---|
148 | e.extra_compile_args = platform_copt[c] |
---|
149 | |
---|
150 | build_ext.build_extensions(self) |
---|
151 | |
---|
152 | |
---|
153 | class BuildSphinxCommand(Command): |
---|
154 | description = "Build Sphinx documentation." |
---|
155 | user_options = [] |
---|
156 | |
---|
157 | def initialize_options(self): |
---|
158 | self.cwd = None |
---|
159 | |
---|
160 | def finalize_options(self): |
---|
161 | self.cwd = os.getcwd() |
---|
162 | |
---|
163 | def run(self): |
---|
164 | sys.path.append("docs/sphinx-docs") |
---|
165 | import build_sphinx |
---|
166 | build_sphinx.rebuild() |
---|
167 | |
---|
168 | |
---|
169 | # sas module |
---|
170 | package_dir["sas"] = os.path.join("src", "sas") |
---|
171 | packages.append("sas") |
---|
172 | |
---|
173 | # sas module |
---|
174 | package_dir["sas.sasgui"] = os.path.join("src", "sas", "sasgui") |
---|
175 | packages.append("sas.sasgui") |
---|
176 | |
---|
177 | # sas module |
---|
178 | package_dir["sas.sascalc"] = os.path.join("src", "sas", "sascalc") |
---|
179 | packages.append("sas.sascalc") |
---|
180 | |
---|
181 | # sas.sascalc.invariant |
---|
182 | package_dir["sas.sascalc.invariant"] = os.path.join( |
---|
183 | "src", "sas", "sascalc", "invariant") |
---|
184 | packages.extend(["sas.sascalc.invariant"]) |
---|
185 | |
---|
186 | # sas.sasgui.guiframe |
---|
187 | guiframe_path = os.path.join("src", "sas", "sasgui", "guiframe") |
---|
188 | package_dir["sas.sasgui.guiframe"] = guiframe_path |
---|
189 | package_dir["sas.sasgui.guiframe.local_perspectives"] = os.path.join( |
---|
190 | os.path.join(guiframe_path, "local_perspectives")) |
---|
191 | package_data["sas.sasgui.guiframe"] = ['images/*', 'media/*'] |
---|
192 | packages.extend( |
---|
193 | ["sas.sasgui.guiframe", "sas.sasgui.guiframe.local_perspectives"]) |
---|
194 | # build local plugin |
---|
195 | for d in os.listdir(os.path.join(guiframe_path, "local_perspectives")): |
---|
196 | if d not in ['.svn', '__init__.py', '__init__.pyc']: |
---|
197 | package_name = "sas.sasgui.guiframe.local_perspectives." + d |
---|
198 | packages.append(package_name) |
---|
199 | package_dir[package_name] = os.path.join( |
---|
200 | guiframe_path, "local_perspectives", d) |
---|
201 | |
---|
202 | # sas.sascalc.dataloader |
---|
203 | package_dir["sas.sascalc.dataloader"] = os.path.join( |
---|
204 | "src", "sas", "sascalc", "dataloader") |
---|
205 | package_data["sas.sascalc.dataloader.readers"] = [ |
---|
206 | 'defaults.json', 'schema/*.xsd'] |
---|
207 | packages.extend(["sas.sascalc.dataloader", "sas.sascalc.dataloader.readers", |
---|
208 | "sas.sascalc.dataloader.readers.schema"]) |
---|
209 | |
---|
210 | # sas.sascalc.calculator |
---|
211 | gen_dir = os.path.join("src", "sas", "sascalc", "calculator", "c_extensions") |
---|
212 | package_dir["sas.sascalc.calculator.core"] = gen_dir |
---|
213 | package_dir["sas.sascalc.calculator"] = os.path.join( |
---|
214 | "src", "sas", "sascalc", "calculator") |
---|
215 | packages.extend(["sas.sascalc.calculator", "sas.sascalc.calculator.core"]) |
---|
216 | ext_modules.append(Extension("sas.sascalc.calculator.core.sld2i", |
---|
217 | sources=[ |
---|
218 | os.path.join(gen_dir, "sld2i_module.cpp"), |
---|
219 | os.path.join(gen_dir, "sld2i.cpp"), |
---|
220 | os.path.join(gen_dir, "libfunc.c"), |
---|
221 | os.path.join(gen_dir, "librefl.c"), |
---|
222 | ], |
---|
223 | include_dirs=[gen_dir], |
---|
224 | ) |
---|
225 | ) |
---|
226 | |
---|
227 | # sas.sascalc.pr |
---|
228 | srcdir = os.path.join("src", "sas", "sascalc", "pr", "c_extensions") |
---|
229 | package_dir["sas.sascalc.pr.core"] = srcdir |
---|
230 | package_dir["sas.sascalc.pr"] = os.path.join("src", "sas", "sascalc", "pr") |
---|
231 | packages.extend(["sas.sascalc.pr", "sas.sascalc.pr.core"]) |
---|
232 | ext_modules.append(Extension("sas.sascalc.pr.core.pr_inversion", |
---|
233 | sources=[os.path.join(srcdir, "Cinvertor.c"), |
---|
234 | os.path.join(srcdir, "invertor.c"), |
---|
235 | ], |
---|
236 | include_dirs=[], |
---|
237 | )) |
---|
238 | |
---|
239 | # sas.sascalc.file_converter |
---|
240 | mydir = os.path.join("src", "sas", "sascalc", "file_converter", "c_ext") |
---|
241 | package_dir["sas.sascalc.file_converter.core"] = mydir |
---|
242 | package_dir["sas.sascalc.file_converter"] = os.path.join( |
---|
243 | "src", "sas", "sascalc", "file_converter") |
---|
244 | packages.extend(["sas.sascalc.file_converter", |
---|
245 | "sas.sascalc.file_converter.core"]) |
---|
246 | ext_modules.append(Extension("sas.sascalc.file_converter.core.bsl_loader", |
---|
247 | sources=[os.path.join(mydir, "bsl_loader.c")], |
---|
248 | include_dirs=[np.get_include()], |
---|
249 | )) |
---|
250 | |
---|
251 | # sas.sascalc.corfunc |
---|
252 | package_dir["sas.sascalc.corfunc"] = os.path.join( |
---|
253 | "src", "sas", "sascalc", "corfunc") |
---|
254 | packages.extend(["sas.sascalc.corfunc"]) |
---|
255 | |
---|
256 | # sas.sascalc.fit |
---|
257 | package_dir["sas.sascalc.fit"] = os.path.join("src", "sas", "sascalc", "fit") |
---|
258 | packages.append("sas.sascalc.fit") |
---|
259 | |
---|
260 | # Perspectives |
---|
261 | package_dir["sas.sasgui.perspectives"] = os.path.join( |
---|
262 | "src", "sas", "sasgui", "perspectives") |
---|
263 | package_dir["sas.sasgui.perspectives.pr"] = os.path.join( |
---|
264 | "src", "sas", "sasgui", "perspectives", "pr") |
---|
265 | packages.extend(["sas.sasgui.perspectives", "sas.sasgui.perspectives.pr"]) |
---|
266 | package_data["sas.sasgui.perspectives.pr"] = ['media/*'] |
---|
267 | |
---|
268 | package_dir["sas.sasgui.perspectives.invariant"] = os.path.join( |
---|
269 | "src", "sas", "sasgui", "perspectives", "invariant") |
---|
270 | packages.extend(["sas.sasgui.perspectives.invariant"]) |
---|
271 | package_data['sas.sasgui.perspectives.invariant'] = [ |
---|
272 | os.path.join("media", '*')] |
---|
273 | |
---|
274 | package_dir["sas.sasgui.perspectives.fitting"] = os.path.join( |
---|
275 | "src", "sas", "sasgui", "perspectives", "fitting") |
---|
276 | package_dir["sas.sasgui.perspectives.fitting.plugin_models"] = os.path.join( |
---|
277 | "src", "sas", "sasgui", "perspectives", "fitting", "plugin_models") |
---|
278 | packages.extend(["sas.sasgui.perspectives.fitting", |
---|
279 | "sas.sasgui.perspectives.fitting.plugin_models"]) |
---|
280 | package_data['sas.sasgui.perspectives.fitting'] = [ |
---|
281 | 'media/*', 'plugin_models/*'] |
---|
282 | |
---|
283 | packages.extend(["sas.sasgui.perspectives", |
---|
284 | "sas.sasgui.perspectives.calculator"]) |
---|
285 | package_data['sas.sasgui.perspectives.calculator'] = ['images/*', 'media/*'] |
---|
286 | |
---|
287 | package_dir["sas.sasgui.perspectives.corfunc"] = os.path.join( |
---|
288 | "src", "sas", "sasgui", "perspectives", "corfunc") |
---|
289 | packages.extend(["sas.sasgui.perspectives.corfunc"]) |
---|
290 | package_data['sas.sasgui.perspectives.corfunc'] = ['media/*'] |
---|
291 | |
---|
292 | package_dir["sas.sasgui.perspectives.file_converter"] = os.path.join( |
---|
293 | "src", "sas", "sasgui", "perspectives", "file_converter") |
---|
294 | packages.extend(["sas.sasgui.perspectives.file_converter"]) |
---|
295 | package_data['sas.sasgui.perspectives.file_converter'] = ['media/*'] |
---|
296 | |
---|
297 | # Data util |
---|
298 | package_dir["sas.sascalc.data_util"] = os.path.join( |
---|
299 | "src", "sas", "sascalc", "data_util") |
---|
300 | packages.append("sas.sascalc.data_util") |
---|
301 | |
---|
302 | # Plottools |
---|
303 | package_dir["sas.sasgui.plottools"] = os.path.join( |
---|
304 | "src", "sas", "sasgui", "plottools") |
---|
305 | packages.append("sas.sasgui.plottools") |
---|
306 | |
---|
307 | # # Last of the sas.models |
---|
308 | # package_dir["sas.models"] = os.path.join("src", "sas", "models") |
---|
309 | # packages.append("sas.models") |
---|
310 | |
---|
311 | EXTENSIONS = [".c", ".cpp"] |
---|
312 | |
---|
313 | |
---|
314 | def append_file(file_list, dir_path): |
---|
315 | """ |
---|
316 | Add sources file to sources |
---|
317 | """ |
---|
318 | for f in os.listdir(dir_path): |
---|
319 | if os.path.isfile(os.path.join(dir_path, f)): |
---|
320 | _, ext = os.path.splitext(f) |
---|
321 | if ext.lower() in EXTENSIONS: |
---|
322 | file_list.append(os.path.join(dir_path, f)) |
---|
323 | elif os.path.isdir(os.path.join(dir_path, f)) and \ |
---|
324 | not f.startswith("."): |
---|
325 | sub_dir = os.path.join(dir_path, f) |
---|
326 | for new_f in os.listdir(sub_dir): |
---|
327 | if os.path.isfile(os.path.join(sub_dir, new_f)): |
---|
328 | _, ext = os.path.splitext(new_f) |
---|
329 | if ext.lower() in EXTENSIONS: |
---|
330 | file_list.append(os.path.join(sub_dir, new_f)) |
---|
331 | |
---|
332 | |
---|
333 | # Comment out the following to avoid rebuilding all the models |
---|
334 | file_sources = [] |
---|
335 | append_file(file_sources, gen_dir) |
---|
336 | |
---|
337 | # Wojtek's hacky way to add doc files while bundling egg |
---|
338 | # def add_doc_files(directory): |
---|
339 | # paths = [] |
---|
340 | # for (path, directories, filenames) in os.walk(directory): |
---|
341 | # for filename in filenames: |
---|
342 | # paths.append(os.path.join(path, filename)) |
---|
343 | # return paths |
---|
344 | |
---|
345 | #doc_files = add_doc_files('doc') |
---|
346 | |
---|
347 | # SasView |
---|
348 | package_dir["sas.sasview"] = "sasview" |
---|
349 | package_data['sas.sasview'] = ['images/*', |
---|
350 | 'media/*', |
---|
351 | 'logging.ini', |
---|
352 | 'test/*.txt', |
---|
353 | 'test/1d_data/*', |
---|
354 | 'test/2d_data/*', |
---|
355 | 'test/convertible_files/*', |
---|
356 | 'test/coordinate_data/*', |
---|
357 | 'test/image_data/*', |
---|
358 | 'test/media/*', |
---|
359 | 'test/other_files/*', |
---|
360 | 'test/save_states/*', |
---|
361 | 'test/sesans_data/*' |
---|
362 | ] |
---|
363 | packages.append("sas.sasview") |
---|
364 | |
---|
365 | required = [ |
---|
366 | 'bumps>=0.7.5.9', 'periodictable>=1.3.1', 'pyparsing<2.0.0', |
---|
367 | |
---|
368 | # 'lxml>=2.2.2', |
---|
369 | 'lxml', 'h5py', |
---|
370 | |
---|
371 | # The following dependecies won't install automatically, so assume them |
---|
372 | # The numbers should be bumped up for matplotlib and wxPython as well. |
---|
373 | # 'numpy>=1.4.1', 'scipy>=0.7.2', 'matplotlib>=0.99.1.1', |
---|
374 | # 'wxPython>=2.8.11', 'pil', |
---|
375 | ] |
---|
376 | |
---|
377 | if os.name == 'nt': |
---|
378 | required.extend(['html5lib', 'reportlab']) |
---|
379 | else: |
---|
380 | # 'pil' is now called 'pillow' |
---|
381 | required.extend(['pillow']) |
---|
382 | |
---|
383 | # Set up SasView |
---|
384 | setup( |
---|
385 | name="sasview", |
---|
386 | version=VERSION, |
---|
387 | description="SasView application", |
---|
388 | author="SasView Team", |
---|
389 | author_email="developers@sasview.org", |
---|
390 | url="http://sasview.org", |
---|
391 | license="PSF", |
---|
392 | keywords="small-angle x-ray and neutron scattering analysis", |
---|
393 | download_url="https://github.com/SasView/sasview.git", |
---|
394 | package_dir=package_dir, |
---|
395 | packages=packages, |
---|
396 | package_data=package_data, |
---|
397 | ext_modules=ext_modules, |
---|
398 | install_requires=required, |
---|
399 | zip_safe=False, |
---|
400 | entry_points={ |
---|
401 | 'console_scripts': [ |
---|
402 | "sasview = sas.sasview.sasview:run", |
---|
403 | ] |
---|
404 | }, |
---|
405 | cmdclass={'build_ext': build_ext_subclass, |
---|
406 | 'docs': BuildSphinxCommand, |
---|
407 | 'disable_openmp': DisableOpenMPCommand} |
---|
408 | ) |
---|