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