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