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],"core","include") |
---|
19 | except: |
---|
20 | print "\nNumpy is needed to build SansView. 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 | if sys.argv[-1] == "-nomp": |
---|
34 | # Disable OpenMP |
---|
35 | copt = {} |
---|
36 | lopt = {} |
---|
37 | else: |
---|
38 | # Options to enable OpenMP |
---|
39 | copt = {'msvc': ['/openmp'], |
---|
40 | 'mingw32' : ['-fopenmp'], |
---|
41 | 'unix' : ['-fopenmp']} |
---|
42 | lopt = {'msvc': ['/MANIFEST'], |
---|
43 | 'mingw32' : ['-fopenmp'], |
---|
44 | 'unix' : ['-lgomp']} |
---|
45 | |
---|
46 | class build_ext_subclass( build_ext ): |
---|
47 | def build_extensions(self): |
---|
48 | # Get 64-bitness |
---|
49 | if sys.version_info >= (2, 6): |
---|
50 | is_64bits = sys.maxsize > 2**32 |
---|
51 | else: |
---|
52 | # 'sys.maxsize' and 64bit: Not supported for python2.5 |
---|
53 | is_64bits = False |
---|
54 | |
---|
55 | c = self.compiler.compiler_type |
---|
56 | print "Compiling with %s (64bit=%s)" % (c, str(is_64bits)) |
---|
57 | |
---|
58 | if not (sys.platform=='darwin' and not is_64bits): |
---|
59 | if copt.has_key(c): |
---|
60 | for e in self.extensions: |
---|
61 | e.extra_compile_args = copt[ c ] |
---|
62 | if lopt.has_key(c): |
---|
63 | for e in self.extensions: |
---|
64 | e.extra_link_args = lopt[ c ] |
---|
65 | |
---|
66 | build_ext.build_extensions(self) |
---|
67 | |
---|
68 | |
---|
69 | # sans.invariant |
---|
70 | package_dir["sans.invariant"] = "sansinvariant/src/sans/invariant" |
---|
71 | packages.extend(["sans.invariant"]) |
---|
72 | |
---|
73 | # sans.guiframe |
---|
74 | guiframe_path = os.path.join("sansguiframe", "src", "sans", "guiframe") |
---|
75 | package_dir["sans.guiframe"] = guiframe_path |
---|
76 | package_dir["sans.guiframe.local_perspectives"] = os.path.join(guiframe_path, "local_perspectives") |
---|
77 | package_data["sans.guiframe"] = ['images/*', 'media/*'] |
---|
78 | packages.extend(["sans.guiframe", "sans.guiframe.local_perspectives"]) |
---|
79 | # build local plugin |
---|
80 | for dir in os.listdir(os.path.join(guiframe_path, "local_perspectives")): |
---|
81 | if dir not in ['.svn','__init__.py', '__init__.pyc']: |
---|
82 | package_name = "sans.guiframe.local_perspectives." + dir |
---|
83 | packages.append(package_name) |
---|
84 | package_dir[package_name] = os.path.join(guiframe_path, "local_perspectives", dir) |
---|
85 | |
---|
86 | # sans.dataloader |
---|
87 | package_dir["sans.dataloader"] = os.path.join("sansdataloader", "src", "sans", "dataloader") |
---|
88 | package_data["sans.dataloader.readers"] = ['defaults.xml'] |
---|
89 | packages.extend(["sans.dataloader","sans.dataloader.readers"]) |
---|
90 | |
---|
91 | # sans.calculator |
---|
92 | package_dir["sans.calculator"] = "sanscalculator/src/sans/calculator" |
---|
93 | packages.extend(["sans.calculator"]) |
---|
94 | |
---|
95 | # sans.pr |
---|
96 | numpy_incl_path = os.path.join(NUMPY_INC, "numpy") |
---|
97 | srcdir = os.path.join("pr_inversion", "src", "sans", "pr", "c_extensions") |
---|
98 | |
---|
99 | |
---|
100 | |
---|
101 | package_dir["sans.pr.core"] = srcdir |
---|
102 | package_dir["sans.pr"] = os.path.join("pr_inversion", "src","sans", "pr") |
---|
103 | packages.extend(["sans.pr","sans.pr.core"]) |
---|
104 | ext_modules.append( Extension("sans.pr.core.pr_inversion", |
---|
105 | sources = [ os.path.join(srcdir, "Cinvertor.c"), |
---|
106 | os.path.join(srcdir, "invertor.c"), |
---|
107 | ], |
---|
108 | include_dirs=[numpy_incl_path], |
---|
109 | ) ) |
---|
110 | |
---|
111 | # sans.fit (park integration) |
---|
112 | package_dir["sans.fit"] = "park_integration/src/sans/fit" |
---|
113 | packages.append("sans.fit") |
---|
114 | |
---|
115 | # inversion view |
---|
116 | package_dir["sans.perspectives"] = "inversionview/src/sans/perspectives" |
---|
117 | package_dir["sans.perspectives.pr"] = "inversionview/src/sans/perspectives/pr" |
---|
118 | packages.extend(["sans.perspectives","sans.perspectives.pr"]) |
---|
119 | package_data["sans.perspectives.pr"] = ['images/*'] |
---|
120 | |
---|
121 | # Invariant view |
---|
122 | package_dir["sans.perspectives"] = os.path.join("invariantview", "src", "sans", "perspectives") |
---|
123 | package_dir["sans.perspectives.invariant"] = os.path.join("invariantview", "src", "sans", "perspectives", "invariant") |
---|
124 | |
---|
125 | package_data['sans.perspectives.invariant'] = [os.path.join("media",'*')] |
---|
126 | packages.extend(["sans.perspectives","sans.perspectives.invariant"]) |
---|
127 | |
---|
128 | # Fitting view |
---|
129 | package_dir["sans.perspectives"] = os.path.join("fittingview", "src", "sans", "perspectives"), |
---|
130 | package_dir["sans.perspectives.fitting"] = os.path.join("fittingview", "src", "sans", "perspectives", "fitting") |
---|
131 | package_data['sans.perspectives.fitting'] = ['media/*','plugin_models/*'] |
---|
132 | packages.extend(["sans.perspectives", "sans.perspectives.fitting"]) |
---|
133 | |
---|
134 | # Calculator view |
---|
135 | package_dir["sans.perspectives"] = "calculatorview/src/sans/perspectives" |
---|
136 | package_dir["sans.perspectives.calculator"] = os.path.join("calculatorview", "src", "sans", "perspectives", "calculator") |
---|
137 | package_data['sans.perspectives.calculator'] = ['images/*', 'media/*'] |
---|
138 | packages.extend(["sans.perspectives", "sans.perspectives.calculator"]) |
---|
139 | |
---|
140 | # Data util |
---|
141 | package_dir["data_util"] = "sansutil" |
---|
142 | packages.extend(["data_util"]) |
---|
143 | |
---|
144 | # Plottools |
---|
145 | package_dir["danse"] = os.path.join("plottools", "src", "danse") |
---|
146 | package_dir["danse.common"] = os.path.join("plottools", "src", "danse", "common") |
---|
147 | package_dir["danse.common.plottools"] = os.path.join("plottools", "src", "danse", "common", "plottools") |
---|
148 | packages.extend(["danse", "danse.common", "danse.common.plottools"]) |
---|
149 | |
---|
150 | # Park 1.2.1 |
---|
151 | package_dir["park"]="park-1.2.1/park" |
---|
152 | packages.extend(["park"]) |
---|
153 | package_data["park"] = ['park-1.2.1/*.txt', 'park-1.2.1/park.epydoc'] |
---|
154 | ext_modules.append( Extension("park._modeling", |
---|
155 | sources = [ os.path.join("park-1.2.1", "park", "lib", "modeling.cc"), |
---|
156 | os.path.join("park-1.2.1", "park", "lib", "resolution.c"), |
---|
157 | ], |
---|
158 | ) ) |
---|
159 | |
---|
160 | # Sans models |
---|
161 | srcdir = os.path.join("sansmodels", "src", "sans", "models", "c_extensions") |
---|
162 | igordir = os.path.join("sansmodels", "src","sans", "models", "libigor") |
---|
163 | c_model_dir = os.path.join("sansmodels", "src", "sans", "models", "c_models") |
---|
164 | smear_dir = os.path.join("sansmodels", "src", "sans", "models", "c_smearer") |
---|
165 | |
---|
166 | IGNORED_FILES = ["a.exe", |
---|
167 | "__init__.py" |
---|
168 | ".svn", |
---|
169 | "lineparser.py", |
---|
170 | "run.py", |
---|
171 | "CGaussian.cpp", |
---|
172 | "CLogNormal.cpp", |
---|
173 | "CLorentzian.cpp", |
---|
174 | "CSchulz.cpp", |
---|
175 | "WrapperGenerator.py", |
---|
176 | "wrapping.py" |
---|
177 | ] |
---|
178 | |
---|
179 | if not os.name=='nt': |
---|
180 | IGNORED_FILES.extend(["gamma_win.c","winFuncs.c"]) |
---|
181 | |
---|
182 | |
---|
183 | EXTENSIONS = [".c", ".cpp"] |
---|
184 | |
---|
185 | def append_file(file_list, dir_path): |
---|
186 | """ |
---|
187 | Add sources file to sources |
---|
188 | """ |
---|
189 | for f in os.listdir(dir_path): |
---|
190 | if os.path.isfile(os.path.join(dir_path, f)): |
---|
191 | _, ext = os.path.splitext(f) |
---|
192 | if ext.lower() in EXTENSIONS and f not in IGNORED_FILES: |
---|
193 | file_list.append(os.path.join(dir_path, f)) |
---|
194 | elif os.path.isdir(os.path.join(dir_path, f)) and \ |
---|
195 | not f.startswith("."): |
---|
196 | sub_dir = os.path.join(dir_path, f) |
---|
197 | for new_f in os.listdir(sub_dir): |
---|
198 | if os.path.isfile(os.path.join(sub_dir, new_f)): |
---|
199 | _, ext = os.path.splitext(new_f) |
---|
200 | if ext.lower() in EXTENSIONS and\ |
---|
201 | new_f not in IGNORED_FILES: |
---|
202 | file_list.append(os.path.join(sub_dir, new_f)) |
---|
203 | |
---|
204 | model_sources = [] |
---|
205 | append_file(file_list=model_sources, dir_path=srcdir) |
---|
206 | append_file(file_list=model_sources, dir_path=igordir) |
---|
207 | append_file(file_list=model_sources, dir_path=c_model_dir) |
---|
208 | smear_sources = [] |
---|
209 | append_file(file_list=smear_sources, dir_path=smear_dir) |
---|
210 | |
---|
211 | |
---|
212 | package_dir["sans"] = os.path.join("sansmodels", "src", "sans") |
---|
213 | package_dir["sans.models"] = os.path.join("sansmodels", "src", "sans", "models") |
---|
214 | package_dir["sans.models.sans_extension"] = srcdir |
---|
215 | |
---|
216 | package_data['sans.models'] = [os.path.join('media', "*")] |
---|
217 | packages.extend(["sans","sans.models","sans.models.sans_extension"]) |
---|
218 | |
---|
219 | smearer_sources = [os.path.join(smear_dir, "smearer.cpp"), |
---|
220 | os.path.join(smear_dir, "smearer_module.cpp")] |
---|
221 | |
---|
222 | if os.name=='nt': |
---|
223 | smearer_sources.append(os.path.join(igordir, "winFuncs.c")) |
---|
224 | |
---|
225 | ext_modules.extend( [ Extension("sans.models.sans_extension.c_models", |
---|
226 | sources=model_sources, |
---|
227 | include_dirs=[igordir, srcdir, c_model_dir, numpy_incl_path], |
---|
228 | ), |
---|
229 | # Smearer extension |
---|
230 | Extension("sans.models.sans_extension.smearer", |
---|
231 | sources = smearer_sources, |
---|
232 | include_dirs=[igordir, smear_dir, numpy_incl_path], |
---|
233 | ), |
---|
234 | |
---|
235 | Extension("sans.models.sans_extension.smearer2d_helper", |
---|
236 | sources = [os.path.join(smear_dir, |
---|
237 | "smearer2d_helper_module.cpp"), |
---|
238 | os.path.join(smear_dir, "smearer2d_helper.cpp"),], |
---|
239 | include_dirs=[smear_dir,numpy_incl_path], |
---|
240 | ) |
---|
241 | ] ) |
---|
242 | |
---|
243 | # SansView |
---|
244 | package_dir["sans.sansview"] = "sansview" |
---|
245 | package_data['sans.sansview'] = ['images/*', 'media/*', 'test/*'] |
---|
246 | packages.append("sans.sansview") |
---|
247 | |
---|
248 | #required = ['lxml>=2.2.2', 'numpy>=1.4.1', 'matplotlib>=0.99.1.1', 'wxPython>=2.8.11', |
---|
249 | # 'pil','periodictable>=1.3.0', 'scipy>=0.7.2'] |
---|
250 | required = ['lxml','periodictable>=1.3.0'] |
---|
251 | """ |
---|
252 | if os.name=='nt': |
---|
253 | #required.extend(['comtypes', 'pisa', 'html5lib', 'reportlab']) |
---|
254 | required.extend(['pisa', 'html5lib']) |
---|
255 | if sys.version_info < (2, 7): |
---|
256 | required.append('comtypes') |
---|
257 | else: |
---|
258 | required.extend(['pil']) |
---|
259 | """ |
---|
260 | # Set up SansView |
---|
261 | setup( |
---|
262 | name="sansview", |
---|
263 | version = VERSION, |
---|
264 | description = "SansView application", |
---|
265 | author = "University of Tennessee", |
---|
266 | author_email = "sansdanse@gmail.com", |
---|
267 | url = "http://danse.chem.utk.edu", |
---|
268 | license = "PSF", |
---|
269 | keywords = "small-angle neutron scattering analysis", |
---|
270 | download_url = "https://sourceforge.net/projects/sansviewproject/files/", |
---|
271 | package_dir = package_dir, |
---|
272 | packages = packages, |
---|
273 | package_data = package_data, |
---|
274 | ext_modules = ext_modules, |
---|
275 | install_requires = required, |
---|
276 | zip_safe = False, |
---|
277 | entry_points = { |
---|
278 | 'console_scripts':[ |
---|
279 | "sansview = sans.sansview.sansview:run", |
---|
280 | ] |
---|
281 | }, |
---|
282 | cmdclass = {'build_ext': build_ext_subclass } |
---|
283 | ) |
---|