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 and darwin_ver < 14: |
---|
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 module |
---|
167 | package_dir["sas.sasgui"] = os.path.join("src", "sas", "sasgui") |
---|
168 | packages.append("sas.sasgui") |
---|
169 | |
---|
170 | # sas module |
---|
171 | package_dir["sas.sascalc"] = os.path.join("src", "sas", "sascalc") |
---|
172 | packages.append("sas.sascalc") |
---|
173 | |
---|
174 | # sas.sascalc.invariant |
---|
175 | package_dir["sas.sascalc.invariant"] = os.path.join("src", "sas", "sascalc", "invariant") |
---|
176 | packages.extend(["sas.sascalc.invariant"]) |
---|
177 | |
---|
178 | # sas.sasgui.guiframe |
---|
179 | guiframe_path = os.path.join("src", "sas", "sasgui", "guiframe") |
---|
180 | package_dir["sas.sasgui.guiframe"] = guiframe_path |
---|
181 | package_dir["sas.sasgui.guiframe.local_perspectives"] = os.path.join(os.path.join(guiframe_path, "local_perspectives")) |
---|
182 | package_data["sas.sasgui.guiframe"] = ['images/*', 'media/*'] |
---|
183 | packages.extend(["sas.sasgui.guiframe", "sas.sasgui.guiframe.local_perspectives"]) |
---|
184 | # build local plugin |
---|
185 | for d in os.listdir(os.path.join(guiframe_path, "local_perspectives")): |
---|
186 | if d not in ['.svn','__init__.py', '__init__.pyc']: |
---|
187 | package_name = "sas.sasgui.guiframe.local_perspectives." + d |
---|
188 | packages.append(package_name) |
---|
189 | package_dir[package_name] = os.path.join(guiframe_path, "local_perspectives", d) |
---|
190 | |
---|
191 | # sas.sascalc.dataloader |
---|
192 | package_dir["sas.sascalc.dataloader"] = os.path.join("src", "sas", "sascalc", "dataloader") |
---|
193 | package_data["sas.sascalc.dataloader.readers"] = ['defaults.json','schema/*.xsd'] |
---|
194 | packages.extend(["sas.sascalc.dataloader","sas.sascalc.dataloader.readers","sas.sascalc.dataloader.readers.schema"]) |
---|
195 | |
---|
196 | # sas.sascalc.calculator |
---|
197 | numpy_incl_path = os.path.join(NUMPY_INC, "numpy") |
---|
198 | gen_dir = os.path.join("src", "sas", "sascalc", "calculator", "c_extensions") |
---|
199 | package_dir["sas.sascalc.calculator.core"] = gen_dir |
---|
200 | package_dir["sas.sascalc.calculator"] = os.path.join("src", "sas", "sascalc", "calculator") |
---|
201 | packages.extend(["sas.sascalc.calculator","sas.sascalc.calculator.core"]) |
---|
202 | ext_modules.append( Extension("sas.sascalc.calculator.core.sld2i", |
---|
203 | sources = [ |
---|
204 | os.path.join(gen_dir, "sld2i_module.cpp"), |
---|
205 | os.path.join(gen_dir, "sld2i.cpp"), |
---|
206 | os.path.join(gen_dir, "libfunc.c"), |
---|
207 | os.path.join(gen_dir, "librefl.c"), |
---|
208 | os.path.join(gen_dir, "winFuncs.c"), |
---|
209 | ], |
---|
210 | include_dirs=[numpy_incl_path, gen_dir], |
---|
211 | ) |
---|
212 | ) |
---|
213 | |
---|
214 | |
---|
215 | # sas.sascalc.pr |
---|
216 | srcdir = os.path.join("src", "sas", "sascalc", "pr", "c_extensions") |
---|
217 | package_dir["sas.sascalc.pr.core"] = srcdir |
---|
218 | package_dir["sas.sascalc.pr"] = os.path.join("src","sas", "sascalc", "pr") |
---|
219 | packages.extend(["sas.sascalc.pr","sas.sascalc.pr.core"]) |
---|
220 | ext_modules.append( Extension("sas.sascalc.pr.core.pr_inversion", |
---|
221 | sources = [os.path.join(srcdir, "Cinvertor.c"), |
---|
222 | os.path.join(srcdir, "invertor.c"), |
---|
223 | ], |
---|
224 | include_dirs=[numpy_incl_path], |
---|
225 | ) ) |
---|
226 | |
---|
227 | # sas.sascalc.fit |
---|
228 | package_dir["sas.sascalc.fit"] = os.path.join("src", "sas", "sascalc", "fit") |
---|
229 | packages.append("sas.sascalc.fit") |
---|
230 | |
---|
231 | # Perspectives |
---|
232 | package_dir["sas.sasgui.perspectives"] = os.path.join("src", "sas", "sasgui", "perspectives") |
---|
233 | package_dir["sas.sasgui.perspectives.pr"] = os.path.join("src", "sas", "sasgui", "perspectives", "pr") |
---|
234 | packages.extend(["sas.sasgui.perspectives","sas.sasgui.perspectives.pr"]) |
---|
235 | package_data["sas.sasgui.perspectives.pr"] = ['images/*'] |
---|
236 | |
---|
237 | package_dir["sas.sasgui.perspectives.invariant"] = os.path.join("src", "sas", "sasgui", "perspectives", "invariant") |
---|
238 | packages.extend(["sas.sasgui.perspectives.invariant"]) |
---|
239 | package_data['sas.sasgui.perspectives.invariant'] = [os.path.join("media",'*')] |
---|
240 | |
---|
241 | package_dir["sas.sasgui.perspectives.fitting"] = os.path.join("src", "sas", "sasgui", "perspectives", "fitting") |
---|
242 | packages.extend(["sas.sasgui.perspectives.fitting"]) |
---|
243 | package_data['sas.sasgui.perspectives.fitting'] = ['media/*'] |
---|
244 | |
---|
245 | packages.extend(["sas.sasgui.perspectives", "sas.sasgui.perspectives.calculator"]) |
---|
246 | package_data['sas.sasgui.perspectives.calculator'] = ['images/*', 'media/*'] |
---|
247 | |
---|
248 | # Data util |
---|
249 | package_dir["sas.sascalc.data_util"] = os.path.join("src", "sas", "sascalc", "data_util") |
---|
250 | packages.append("sas.sascalc.data_util") |
---|
251 | |
---|
252 | # Plottools |
---|
253 | package_dir["sas.sasgui.plottools"] = os.path.join("src", "sas", "sasgui", "plottools") |
---|
254 | packages.append("sas.sasgui.plottools") |
---|
255 | |
---|
256 | |
---|
257 | IGNORED_FILES = [".svn"] |
---|
258 | if not os.name=='nt': |
---|
259 | IGNORED_FILES.extend(["gamma_win.c","winFuncs.c"]) |
---|
260 | |
---|
261 | EXTENSIONS = [".c", ".cpp"] |
---|
262 | |
---|
263 | def append_file(file_list, dir_path): |
---|
264 | """ |
---|
265 | Add sources file to sources |
---|
266 | """ |
---|
267 | for f in os.listdir(dir_path): |
---|
268 | if os.path.isfile(os.path.join(dir_path, f)): |
---|
269 | _, ext = os.path.splitext(f) |
---|
270 | if ext.lower() in EXTENSIONS and f not in IGNORED_FILES: |
---|
271 | file_list.append(os.path.join(dir_path, f)) |
---|
272 | elif os.path.isdir(os.path.join(dir_path, f)) and \ |
---|
273 | not f.startswith("."): |
---|
274 | sub_dir = os.path.join(dir_path, f) |
---|
275 | for new_f in os.listdir(sub_dir): |
---|
276 | if os.path.isfile(os.path.join(sub_dir, new_f)): |
---|
277 | _, ext = os.path.splitext(new_f) |
---|
278 | if ext.lower() in EXTENSIONS and\ |
---|
279 | new_f not in IGNORED_FILES: |
---|
280 | file_list.append(os.path.join(sub_dir, new_f)) |
---|
281 | |
---|
282 | # Comment out the following to avoid rebuilding all the models |
---|
283 | file_sources = [] |
---|
284 | append_file(file_sources, gen_dir) |
---|
285 | |
---|
286 | # SasView |
---|
287 | package_dir["sas.sasview"] = "sasview" |
---|
288 | package_data['sas.sasview'] = ['images/*', |
---|
289 | 'media/*', |
---|
290 | 'test/*.txt', |
---|
291 | 'test/1d_data/*', |
---|
292 | 'test/2d_data/*', |
---|
293 | 'test/save_states/*', |
---|
294 | 'test/upcoming_formats/*', |
---|
295 | 'default_categories.json'] |
---|
296 | packages.append("sas.sasview") |
---|
297 | |
---|
298 | required = [ |
---|
299 | 'bumps>=0.7.5.6', 'periodictable>=1.3.1', 'pyparsing<2.0.0', |
---|
300 | |
---|
301 | # 'lxml>=2.2.2', |
---|
302 | 'lxml', |
---|
303 | |
---|
304 | ## The following dependecies won't install automatically, so assume them |
---|
305 | ## The numbers should be bumped up for matplotlib and wxPython as well. |
---|
306 | # 'numpy>=1.4.1', 'scipy>=0.7.2', 'matplotlib>=0.99.1.1', |
---|
307 | # 'wxPython>=2.8.11', 'pil', |
---|
308 | ] |
---|
309 | |
---|
310 | if os.name=='nt': |
---|
311 | required.extend(['html5lib', 'reportlab']) |
---|
312 | else: |
---|
313 | required.extend(['pil']) |
---|
314 | |
---|
315 | # Set up SasView |
---|
316 | setup( |
---|
317 | name="sasview", |
---|
318 | version = VERSION, |
---|
319 | description = "SasView application", |
---|
320 | author = "SasView Team", |
---|
321 | author_email = "developers@sasview.org", |
---|
322 | url = "http://sasview.org", |
---|
323 | license = "PSF", |
---|
324 | keywords = "small-angle x-ray and neutron scattering analysis", |
---|
325 | download_url = "https://github.com/SasView/sasview.git", |
---|
326 | package_dir = package_dir, |
---|
327 | packages = packages, |
---|
328 | package_data = package_data, |
---|
329 | ext_modules = ext_modules, |
---|
330 | install_requires = required, |
---|
331 | zip_safe = False, |
---|
332 | entry_points = { |
---|
333 | 'console_scripts':[ |
---|
334 | "sasview = sas.sasview.sasview:run", |
---|
335 | ] |
---|
336 | }, |
---|
337 | cmdclass = {'build_ext': build_ext_subclass, |
---|
338 | 'docs': BuildSphinxCommand, |
---|
339 | 'disable_openmp': DisableOpenMPCommand} |
---|
340 | ) |
---|