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 | |
---|
10 | try: |
---|
11 | from numpy.distutils.misc_util import get_numpy_include_dirs |
---|
12 | NUMPY_INC = get_numpy_include_dirs()[0] |
---|
13 | except: |
---|
14 | try: |
---|
15 | import numpy |
---|
16 | NUMPY_INC = os.path.join(os.path.split(numpy.__file__)[0], |
---|
17 | "core","include") |
---|
18 | except: |
---|
19 | msg = "\nNumpy is needed to build SasView. " |
---|
20 | print msg, "Try easy_install numpy.\n %s" % str(sys.exc_value) |
---|
21 | sys.exit(0) |
---|
22 | |
---|
23 | # Manage version number ###################################### |
---|
24 | import sansview |
---|
25 | VERSION = sansview.__version__ |
---|
26 | ############################################################## |
---|
27 | |
---|
28 | package_dir = {} |
---|
29 | package_data = {} |
---|
30 | packages = [] |
---|
31 | ext_modules = [] |
---|
32 | |
---|
33 | # Remove all files that should be updated by this setup |
---|
34 | # We do this here because application updates these files from .sansview |
---|
35 | # except when there is no such file |
---|
36 | # Todo : make this list generic |
---|
37 | plugin_model_list = ['polynominal5.py', 'sph_bessel_jn.py', |
---|
38 | 'sum_Ap1_1_Ap2.py', 'sum_p1_p2.py', |
---|
39 | 'testmodel_2.py', 'testmodel.py', |
---|
40 | 'polynominal5.pyc', 'sph_bessel_jn.pyc', |
---|
41 | 'sum_Ap1_1_Ap2.pyc', 'sum_p1_p2.pyc', |
---|
42 | 'testmodel_2.pyc', 'testmodel.pyc', 'plugins.log'] |
---|
43 | sans_dir = os.path.join(os.path.expanduser("~"),'.sasview') |
---|
44 | if os.path.isdir(sans_dir): |
---|
45 | f_path = os.path.join(sans_dir, "sasview.log") |
---|
46 | if os.path.isfile(f_path): |
---|
47 | os.remove(f_path) |
---|
48 | f_path = os.path.join(sans_dir, "serialized_cat.json") |
---|
49 | if os.path.isfile(f_path): |
---|
50 | os.remove(f_path) |
---|
51 | f_path = os.path.join(sans_dir, 'config', "custom_config.py") |
---|
52 | if os.path.isfile(f_path): |
---|
53 | os.remove(f_path) |
---|
54 | f_path = os.path.join(sans_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 | |
---|
61 | # 'sys.maxsize' and 64bit: Not supported for python2.5 |
---|
62 | is_64bits = False |
---|
63 | if sys.version_info >= (2, 6): |
---|
64 | is_64bits = sys.maxsize > 2**32 |
---|
65 | |
---|
66 | |
---|
67 | enable_openmp = True |
---|
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 | |
---|
104 | |
---|
105 | class build_ext_subclass( build_ext ): |
---|
106 | def build_extensions(self): |
---|
107 | # Get 64-bitness |
---|
108 | c = self.compiler.compiler_type |
---|
109 | print "Compiling with %s (64bit=%s)" % (c, str(is_64bits)) |
---|
110 | |
---|
111 | # OpenMP build options |
---|
112 | if enable_openmp: |
---|
113 | if copt.has_key(c): |
---|
114 | for e in self.extensions: |
---|
115 | e.extra_compile_args = copt[ c ] |
---|
116 | if lopt.has_key(c): |
---|
117 | for e in self.extensions: |
---|
118 | e.extra_link_args = lopt[ c ] |
---|
119 | |
---|
120 | # Platform-specific build options |
---|
121 | if platform_lopt.has_key(c): |
---|
122 | for e in self.extensions: |
---|
123 | e.extra_link_args = platform_lopt[ c ] |
---|
124 | |
---|
125 | if platform_copt.has_key(c): |
---|
126 | for e in self.extensions: |
---|
127 | e.extra_compile_args = platform_copt[ c ] |
---|
128 | |
---|
129 | |
---|
130 | build_ext.build_extensions(self) |
---|
131 | |
---|
132 | # sans module |
---|
133 | package_dir["sans"] = os.path.join("src", "sans") |
---|
134 | packages.append("sans") |
---|
135 | |
---|
136 | # sans.invariant |
---|
137 | package_dir["sans.invariant"] = os.path.join("src", "sans", "invariant") |
---|
138 | packages.extend(["sans.invariant"]) |
---|
139 | |
---|
140 | # sans.guiframe |
---|
141 | guiframe_path = os.path.join("src", "sans", "guiframe") |
---|
142 | package_dir["sans.guiframe"] = guiframe_path |
---|
143 | package_dir["sans.guiframe.local_perspectives"] = os.path.join(os.path.join(guiframe_path, "local_perspectives")) |
---|
144 | package_data["sans.guiframe"] = ['images/*', 'media/*'] |
---|
145 | packages.extend(["sans.guiframe", "sans.guiframe.local_perspectives"]) |
---|
146 | # build local plugin |
---|
147 | for d in os.listdir(os.path.join(guiframe_path, "local_perspectives")): |
---|
148 | if d not in ['.svn','__init__.py', '__init__.pyc']: |
---|
149 | package_name = "sans.guiframe.local_perspectives." + d |
---|
150 | packages.append(package_name) |
---|
151 | package_dir[package_name] = os.path.join(guiframe_path, "local_perspectives", d) |
---|
152 | |
---|
153 | # sans.dataloader |
---|
154 | package_dir["sans.dataloader"] = os.path.join("src", "sans", "dataloader") |
---|
155 | package_data["sans.dataloader.readers"] = ['defaults.xml','schema/*.xsd'] |
---|
156 | packages.extend(["sans.dataloader","sans.dataloader.readers","sans.dataloader.readers.schema"]) |
---|
157 | |
---|
158 | # sans.calculator |
---|
159 | package_dir["sans.calculator"] =os.path.join("src", "sans", "calculator") |
---|
160 | packages.extend(["sans.calculator"]) |
---|
161 | |
---|
162 | # sans.pr |
---|
163 | numpy_incl_path = os.path.join(NUMPY_INC, "numpy") |
---|
164 | srcdir = os.path.join("src", "sans", "pr", "c_extensions") |
---|
165 | package_dir["sans.pr.core"] = srcdir |
---|
166 | package_dir["sans.pr"] = os.path.join("src","sans", "pr") |
---|
167 | packages.extend(["sans.pr","sans.pr.core"]) |
---|
168 | ext_modules.append( Extension("sans.pr.core.pr_inversion", |
---|
169 | sources = [os.path.join(srcdir, "Cinvertor.c"), |
---|
170 | os.path.join(srcdir, "invertor.c"), |
---|
171 | ], |
---|
172 | include_dirs=[numpy_incl_path], |
---|
173 | ) ) |
---|
174 | |
---|
175 | # sans.fit (park integration) |
---|
176 | package_dir["sans.fit"] = os.path.join("src", "sans", "fit") |
---|
177 | packages.append("sans.fit") |
---|
178 | |
---|
179 | # Perspectives |
---|
180 | package_dir["sans.perspectives"] = os.path.join("src", "sans", "perspectives") |
---|
181 | package_dir["sans.perspectives.pr"] = os.path.join("src", "sans", "perspectives", "pr") |
---|
182 | packages.extend(["sans.perspectives","sans.perspectives.pr"]) |
---|
183 | package_data["sans.perspectives.pr"] = ['images/*'] |
---|
184 | |
---|
185 | package_dir["sans.perspectives.invariant"] = os.path.join("src", "sans", "perspectives", "invariant") |
---|
186 | packages.extend(["sans.perspectives.invariant"]) |
---|
187 | package_data['sans.perspectives.invariant'] = [os.path.join("media",'*')] |
---|
188 | |
---|
189 | package_dir["sans.perspectives.fitting"] = os.path.join("src", "sans", "perspectives", "fitting") |
---|
190 | package_dir["sans.perspectives.fitting.plugin_models"] = os.path.join("src", "sans", "perspectives", "fitting", "plugin_models") |
---|
191 | packages.extend(["sans.perspectives.fitting", |
---|
192 | "sans.perspectives.fitting.plugin_models"]) |
---|
193 | package_data['sans.perspectives.fitting'] = ['media/*','plugin_models/*'] |
---|
194 | |
---|
195 | packages.extend(["sans.perspectives", "sans.perspectives.calculator"]) |
---|
196 | package_data['sans.perspectives.calculator'] = ['images/*', 'media/*'] |
---|
197 | |
---|
198 | # Data util |
---|
199 | package_dir["data_util"] = os.path.join("src", "sans", "data_util") |
---|
200 | packages.append("sans.data_util") |
---|
201 | |
---|
202 | # Plottools |
---|
203 | package_dir["sans.plottools"] = os.path.join("src", "sans", "plottools") |
---|
204 | packages.append("sans.plottools") |
---|
205 | |
---|
206 | # Park 1.2.1 |
---|
207 | package_dir["park"]="park-1.2.1/park" |
---|
208 | packages.extend(["park"]) |
---|
209 | package_data["park"] = ['park-1.2.1/*.txt', 'park-1.2.1/park.epydoc'] |
---|
210 | ext_modules.append( Extension("park._modeling", |
---|
211 | sources = [ os.path.join("park-1.2.1", |
---|
212 | "park", "lib", "modeling.cc"), |
---|
213 | os.path.join("park-1.2.1", |
---|
214 | "park", "lib", "resolution.c"), |
---|
215 | ], |
---|
216 | ) ) |
---|
217 | |
---|
218 | # Sans models |
---|
219 | includedir = os.path.join("src", "sans", "models", "include") |
---|
220 | igordir = os.path.join("src", "sans", "models", "c_extension", "libigor") |
---|
221 | cephes_dir = os.path.join("src", "sans", "models", "c_extension", "cephes") |
---|
222 | c_model_dir = os.path.join("src", "sans", "models", "c_extension", "c_models") |
---|
223 | smear_dir = os.path.join("src", "sans", "models", "c_extension", "c_smearer") |
---|
224 | gen_dir = os.path.join("src", "sans", "models", "c_extension", "c_gen") |
---|
225 | wrapper_dir = os.path.join("src", "sans", "models", "c_extension", "python_wrapper", "generated") |
---|
226 | model_dir = os.path.join("src", "sans","models") |
---|
227 | |
---|
228 | if os.path.isdir(wrapper_dir): |
---|
229 | for file in os.listdir(wrapper_dir): |
---|
230 | file_path = os.path.join(wrapper_dir, file) |
---|
231 | os.remove(file_path) |
---|
232 | else: |
---|
233 | os.makedirs(wrapper_dir) |
---|
234 | sys.path.append(os.path.join("src", "sans", "models", "c_extension", "python_wrapper")) |
---|
235 | from wrapping import generate_wrappers |
---|
236 | generate_wrappers(header_dir = includedir, |
---|
237 | output_dir = model_dir, |
---|
238 | c_wrapper_dir = wrapper_dir) |
---|
239 | |
---|
240 | IGNORED_FILES = [".svn"] |
---|
241 | if not os.name=='nt': |
---|
242 | IGNORED_FILES.extend(["gamma_win.c","winFuncs.c"]) |
---|
243 | |
---|
244 | EXTENSIONS = [".c", ".cpp"] |
---|
245 | |
---|
246 | def append_file(file_list, dir_path): |
---|
247 | """ |
---|
248 | Add sources file to sources |
---|
249 | """ |
---|
250 | for f in os.listdir(dir_path): |
---|
251 | if os.path.isfile(os.path.join(dir_path, f)): |
---|
252 | _, ext = os.path.splitext(f) |
---|
253 | if ext.lower() in EXTENSIONS and f not in IGNORED_FILES: |
---|
254 | file_list.append(os.path.join(dir_path, f)) |
---|
255 | elif os.path.isdir(os.path.join(dir_path, f)) and \ |
---|
256 | not f.startswith("."): |
---|
257 | sub_dir = os.path.join(dir_path, f) |
---|
258 | for new_f in os.listdir(sub_dir): |
---|
259 | if os.path.isfile(os.path.join(sub_dir, new_f)): |
---|
260 | _, ext = os.path.splitext(new_f) |
---|
261 | if ext.lower() in EXTENSIONS and\ |
---|
262 | new_f not in IGNORED_FILES: |
---|
263 | file_list.append(os.path.join(sub_dir, new_f)) |
---|
264 | |
---|
265 | model_sources = [] |
---|
266 | append_file(file_list=model_sources, dir_path=igordir) |
---|
267 | append_file(file_list=model_sources, dir_path=c_model_dir) |
---|
268 | append_file(file_list=model_sources, dir_path=wrapper_dir) |
---|
269 | |
---|
270 | smear_sources = [] |
---|
271 | append_file(file_list=smear_sources, dir_path=smear_dir) |
---|
272 | |
---|
273 | package_dir["sans.models"] = model_dir |
---|
274 | package_dir["sans.models.sans_extension"] = os.path.join("src", "sans", "models", "sans_extension") |
---|
275 | package_data['sans.models'] = [os.path.join('media', "*.*")] |
---|
276 | package_data['sans.models'] += [os.path.join('media','img', "*.*")] |
---|
277 | packages.extend(["sans.models","sans.models.sans_extension"]) |
---|
278 | |
---|
279 | smearer_sources = [os.path.join(smear_dir, "smearer.cpp"), |
---|
280 | os.path.join(smear_dir, "smearer_module.cpp")] |
---|
281 | geni_sources = [os.path.join(gen_dir, "sld2i_module.cpp")] |
---|
282 | if os.name=='nt': |
---|
283 | smearer_sources.append(os.path.join(igordir, "winFuncs.c")) |
---|
284 | geni_sources.append(os.path.join(igordir, "winFuncs.c")) |
---|
285 | ext_modules.extend( [ Extension("sans.models.sans_extension.c_models", |
---|
286 | sources=model_sources, |
---|
287 | include_dirs=[igordir, includedir, |
---|
288 | c_model_dir, numpy_incl_path, cephes_dir], |
---|
289 | ), |
---|
290 | # Smearer extension |
---|
291 | Extension("sans.models.sans_extension.smearer", |
---|
292 | sources = smearer_sources, |
---|
293 | include_dirs=[igordir, |
---|
294 | smear_dir, numpy_incl_path], |
---|
295 | ), |
---|
296 | |
---|
297 | Extension("sans.models.sans_extension.smearer2d_helper", |
---|
298 | sources = [os.path.join(smear_dir, |
---|
299 | "smearer2d_helper_module.cpp"), |
---|
300 | os.path.join(smear_dir, |
---|
301 | "smearer2d_helper.cpp"),], |
---|
302 | include_dirs=[smear_dir, numpy_incl_path], |
---|
303 | ), |
---|
304 | |
---|
305 | Extension("sans.models.sans_extension.sld2i", |
---|
306 | sources = [os.path.join(gen_dir, |
---|
307 | "sld2i_module.cpp"), |
---|
308 | os.path.join(gen_dir, |
---|
309 | "sld2i.cpp"), |
---|
310 | os.path.join(c_model_dir, |
---|
311 | "libfunc.c"), |
---|
312 | os.path.join(c_model_dir, |
---|
313 | "librefl.c"),], |
---|
314 | include_dirs=[gen_dir, includedir, |
---|
315 | c_model_dir, numpy_incl_path], |
---|
316 | ) |
---|
317 | ] ) |
---|
318 | |
---|
319 | # SasView |
---|
320 | |
---|
321 | package_dir["sans.sansview"] = "sansview" |
---|
322 | package_data['sans.sansview'] = ['images/*', 'media/*', 'test/*', |
---|
323 | 'default_categories.json'] |
---|
324 | packages.append("sans.sansview") |
---|
325 | |
---|
326 | #required = ['lxml>=2.2.2', 'numpy>=1.4.1', 'matplotlib>=0.99.1.1', |
---|
327 | # 'wxPython>=2.8.11', 'pil', |
---|
328 | # 'periodictable>=1.3.0', 'scipy>=0.7.2'] |
---|
329 | required = ['lxml','periodictable>=1.3.1','pyparsing<2.0.0'] |
---|
330 | |
---|
331 | if os.name=='nt': |
---|
332 | required.extend(['html5lib', 'reportlab']) |
---|
333 | else: |
---|
334 | required.extend(['pil']) |
---|
335 | |
---|
336 | # Set up SasView |
---|
337 | setup( |
---|
338 | name="sasview", |
---|
339 | version = VERSION, |
---|
340 | description = "SasView application", |
---|
341 | author = "University of Tennessee", |
---|
342 | author_email = "sansdanse@gmail.com", |
---|
343 | url = "http://sasview.org", |
---|
344 | license = "PSF", |
---|
345 | keywords = "small-angle x-ray and neutron scattering analysis", |
---|
346 | download_url = "https://sourceforge.net/projects/sansviewproject/files/", |
---|
347 | package_dir = package_dir, |
---|
348 | packages = packages, |
---|
349 | package_data = package_data, |
---|
350 | ext_modules = ext_modules, |
---|
351 | install_requires = required, |
---|
352 | zip_safe = False, |
---|
353 | entry_points = { |
---|
354 | 'console_scripts':[ |
---|
355 | "sasview = sans.sansview.sansview:run", |
---|
356 | ] |
---|
357 | }, |
---|
358 | cmdclass = {'build_ext': build_ext_subclass } |
---|
359 | ) |
---|