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"] = os.path.join("src", "sans", "invariant") |
---|
111 | packages.extend(["sans.invariant"]) |
---|
112 | |
---|
113 | # sans.guiframe |
---|
114 | guiframe_path = os.path.join("src", "sans", "guiframe") |
---|
115 | package_dir["sans.guiframe"] = guiframe_path |
---|
116 | package_dir["sans.guiframe.local_perspectives"] = os.path.join(os.path.join(guiframe_path, "local_perspectives")) |
---|
117 | package_data["sans.guiframe"] = ['images/*', 'media/*'] |
---|
118 | packages.extend(["sans.guiframe", "sans.guiframe.local_perspectives"]) |
---|
119 | # build local plugin |
---|
120 | for dir in os.listdir(os.path.join(guiframe_path, "local_perspectives")): |
---|
121 | if dir not in ['.svn','__init__.py', '__init__.pyc']: |
---|
122 | package_name = "sans.guiframe.local_perspectives." + dir |
---|
123 | packages.append(package_name) |
---|
124 | package_dir[package_name] = os.path.join(guiframe_path, "local_perspectives", dir) |
---|
125 | |
---|
126 | # sans.dataloader |
---|
127 | package_dir["sans.dataloader"] = os.path.join("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"] =os.path.join("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("src", "sans", "pr", "c_extensions") |
---|
138 | package_dir["sans.pr.core"] = srcdir |
---|
139 | package_dir["sans.pr"] = os.path.join("src","sans", "pr") |
---|
140 | packages.extend(["sans.pr","sans.pr.core"]) |
---|
141 | ext_modules.append( Extension("sans.pr.core.pr_inversion", |
---|
142 | sources = [os.path.join(srcdir, "Cinvertor.c"), |
---|
143 | os.path.join(srcdir, "invertor.c"), |
---|
144 | ], |
---|
145 | include_dirs=[numpy_incl_path], |
---|
146 | ) ) |
---|
147 | |
---|
148 | # sans.fit (park integration) |
---|
149 | package_dir["sans.fit"] = os.path.join("src", "sans", "fit") |
---|
150 | packages.append("sans.fit") |
---|
151 | |
---|
152 | # Perspectives |
---|
153 | package_dir["sans.perspectives"] = os.path.join("src", "sans", "perspectives") |
---|
154 | package_dir["sans.perspectives.pr"] = os.path.join("src", "sans", "perspectives", "pr") |
---|
155 | packages.extend(["sans.perspectives","sans.perspectives.pr"]) |
---|
156 | package_data["sans.perspectives.pr"] = ['images/*'] |
---|
157 | |
---|
158 | package_dir["sans.perspectives.invariant"] = os.path.join("src", "sans", "perspectives", "invariant") |
---|
159 | packages.extend(["sans.perspectives.invariant"]) |
---|
160 | package_data['sans.perspectives.invariant'] = [os.path.join("media",'*')] |
---|
161 | |
---|
162 | package_dir["sans.perspectives.fitting"] = os.path.join("src", "sans", "perspectives", "fitting") |
---|
163 | package_dir["sans.perspectives.fitting.plugin_models"] = os.path.join("src", "sans", "perspectives", "fitting", "plugin_models") |
---|
164 | packages.extend(["sans.perspectives.fitting", |
---|
165 | "sans.perspectives.fitting.plugin_models"]) |
---|
166 | package_data['sans.perspectives.fitting'] = ['media/*','plugin_models/*'] |
---|
167 | |
---|
168 | packages.extend(["sans.perspectives", "sans.perspectives.calculator"]) |
---|
169 | package_data['sans.perspectives.calculator'] = ['images/*', 'media/*'] |
---|
170 | |
---|
171 | # Data util |
---|
172 | package_dir["data_util"] = os.path.join("src", "data_util") |
---|
173 | packages.extend(["data_util"]) |
---|
174 | |
---|
175 | # Plottools |
---|
176 | package_dir["danse"] = os.path.join("src", "danse") |
---|
177 | package_dir["danse.common"] = os.path.join("src", "danse", "common") |
---|
178 | package_dir["danse.common.plottools"] = os.path.join("src", "danse", "common", "plottools") |
---|
179 | packages.extend(["danse", "danse.common", "danse.common.plottools"]) |
---|
180 | |
---|
181 | # Park 1.2.1 |
---|
182 | package_dir["park"]="park-1.2.1/park" |
---|
183 | packages.extend(["park"]) |
---|
184 | package_data["park"] = ['park-1.2.1/*.txt', 'park-1.2.1/park.epydoc'] |
---|
185 | ext_modules.append( Extension("park._modeling", |
---|
186 | sources = [ os.path.join("park-1.2.1", |
---|
187 | "park", "lib", "modeling.cc"), |
---|
188 | os.path.join("park-1.2.1", |
---|
189 | "park", "lib", "resolution.c"), |
---|
190 | ], |
---|
191 | ) ) |
---|
192 | |
---|
193 | # Sans models |
---|
194 | includedir = os.path.join("src", "sans", "models", "include") |
---|
195 | igordir = os.path.join("src", "sans", "models", "c_extension", "libigor") |
---|
196 | cephes_dir = os.path.join("src", "sans", "models", "c_extension", "cephes") |
---|
197 | c_model_dir = os.path.join("src", "sans", "models", "c_extension", "c_models") |
---|
198 | smear_dir = os.path.join("src", "sans", "models", "c_extension", "c_smearer") |
---|
199 | gen_dir = os.path.join("src", "sans", "models", "c_extension", "c_gen") |
---|
200 | wrapper_dir = os.path.join("src", "sans", "models", "c_extension", "python_wrapper", "generated") |
---|
201 | model_dir = os.path.join("src", "sans","models") |
---|
202 | |
---|
203 | if os.path.isdir(wrapper_dir): |
---|
204 | for file in os.listdir(wrapper_dir): |
---|
205 | file_path = os.path.join(wrapper_dir, file) |
---|
206 | os.remove(file_path) |
---|
207 | else: |
---|
208 | os.makedirs(wrapper_dir) |
---|
209 | sys.path.append(os.path.join("src", "sans", "models", "c_extension", "python_wrapper")) |
---|
210 | from wrapping import generate_wrappers |
---|
211 | generate_wrappers(header_dir = includedir, |
---|
212 | output_dir = model_dir, |
---|
213 | c_wrapper_dir = wrapper_dir) |
---|
214 | |
---|
215 | IGNORED_FILES = [".svn"] |
---|
216 | if not os.name=='nt': |
---|
217 | IGNORED_FILES.extend(["gamma_win.c","winFuncs.c"]) |
---|
218 | |
---|
219 | |
---|
220 | EXTENSIONS = [".c", ".cpp"] |
---|
221 | |
---|
222 | def append_file(file_list, dir_path): |
---|
223 | """ |
---|
224 | Add sources file to sources |
---|
225 | """ |
---|
226 | for f in os.listdir(dir_path): |
---|
227 | if os.path.isfile(os.path.join(dir_path, f)): |
---|
228 | _, ext = os.path.splitext(f) |
---|
229 | if ext.lower() in EXTENSIONS and f not in IGNORED_FILES: |
---|
230 | file_list.append(os.path.join(dir_path, f)) |
---|
231 | elif os.path.isdir(os.path.join(dir_path, f)) and \ |
---|
232 | not f.startswith("."): |
---|
233 | sub_dir = os.path.join(dir_path, f) |
---|
234 | for new_f in os.listdir(sub_dir): |
---|
235 | if os.path.isfile(os.path.join(sub_dir, new_f)): |
---|
236 | _, ext = os.path.splitext(new_f) |
---|
237 | if ext.lower() in EXTENSIONS and\ |
---|
238 | new_f not in IGNORED_FILES: |
---|
239 | file_list.append(os.path.join(sub_dir, new_f)) |
---|
240 | |
---|
241 | model_sources = [] |
---|
242 | append_file(file_list=model_sources, dir_path=igordir) |
---|
243 | append_file(file_list=model_sources, dir_path=c_model_dir) |
---|
244 | append_file(file_list=model_sources, dir_path=wrapper_dir) |
---|
245 | |
---|
246 | smear_sources = [] |
---|
247 | append_file(file_list=smear_sources, dir_path=smear_dir) |
---|
248 | |
---|
249 | # SasView |
---|
250 | |
---|
251 | package_dir["sans.sansview"] = "sansview" |
---|
252 | package_data['sans.sansview'] = ['images/*', 'media/*', 'test/*', |
---|
253 | 'default_categories.p'] |
---|
254 | packages.append("sans.sansview") |
---|
255 | |
---|
256 | #required = ['lxml>=2.2.2', 'numpy>=1.4.1', 'matplotlib>=0.99.1.1', |
---|
257 | # 'wxPython>=2.8.11', 'pil', |
---|
258 | # 'periodictable>=1.3.0', 'scipy>=0.7.2'] |
---|
259 | required = ['lxml','periodictable>=1.3.1','pyparsing<2.0.0'] |
---|
260 | |
---|
261 | if os.name=='nt': |
---|
262 | required.extend(['html5lib', 'reportlab']) |
---|
263 | else: |
---|
264 | required.extend(['pil']) |
---|
265 | |
---|
266 | # Set up SasView |
---|
267 | setup( |
---|
268 | name="sasview", |
---|
269 | version = VERSION, |
---|
270 | description = "SasView application", |
---|
271 | author = "University of Tennessee", |
---|
272 | author_email = "sansdanse@gmail.com", |
---|
273 | url = "http://danse.chem.utk.edu", |
---|
274 | license = "PSF", |
---|
275 | keywords = "small-angle x-ray and neutron scattering analysis", |
---|
276 | download_url = "https://sourceforge.net/projects/sansviewproject/files/", |
---|
277 | package_dir = package_dir, |
---|
278 | packages = packages, |
---|
279 | package_data = package_data, |
---|
280 | ext_modules = ext_modules, |
---|
281 | install_requires = required, |
---|
282 | zip_safe = False, |
---|
283 | entry_points = { |
---|
284 | 'console_scripts':[ |
---|
285 | "sasview = sans.sansview.sansview:run", |
---|
286 | ] |
---|
287 | }, |
---|
288 | cmdclass = {'build_ext': build_ext_subclass } |
---|
289 | ) |
---|