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