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