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