[d6bc28cf] | 1 | """ |
---|
[c329f4d] | 2 | Setup for SasView |
---|
[d6bc28cf] | 3 | #TODO: Add checks to see that all the dependencies are on the system |
---|
| 4 | """ |
---|
[8ab3302] | 5 | import sys |
---|
[d6bc28cf] | 6 | import os |
---|
[01de557] | 7 | import platform |
---|
[df7a7e3] | 8 | import shutil |
---|
[d6bc28cf] | 9 | from setuptools import setup, Extension, find_packages |
---|
[2cef9d3] | 10 | from distutils.command.build_ext import build_ext |
---|
| 11 | |
---|
[e13ef7f] | 12 | try: |
---|
| 13 | from numpy.distutils.misc_util import get_numpy_include_dirs |
---|
| 14 | NUMPY_INC = get_numpy_include_dirs()[0] |
---|
| 15 | except: |
---|
[cb5fb4a] | 16 | try: |
---|
[e13ef7f] | 17 | import numpy |
---|
[8ab3302] | 18 | NUMPY_INC = os.path.join(os.path.split(numpy.__file__)[0], |
---|
| 19 | "core","include") |
---|
[cb5fb4a] | 20 | except: |
---|
[c329f4d] | 21 | msg = "\nNumpy is needed to build SasView. " |
---|
[8ab3302] | 22 | print msg, "Try easy_install numpy.\n %s" % str(sys.exc_value) |
---|
[e13ef7f] | 23 | sys.exit(0) |
---|
[d6bc28cf] | 24 | |
---|
[5548954] | 25 | # Manage version number ###################################### |
---|
[a134fc6] | 26 | import sansview |
---|
| 27 | VERSION = sansview.__version__ |
---|
[5548954] | 28 | ############################################################## |
---|
| 29 | |
---|
[d6bc28cf] | 30 | package_dir = {} |
---|
| 31 | package_data = {} |
---|
| 32 | packages = [] |
---|
| 33 | ext_modules = [] |
---|
| 34 | |
---|
[8ab3302] | 35 | # Remove all files that should be updated by this setup |
---|
| 36 | # We do this here because application updates these files from .sansview |
---|
| 37 | # except when there is no such file |
---|
| 38 | # Todo : make this list generic |
---|
| 39 | plugin_model_list = ['polynominal5.py', 'sph_bessel_jn.py', |
---|
| 40 | 'sum_Ap1_1_Ap2.py', 'sum_p1_p2.py', |
---|
[b30ed8f] | 41 | 'testmodel_2.py', 'testmodel.py', |
---|
| 42 | 'polynominal5.pyc', 'sph_bessel_jn.pyc', |
---|
| 43 | 'sum_Ap1_1_Ap2.pyc', 'sum_p1_p2.pyc', |
---|
[eb32080e] | 44 | 'testmodel_2.pyc', 'testmodel.pyc', 'plugins.log'] |
---|
[c329f4d] | 45 | sans_dir = os.path.join(os.path.expanduser("~"),'.sasview') |
---|
[8ab3302] | 46 | if os.path.isdir(sans_dir): |
---|
[c329f4d] | 47 | f_path = os.path.join(sans_dir, "sasview.log") |
---|
[e615a0d] | 48 | if os.path.isfile(f_path): |
---|
| 49 | os.remove(f_path) |
---|
[ea5fa58] | 50 | f_path = os.path.join(sans_dir, "serialized_cat.p") |
---|
| 51 | if os.path.isfile(f_path): |
---|
| 52 | os.remove(f_path) |
---|
[e615a0d] | 53 | f_path = os.path.join(sans_dir, 'config', "custom_config.py") |
---|
| 54 | if os.path.isfile(f_path): |
---|
| 55 | os.remove(f_path) |
---|
| 56 | f_path = os.path.join(sans_dir, 'plugin_models') |
---|
| 57 | if os.path.isdir(f_path): |
---|
| 58 | for file in os.listdir(f_path): |
---|
| 59 | if file in plugin_model_list: |
---|
| 60 | file_path = os.path.join(f_path, file) |
---|
| 61 | os.remove(file_path) |
---|
| 62 | |
---|
| 63 | # 'sys.maxsize' and 64bit: Not supported for python2.5 |
---|
| 64 | is_64bits = False |
---|
| 65 | if sys.version_info >= (2, 6): |
---|
| 66 | is_64bits = sys.maxsize > 2**32 |
---|
| 67 | |
---|
| 68 | |
---|
[b30ed8f] | 69 | enable_openmp = True |
---|
[e79a467] | 70 | |
---|
[b30ed8f] | 71 | if sys.platform =='darwin' and not is_64bits: |
---|
| 72 | # Disable OpenMP |
---|
| 73 | enable_openmp = False |
---|
| 74 | |
---|
| 75 | # Options to enable OpenMP |
---|
| 76 | copt = {'msvc': ['/openmp'], |
---|
| 77 | 'mingw32' : ['-fopenmp'], |
---|
| 78 | 'unix' : ['-fopenmp']} |
---|
| 79 | lopt = {'msvc': ['/MANIFEST'], |
---|
| 80 | 'mingw32' : ['-fopenmp'], |
---|
| 81 | 'unix' : ['-lgomp']} |
---|
[13f00a0] | 82 | |
---|
[ebdb833] | 83 | # Platform-specific link options |
---|
| 84 | platform_lopt = {'msvc' : ['/MANIFEST']} |
---|
| 85 | |
---|
[13f00a0] | 86 | class build_ext_subclass( build_ext ): |
---|
| 87 | def build_extensions(self): |
---|
| 88 | # Get 64-bitness |
---|
| 89 | c = self.compiler.compiler_type |
---|
| 90 | print "Compiling with %s (64bit=%s)" % (c, str(is_64bits)) |
---|
| 91 | |
---|
[ebdb833] | 92 | # OpenMP build options |
---|
[b30ed8f] | 93 | if enable_openmp: |
---|
[13f00a0] | 94 | if copt.has_key(c): |
---|
| 95 | for e in self.extensions: |
---|
| 96 | e.extra_compile_args = copt[ c ] |
---|
| 97 | if lopt.has_key(c): |
---|
| 98 | for e in self.extensions: |
---|
| 99 | e.extra_link_args = lopt[ c ] |
---|
| 100 | |
---|
[ebdb833] | 101 | # Platform-specific build options |
---|
| 102 | if platform_lopt.has_key(c): |
---|
| 103 | for e in self.extensions: |
---|
| 104 | e.extra_link_args = platform_lopt[ c ] |
---|
| 105 | |
---|
[13f00a0] | 106 | build_ext.build_extensions(self) |
---|
[d6bc28cf] | 107 | |
---|
[29e96f3] | 108 | |
---|
[d6bc28cf] | 109 | # sans.invariant |
---|
| 110 | package_dir["sans.invariant"] = "sansinvariant/src/sans/invariant" |
---|
| 111 | packages.extend(["sans.invariant"]) |
---|
| 112 | |
---|
| 113 | # sans.guiframe |
---|
[0711849] | 114 | guiframe_path = os.path.join("sansguiframe", "src", "sans", "guiframe") |
---|
[d6bc28cf] | 115 | package_dir["sans.guiframe"] = guiframe_path |
---|
[8ab3302] | 116 | package_dir["sans.guiframe.local_perspectives"] = os.path.join(guiframe_path, |
---|
| 117 | "local_perspectives") |
---|
[ea5fa58] | 118 | package_data["sans.guiframe"] = ['images/*', 'media/*'] |
---|
[d6bc28cf] | 119 | packages.extend(["sans.guiframe", "sans.guiframe.local_perspectives"]) |
---|
| 120 | # build local plugin |
---|
| 121 | for dir in os.listdir(os.path.join(guiframe_path, "local_perspectives")): |
---|
| 122 | if dir not in ['.svn','__init__.py', '__init__.pyc']: |
---|
| 123 | package_name = "sans.guiframe.local_perspectives." + dir |
---|
| 124 | packages.append(package_name) |
---|
[8ab3302] | 125 | package_dir[package_name] = os.path.join(guiframe_path, |
---|
| 126 | "local_perspectives", dir) |
---|
[d6bc28cf] | 127 | |
---|
| 128 | # sans.dataloader |
---|
[8ab3302] | 129 | package_dir["sans.dataloader"] = os.path.join("sansdataloader", |
---|
| 130 | "src", "sans", "dataloader") |
---|
[d6bc28cf] | 131 | package_data["sans.dataloader.readers"] = ['defaults.xml'] |
---|
| 132 | packages.extend(["sans.dataloader","sans.dataloader.readers"]) |
---|
| 133 | |
---|
| 134 | # sans.calculator |
---|
| 135 | package_dir["sans.calculator"] = "sanscalculator/src/sans/calculator" |
---|
| 136 | packages.extend(["sans.calculator"]) |
---|
| 137 | |
---|
| 138 | # sans.pr |
---|
[cb5fb4a] | 139 | numpy_incl_path = os.path.join(NUMPY_INC, "numpy") |
---|
[d6bc28cf] | 140 | srcdir = os.path.join("pr_inversion", "src", "sans", "pr", "c_extensions") |
---|
| 141 | |
---|
| 142 | |
---|
| 143 | |
---|
| 144 | package_dir["sans.pr.core"] = srcdir |
---|
| 145 | package_dir["sans.pr"] = os.path.join("pr_inversion", "src","sans", "pr") |
---|
| 146 | packages.extend(["sans.pr","sans.pr.core"]) |
---|
| 147 | ext_modules.append( Extension("sans.pr.core.pr_inversion", |
---|
[29e96f3] | 148 | sources = [ os.path.join(srcdir, "Cinvertor.c"), |
---|
| 149 | os.path.join(srcdir, "invertor.c"), |
---|
| 150 | ], |
---|
| 151 | include_dirs=[numpy_incl_path], |
---|
| 152 | ) ) |
---|
[d6bc28cf] | 153 | |
---|
| 154 | # sans.fit (park integration) |
---|
| 155 | package_dir["sans.fit"] = "park_integration/src/sans/fit" |
---|
| 156 | packages.append("sans.fit") |
---|
| 157 | |
---|
| 158 | # inversion view |
---|
| 159 | package_dir["sans.perspectives"] = "inversionview/src/sans/perspectives" |
---|
| 160 | package_dir["sans.perspectives.pr"] = "inversionview/src/sans/perspectives/pr" |
---|
| 161 | packages.extend(["sans.perspectives","sans.perspectives.pr"]) |
---|
| 162 | package_data["sans.perspectives.pr"] = ['images/*'] |
---|
| 163 | |
---|
| 164 | # Invariant view |
---|
[8ab3302] | 165 | package_dir["sans.perspectives"] = os.path.join("invariantview", "src", |
---|
| 166 | "sans", "perspectives") |
---|
| 167 | package_dir["sans.perspectives.invariant"] = os.path.join("invariantview", |
---|
| 168 | "src", "sans", "perspectives", "invariant") |
---|
[d6bc28cf] | 169 | |
---|
| 170 | package_data['sans.perspectives.invariant'] = [os.path.join("media",'*')] |
---|
| 171 | packages.extend(["sans.perspectives","sans.perspectives.invariant"]) |
---|
| 172 | |
---|
| 173 | # Fitting view |
---|
[8ab3302] | 174 | fitting_path = os.path.join("fittingview", "src", "sans", |
---|
| 175 | "perspectives", "fitting") |
---|
| 176 | package_dir["sans.perspectives"] = os.path.join("fittingview", |
---|
| 177 | "src", "sans", "perspectives"), |
---|
| 178 | package_dir["sans.perspectives.fitting"] = fitting_path |
---|
| 179 | package_dir["sans.perspectives.fitting.plugin_models"] = \ |
---|
| 180 | os.path.join(fitting_path, "plugin_models") |
---|
[8ca5890] | 181 | package_data['sans.perspectives.fitting'] = ['media/*','plugin_models/*'] |
---|
[8ab3302] | 182 | packages.extend(["sans.perspectives", "sans.perspectives.fitting", |
---|
| 183 | "sans.perspectives.fitting.plugin_models"]) |
---|
[d6bc28cf] | 184 | |
---|
| 185 | # Calculator view |
---|
| 186 | package_dir["sans.perspectives"] = "calculatorview/src/sans/perspectives" |
---|
[8ab3302] | 187 | package_dir["sans.perspectives.calculator"] = os.path.join("calculatorview", |
---|
| 188 | "src", "sans", "perspectives", "calculator") |
---|
[d6bc28cf] | 189 | package_data['sans.perspectives.calculator'] = ['images/*', 'media/*'] |
---|
| 190 | packages.extend(["sans.perspectives", "sans.perspectives.calculator"]) |
---|
| 191 | |
---|
| 192 | # Data util |
---|
| 193 | package_dir["data_util"] = "sansutil" |
---|
| 194 | packages.extend(["data_util"]) |
---|
| 195 | |
---|
| 196 | # Plottools |
---|
| 197 | package_dir["danse"] = os.path.join("plottools", "src", "danse") |
---|
[8ab3302] | 198 | package_dir["danse.common"] = os.path.join("plottools", "src", |
---|
| 199 | "danse", "common") |
---|
| 200 | package_dir["danse.common.plottools"] = os.path.join("plottools", |
---|
| 201 | "src", "danse", "common", "plottools") |
---|
[d6bc28cf] | 202 | packages.extend(["danse", "danse.common", "danse.common.plottools"]) |
---|
| 203 | |
---|
| 204 | # Park 1.2.1 |
---|
| 205 | package_dir["park"]="park-1.2.1/park" |
---|
| 206 | packages.extend(["park"]) |
---|
| 207 | package_data["park"] = ['park-1.2.1/*.txt', 'park-1.2.1/park.epydoc'] |
---|
| 208 | ext_modules.append( Extension("park._modeling", |
---|
[8ab3302] | 209 | sources = [ os.path.join("park-1.2.1", |
---|
| 210 | "park", "lib", "modeling.cc"), |
---|
| 211 | os.path.join("park-1.2.1", |
---|
| 212 | "park", "lib", "resolution.c"), |
---|
[29e96f3] | 213 | ], |
---|
| 214 | ) ) |
---|
[d6bc28cf] | 215 | |
---|
| 216 | # Sans models |
---|
[503a972] | 217 | includedir = os.path.join("sansmodels", "include") |
---|
[67424cd] | 218 | igordir = os.path.join("sansmodels", "src", "libigor") |
---|
| 219 | c_model_dir = os.path.join("sansmodels", "src", "c_models") |
---|
| 220 | smear_dir = os.path.join("sansmodels", "src", "c_smearer") |
---|
[318b5bbb] | 221 | gen_dir = os.path.join("sansmodels", "src", "c_gen") |
---|
[642a025] | 222 | wrapper_dir = os.path.join("sansmodels", "src", "python_wrapper", "generated") |
---|
[082c565] | 223 | model_dir = os.path.join("sansmodels", "src", "sans","models") |
---|
| 224 | |
---|
[78f74bd7] | 225 | if os.path.isdir(wrapper_dir): |
---|
| 226 | for file in os.listdir(wrapper_dir): |
---|
| 227 | file_path = os.path.join(wrapper_dir, file) |
---|
| 228 | os.remove(file_path) |
---|
| 229 | else: |
---|
[0ba3b08] | 230 | os.makedirs(wrapper_dir) |
---|
[642a025] | 231 | sys.path.append(os.path.join("sansmodels", "src", "python_wrapper")) |
---|
[2d1b700] | 232 | from wrapping import generate_wrappers |
---|
[082c565] | 233 | generate_wrappers(header_dir = includedir, |
---|
| 234 | output_dir = model_dir, |
---|
| 235 | c_wrapper_dir = wrapper_dir) |
---|
[2d1b700] | 236 | |
---|
[101065a] | 237 | IGNORED_FILES = [".svn"] |
---|
[9cde4cc] | 238 | if not os.name=='nt': |
---|
[2c63e80e] | 239 | IGNORED_FILES.extend(["gamma_win.c","winFuncs.c"]) |
---|
[9cde4cc] | 240 | |
---|
| 241 | |
---|
[d6bc28cf] | 242 | EXTENSIONS = [".c", ".cpp"] |
---|
| 243 | |
---|
| 244 | def append_file(file_list, dir_path): |
---|
| 245 | """ |
---|
| 246 | Add sources file to sources |
---|
| 247 | """ |
---|
| 248 | for f in os.listdir(dir_path): |
---|
| 249 | if os.path.isfile(os.path.join(dir_path, f)): |
---|
| 250 | _, ext = os.path.splitext(f) |
---|
| 251 | if ext.lower() in EXTENSIONS and f not in IGNORED_FILES: |
---|
| 252 | file_list.append(os.path.join(dir_path, f)) |
---|
| 253 | elif os.path.isdir(os.path.join(dir_path, f)) and \ |
---|
| 254 | not f.startswith("."): |
---|
| 255 | sub_dir = os.path.join(dir_path, f) |
---|
| 256 | for new_f in os.listdir(sub_dir): |
---|
| 257 | if os.path.isfile(os.path.join(sub_dir, new_f)): |
---|
| 258 | _, ext = os.path.splitext(new_f) |
---|
| 259 | if ext.lower() in EXTENSIONS and\ |
---|
| 260 | new_f not in IGNORED_FILES: |
---|
| 261 | file_list.append(os.path.join(sub_dir, new_f)) |
---|
| 262 | |
---|
| 263 | model_sources = [] |
---|
| 264 | append_file(file_list=model_sources, dir_path=igordir) |
---|
| 265 | append_file(file_list=model_sources, dir_path=c_model_dir) |
---|
[67424cd] | 266 | append_file(file_list=model_sources, dir_path=wrapper_dir) |
---|
| 267 | |
---|
[d6bc28cf] | 268 | smear_sources = [] |
---|
| 269 | append_file(file_list=smear_sources, dir_path=smear_dir) |
---|
| 270 | |
---|
| 271 | |
---|
| 272 | package_dir["sans"] = os.path.join("sansmodels", "src", "sans") |
---|
[082c565] | 273 | package_dir["sans.models"] = model_dir |
---|
| 274 | |
---|
[ea5fa58] | 275 | package_dir["sans.models.sans_extension"] = os.path.join("sansmodels", "src", |
---|
| 276 | "sans", "models", "sans_extension") |
---|
[d6bc28cf] | 277 | |
---|
[5a313a3] | 278 | package_data['sans.models'] = [os.path.join('media', "*.*")] |
---|
| 279 | package_data['sans.models'] += [os.path.join('media','img', "*.*")] |
---|
| 280 | |
---|
[d6bc28cf] | 281 | packages.extend(["sans","sans.models","sans.models.sans_extension"]) |
---|
| 282 | |
---|
[1d10ee9] | 283 | smearer_sources = [os.path.join(smear_dir, "smearer.cpp"), |
---|
| 284 | os.path.join(smear_dir, "smearer_module.cpp")] |
---|
[318b5bbb] | 285 | geni_sources = [os.path.join(gen_dir, "sld2i_module.cpp")] |
---|
[48b29eb] | 286 | if os.name=='nt': |
---|
[ef70686] | 287 | smearer_sources.append(os.path.join(igordir, "winFuncs.c")) |
---|
[318b5bbb] | 288 | geni_sources.append(os.path.join(igordir, "winFuncs.c")) |
---|
[d6bc28cf] | 289 | ext_modules.extend( [ Extension("sans.models.sans_extension.c_models", |
---|
| 290 | sources=model_sources, |
---|
[101065a] | 291 | include_dirs=[igordir, includedir, |
---|
[8ab3302] | 292 | c_model_dir, numpy_incl_path], |
---|
[29e96f3] | 293 | ), |
---|
[d6bc28cf] | 294 | # Smearer extension |
---|
| 295 | Extension("sans.models.sans_extension.smearer", |
---|
[1d10ee9] | 296 | sources = smearer_sources, |
---|
[8ab3302] | 297 | include_dirs=[igordir, |
---|
| 298 | smear_dir, numpy_incl_path], |
---|
[29e96f3] | 299 | ), |
---|
[d6bc28cf] | 300 | |
---|
| 301 | Extension("sans.models.sans_extension.smearer2d_helper", |
---|
| 302 | sources = [os.path.join(smear_dir, |
---|
[8ab3302] | 303 | "smearer2d_helper_module.cpp"), |
---|
| 304 | os.path.join(smear_dir, |
---|
| 305 | "smearer2d_helper.cpp"),], |
---|
[318b5bbb] | 306 | include_dirs=[smear_dir, numpy_incl_path], |
---|
| 307 | ), |
---|
| 308 | |
---|
| 309 | Extension("sans.models.sans_extension.sld2i", |
---|
| 310 | sources = [os.path.join(gen_dir, |
---|
| 311 | "sld2i_module.cpp"), |
---|
| 312 | os.path.join(gen_dir, |
---|
| 313 | "sld2i.cpp"), |
---|
| 314 | os.path.join(c_model_dir, |
---|
| 315 | "libfunc.c"), |
---|
| 316 | os.path.join(c_model_dir, |
---|
| 317 | "librefl.c"),], |
---|
| 318 | include_dirs=[gen_dir, includedir, |
---|
| 319 | c_model_dir, numpy_incl_path], |
---|
[29e96f3] | 320 | ) |
---|
[d6bc28cf] | 321 | ] ) |
---|
| 322 | |
---|
[c329f4d] | 323 | # SasView |
---|
[df7a7e3] | 324 | |
---|
[d6bc28cf] | 325 | package_dir["sans.sansview"] = "sansview" |
---|
[ea5fa58] | 326 | package_data['sans.sansview'] = ['images/*', 'media/*', 'test/*', |
---|
| 327 | 'default_categories.p'] |
---|
[d6bc28cf] | 328 | packages.append("sans.sansview") |
---|
| 329 | |
---|
[8ab3302] | 330 | #required = ['lxml>=2.2.2', 'numpy>=1.4.1', 'matplotlib>=0.99.1.1', |
---|
| 331 | # 'wxPython>=2.8.11', 'pil', |
---|
| 332 | # 'periodictable>=1.3.0', 'scipy>=0.7.2'] |
---|
[4793734] | 333 | required = ['lxml','periodictable>=1.3.0'] |
---|
[213b445] | 334 | |
---|
[95fe70d] | 335 | if os.name=='nt': |
---|
[7a211030] | 336 | required.extend(['html5lib', 'reportlab']) |
---|
[7f59928e] | 337 | else: |
---|
[202c1ef] | 338 | required.extend(['pil']) |
---|
[30ad350] | 339 | |
---|
[c329f4d] | 340 | # Set up SasView |
---|
[d6bc28cf] | 341 | setup( |
---|
[c329f4d] | 342 | name="sasview", |
---|
[5548954] | 343 | version = VERSION, |
---|
[c329f4d] | 344 | description = "SasView application", |
---|
[d6bc28cf] | 345 | author = "University of Tennessee", |
---|
| 346 | author_email = "sansdanse@gmail.com", |
---|
| 347 | url = "http://danse.chem.utk.edu", |
---|
| 348 | license = "PSF", |
---|
[c329f4d] | 349 | keywords = "small-angle x-ray and neutron scattering analysis", |
---|
[d6bc28cf] | 350 | download_url = "https://sourceforge.net/projects/sansviewproject/files/", |
---|
| 351 | package_dir = package_dir, |
---|
| 352 | packages = packages, |
---|
| 353 | package_data = package_data, |
---|
| 354 | ext_modules = ext_modules, |
---|
| 355 | install_requires = required, |
---|
[60f7d19] | 356 | zip_safe = False, |
---|
[a7b774d] | 357 | entry_points = { |
---|
| 358 | 'console_scripts':[ |
---|
| 359 | "sansview = sans.sansview.sansview:run", |
---|
| 360 | ] |
---|
[13f00a0] | 361 | }, |
---|
| 362 | cmdclass = {'build_ext': build_ext_subclass } |
---|
[d113531] | 363 | ) |
---|