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