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