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