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