[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 |
---|
[c8843be] | 7 | import shutil |
---|
[5980b1a] | 8 | from setuptools import setup, Extension |
---|
[2cef9d3] | 9 | from distutils.command.build_ext import build_ext |
---|
[968aa6e] | 10 | from distutils.core import Command |
---|
[18e7309] | 11 | import numpy |
---|
[d6bc28cf] | 12 | |
---|
[5548954] | 13 | # Manage version number ###################################### |
---|
[3a39c2e] | 14 | import sasview |
---|
| 15 | VERSION = sasview.__version__ |
---|
[5548954] | 16 | ############################################################## |
---|
| 17 | |
---|
[d6bc28cf] | 18 | package_dir = {} |
---|
| 19 | package_data = {} |
---|
| 20 | packages = [] |
---|
| 21 | ext_modules = [] |
---|
| 22 | |
---|
[8ab3302] | 23 | # Remove all files that should be updated by this setup |
---|
[3a39c2e] | 24 | # We do this here because application updates these files from .sasview |
---|
[8ab3302] | 25 | # except when there is no such file |
---|
| 26 | # Todo : make this list generic |
---|
[5881b17] | 27 | #plugin_model_list = ['polynominal5.py', 'sph_bessel_jn.py', |
---|
[a62945e] | 28 | # 'sum_Ap1_1_Ap2.py', 'sum_p1_p2.py', |
---|
| 29 | # 'testmodel_2.py', 'testmodel.py', |
---|
| 30 | # 'polynominal5.pyc', 'sph_bessel_jn.pyc', |
---|
| 31 | # 'sum_Ap1_1_Ap2.pyc', 'sum_p1_p2.pyc', |
---|
| 32 | # 'testmodel_2.pyc', 'testmodel.pyc', 'plugins.log'] |
---|
[c8843be] | 33 | |
---|
| 34 | CURRENT_SCRIPT_DIR = os.path.dirname(os.path.abspath(__file__)) |
---|
| 35 | SASVIEW_BUILD = os.path.join(CURRENT_SCRIPT_DIR, "build") |
---|
| 36 | |
---|
[3a39c2e] | 37 | sas_dir = os.path.join(os.path.expanduser("~"),'.sasview') |
---|
| 38 | if os.path.isdir(sas_dir): |
---|
| 39 | f_path = os.path.join(sas_dir, "sasview.log") |
---|
[e615a0d] | 40 | if os.path.isfile(f_path): |
---|
| 41 | os.remove(f_path) |
---|
[50008e3] | 42 | f_path = os.path.join(sas_dir, "categories.json") |
---|
[ea5fa58] | 43 | if os.path.isfile(f_path): |
---|
| 44 | os.remove(f_path) |
---|
[3a39c2e] | 45 | f_path = os.path.join(sas_dir, 'config', "custom_config.py") |
---|
[e615a0d] | 46 | if os.path.isfile(f_path): |
---|
| 47 | os.remove(f_path) |
---|
[5881b17] | 48 | #f_path = os.path.join(sas_dir, 'plugin_models') |
---|
| 49 | #if os.path.isdir(f_path): |
---|
[a62945e] | 50 | # for f in os.listdir(f_path): |
---|
| 51 | # if f in plugin_model_list: |
---|
| 52 | # file_path = os.path.join(f_path, f) |
---|
| 53 | # os.remove(file_path) |
---|
[c8843be] | 54 | if os.path.exists(SASVIEW_BUILD): |
---|
| 55 | print "Removing existing build directory", SASVIEW_BUILD, "for a clean build" |
---|
| 56 | shutil.rmtree(SASVIEW_BUILD) |
---|
[18e7309] | 57 | |
---|
[e615a0d] | 58 | # 'sys.maxsize' and 64bit: Not supported for python2.5 |
---|
| 59 | is_64bits = False |
---|
| 60 | if sys.version_info >= (2, 6): |
---|
| 61 | is_64bits = sys.maxsize > 2**32 |
---|
[18e7309] | 62 | |
---|
[7a04dbb] | 63 | enable_openmp = False |
---|
[e79a467] | 64 | |
---|
[f468791] | 65 | if sys.platform =='darwin': |
---|
| 66 | if not is_64bits: |
---|
| 67 | # Disable OpenMP |
---|
| 68 | enable_openmp = False |
---|
| 69 | else: |
---|
| 70 | # Newer versions of Darwin don't support openmp |
---|
| 71 | try: |
---|
| 72 | darwin_ver = int(os.uname()[2].split('.')[0]) |
---|
| 73 | if darwin_ver >= 12: |
---|
| 74 | enable_openmp = False |
---|
| 75 | except: |
---|
| 76 | print "PROBLEM determining Darwin version" |
---|
[b30ed8f] | 77 | |
---|
| 78 | # Options to enable OpenMP |
---|
| 79 | copt = {'msvc': ['/openmp'], |
---|
| 80 | 'mingw32' : ['-fopenmp'], |
---|
| 81 | 'unix' : ['-fopenmp']} |
---|
| 82 | lopt = {'msvc': ['/MANIFEST'], |
---|
| 83 | 'mingw32' : ['-fopenmp'], |
---|
| 84 | 'unix' : ['-lgomp']} |
---|
[13f00a0] | 85 | |
---|
[ebdb833] | 86 | # Platform-specific link options |
---|
| 87 | platform_lopt = {'msvc' : ['/MANIFEST']} |
---|
[307fa4f] | 88 | platform_copt = {} |
---|
[b9c8fc5] | 89 | |
---|
| 90 | # Set copts to get compile working on OS X >= 10.9 using clang |
---|
| 91 | if sys.platform =='darwin': |
---|
| 92 | try: |
---|
| 93 | darwin_ver = int(os.uname()[2].split('.')[0]) |
---|
[4adf48e] | 94 | if darwin_ver >= 13 and darwin_ver < 14: |
---|
[b9c8fc5] | 95 | platform_copt = {'unix' : ['-Wno-error=unused-command-line-argument-hard-error-in-future']} |
---|
| 96 | except: |
---|
| 97 | print "PROBLEM determining Darwin version" |
---|
| 98 | |
---|
[5972029] | 99 | class DisableOpenMPCommand(Command): |
---|
| 100 | description = "The version of MinGW that comes with Anaconda does not come with OpenMP :( "\ |
---|
| 101 | "This commands means we can turn off compiling with OpenMP for this or any "\ |
---|
| 102 | "other reason." |
---|
| 103 | user_options = [] |
---|
| 104 | |
---|
| 105 | def initialize_options(self): |
---|
| 106 | self.cwd = None |
---|
| 107 | |
---|
| 108 | def finalize_options(self): |
---|
| 109 | self.cwd = os.getcwd() |
---|
| 110 | global enable_openmp |
---|
| 111 | enable_openmp = False |
---|
[1829835] | 112 | |
---|
[5972029] | 113 | def run(self): |
---|
| 114 | pass |
---|
[ebdb833] | 115 | |
---|
[13f00a0] | 116 | class build_ext_subclass( build_ext ): |
---|
| 117 | def build_extensions(self): |
---|
| 118 | # Get 64-bitness |
---|
| 119 | c = self.compiler.compiler_type |
---|
| 120 | print "Compiling with %s (64bit=%s)" % (c, str(is_64bits)) |
---|
[18e7309] | 121 | |
---|
[ebdb833] | 122 | # OpenMP build options |
---|
[b30ed8f] | 123 | if enable_openmp: |
---|
[13f00a0] | 124 | if copt.has_key(c): |
---|
[5980b1a] | 125 | for e in self.extensions: |
---|
| 126 | e.extra_compile_args = copt[ c ] |
---|
[13f00a0] | 127 | if lopt.has_key(c): |
---|
| 128 | for e in self.extensions: |
---|
| 129 | e.extra_link_args = lopt[ c ] |
---|
[18e7309] | 130 | |
---|
[ebdb833] | 131 | # Platform-specific build options |
---|
| 132 | if platform_lopt.has_key(c): |
---|
| 133 | for e in self.extensions: |
---|
| 134 | e.extra_link_args = platform_lopt[ c ] |
---|
| 135 | |
---|
[1829835] | 136 | if platform_copt.has_key(c): |
---|
| 137 | for e in self.extensions: |
---|
| 138 | e.extra_compile_args = platform_copt[ c ] |
---|
| 139 | |
---|
| 140 | |
---|
[13f00a0] | 141 | build_ext.build_extensions(self) |
---|
[d6bc28cf] | 142 | |
---|
[968aa6e] | 143 | class BuildSphinxCommand(Command): |
---|
| 144 | description = "Build Sphinx documentation." |
---|
| 145 | user_options = [] |
---|
| 146 | |
---|
| 147 | def initialize_options(self): |
---|
| 148 | self.cwd = None |
---|
| 149 | |
---|
| 150 | def finalize_options(self): |
---|
| 151 | self.cwd = os.getcwd() |
---|
| 152 | |
---|
[d8c4019] | 153 | def run(self): |
---|
| 154 | sys.path.append("docs/sphinx-docs") |
---|
| 155 | import build_sphinx |
---|
[c2ee2b1] | 156 | build_sphinx.rebuild() |
---|
[968aa6e] | 157 | |
---|
[3a39c2e] | 158 | # sas module |
---|
| 159 | package_dir["sas"] = os.path.join("src", "sas") |
---|
| 160 | packages.append("sas") |
---|
[29e96f3] | 161 | |
---|
[e0bbb7c] | 162 | # sas module |
---|
| 163 | package_dir["sas.sasgui"] = os.path.join("src", "sas", "sasgui") |
---|
| 164 | packages.append("sas.sasgui") |
---|
| 165 | |
---|
| 166 | # sas module |
---|
| 167 | package_dir["sas.sascalc"] = os.path.join("src", "sas", "sascalc") |
---|
| 168 | packages.append("sas.sascalc") |
---|
| 169 | |
---|
| 170 | # sas.sascalc.invariant |
---|
| 171 | package_dir["sas.sascalc.invariant"] = os.path.join("src", "sas", "sascalc", "invariant") |
---|
| 172 | packages.extend(["sas.sascalc.invariant"]) |
---|
[d6bc28cf] | 173 | |
---|
[d85c194] | 174 | # sas.sasgui.guiframe |
---|
| 175 | guiframe_path = os.path.join("src", "sas", "sasgui", "guiframe") |
---|
| 176 | package_dir["sas.sasgui.guiframe"] = guiframe_path |
---|
| 177 | package_dir["sas.sasgui.guiframe.local_perspectives"] = os.path.join(os.path.join(guiframe_path, "local_perspectives")) |
---|
| 178 | package_data["sas.sasgui.guiframe"] = ['images/*', 'media/*'] |
---|
| 179 | packages.extend(["sas.sasgui.guiframe", "sas.sasgui.guiframe.local_perspectives"]) |
---|
[d6bc28cf] | 180 | # build local plugin |
---|
[5980b1a] | 181 | for d in os.listdir(os.path.join(guiframe_path, "local_perspectives")): |
---|
| 182 | if d not in ['.svn','__init__.py', '__init__.pyc']: |
---|
[d85c194] | 183 | package_name = "sas.sasgui.guiframe.local_perspectives." + d |
---|
[3d24489] | 184 | packages.append(package_name) |
---|
[5980b1a] | 185 | package_dir[package_name] = os.path.join(guiframe_path, "local_perspectives", d) |
---|
[d6bc28cf] | 186 | |
---|
[e0bbb7c] | 187 | # sas.sascalc.dataloader |
---|
| 188 | package_dir["sas.sascalc.dataloader"] = os.path.join("src", "sas", "sascalc", "dataloader") |
---|
| 189 | package_data["sas.sascalc.dataloader.readers"] = ['defaults.json','schema/*.xsd'] |
---|
| 190 | packages.extend(["sas.sascalc.dataloader","sas.sascalc.dataloader.readers","sas.sascalc.dataloader.readers.schema"]) |
---|
[d6bc28cf] | 191 | |
---|
[e0bbb7c] | 192 | # sas.sascalc.calculator |
---|
[9e531f2] | 193 | gen_dir = os.path.join("src", "sas", "sascalc", "calculator", "c_extensions") |
---|
| 194 | package_dir["sas.sascalc.calculator.core"] = gen_dir |
---|
| 195 | package_dir["sas.sascalc.calculator"] = os.path.join("src", "sas", "sascalc", "calculator") |
---|
| 196 | packages.extend(["sas.sascalc.calculator","sas.sascalc.calculator.core"]) |
---|
| 197 | ext_modules.append( Extension("sas.sascalc.calculator.core.sld2i", |
---|
| 198 | sources = [ |
---|
| 199 | os.path.join(gen_dir, "sld2i_module.cpp"), |
---|
| 200 | os.path.join(gen_dir, "sld2i.cpp"), |
---|
| 201 | os.path.join(gen_dir, "libfunc.c"), |
---|
| 202 | os.path.join(gen_dir, "librefl.c"), |
---|
| 203 | ], |
---|
[f567f92f] | 204 | include_dirs=[gen_dir], |
---|
[9e531f2] | 205 | ) |
---|
| 206 | ) |
---|
| 207 | |
---|
[b699768] | 208 | # sas.sascalc.pr |
---|
| 209 | srcdir = os.path.join("src", "sas", "sascalc", "pr", "c_extensions") |
---|
| 210 | package_dir["sas.sascalc.pr.core"] = srcdir |
---|
| 211 | package_dir["sas.sascalc.pr"] = os.path.join("src","sas", "sascalc", "pr") |
---|
| 212 | packages.extend(["sas.sascalc.pr","sas.sascalc.pr.core"]) |
---|
| 213 | ext_modules.append( Extension("sas.sascalc.pr.core.pr_inversion", |
---|
[3d24489] | 214 | sources = [os.path.join(srcdir, "Cinvertor.c"), |
---|
[29e96f3] | 215 | os.path.join(srcdir, "invertor.c"), |
---|
| 216 | ], |
---|
[f567f92f] | 217 | include_dirs=[], |
---|
[29e96f3] | 218 | ) ) |
---|
[18e7309] | 219 | |
---|
| 220 | # sas.sascalc.file_converter |
---|
| 221 | mydir = os.path.join("src", "sas", "sascalc", "file_converter", "c_ext") |
---|
| 222 | package_dir["sas.sascalc.file_converter.core"] = mydir |
---|
| 223 | package_dir["sas.sascalc.file_converter"] = os.path.join("src","sas", "sascalc", "file_converter") |
---|
| 224 | packages.extend(["sas.sascalc.file_converter","sas.sascalc.file_converter.core"]) |
---|
| 225 | ext_modules.append( Extension("sas.sascalc.file_converter.core.bsl_loader", |
---|
| 226 | sources = [os.path.join(mydir, "bsl_loader.c")], |
---|
| 227 | include_dirs=[numpy.get_include()], |
---|
| 228 | ) ) |
---|
| 229 | |
---|
[1e13b53] | 230 | #sas.sascalc.corfunc |
---|
| 231 | package_dir["sas.sascalc.corfunc"] = os.path.join("src", "sas", "sascalc", "corfunc") |
---|
| 232 | packages.extend(["sas.sascalc.corfunc"]) |
---|
| 233 | |
---|
[b699768] | 234 | # sas.sascalc.fit |
---|
| 235 | package_dir["sas.sascalc.fit"] = os.path.join("src", "sas", "sascalc", "fit") |
---|
| 236 | packages.append("sas.sascalc.fit") |
---|
[3d24489] | 237 | |
---|
| 238 | # Perspectives |
---|
[d85c194] | 239 | package_dir["sas.sasgui.perspectives"] = os.path.join("src", "sas", "sasgui", "perspectives") |
---|
| 240 | package_dir["sas.sasgui.perspectives.pr"] = os.path.join("src", "sas", "sasgui", "perspectives", "pr") |
---|
| 241 | packages.extend(["sas.sasgui.perspectives","sas.sasgui.perspectives.pr"]) |
---|
[1e13b53] | 242 | package_data["sas.sasgui.perspectives.pr"] = ['media/*'] |
---|
[d85c194] | 243 | |
---|
| 244 | package_dir["sas.sasgui.perspectives.invariant"] = os.path.join("src", "sas", "sasgui", "perspectives", "invariant") |
---|
| 245 | packages.extend(["sas.sasgui.perspectives.invariant"]) |
---|
| 246 | package_data['sas.sasgui.perspectives.invariant'] = [os.path.join("media",'*')] |
---|
| 247 | |
---|
| 248 | package_dir["sas.sasgui.perspectives.fitting"] = os.path.join("src", "sas", "sasgui", "perspectives", "fitting") |
---|
[a7c4ad2] | 249 | package_dir["sas.sasgui.perspectives.fitting.plugin_models"] = os.path.join("src", "sas", "sasgui", "perspectives", "fitting", "plugin_models") |
---|
| 250 | packages.extend(["sas.sasgui.perspectives.fitting", "sas.sasgui.perspectives.fitting.plugin_models"]) |
---|
| 251 | package_data['sas.sasgui.perspectives.fitting'] = ['media/*', 'plugin_models/*'] |
---|
[d85c194] | 252 | |
---|
[9e531f2] | 253 | packages.extend(["sas.sasgui.perspectives", "sas.sasgui.perspectives.calculator"]) |
---|
[d85c194] | 254 | package_data['sas.sasgui.perspectives.calculator'] = ['images/*', 'media/*'] |
---|
[18e7309] | 255 | |
---|
[1e13b53] | 256 | package_dir["sas.sasgui.perspectives.corfunc"] = os.path.join("src", "sas", "sasgui", "perspectives", "corfunc") |
---|
| 257 | packages.extend(["sas.sasgui.perspectives.corfunc"]) |
---|
| 258 | package_data['sas.sasgui.perspectives.corfunc'] = ['media/*'] |
---|
| 259 | |
---|
| 260 | package_dir["sas.sasgui.perspectives.file_converter"] = os.path.join("src", "sas", "sasgui", "perspectives", "file_converter") |
---|
| 261 | packages.extend(["sas.sasgui.perspectives.file_converter"]) |
---|
| 262 | package_data['sas.sasgui.perspectives.file_converter'] = ['media/*'] |
---|
| 263 | |
---|
[d6bc28cf] | 264 | # Data util |
---|
[e0bbb7c] | 265 | package_dir["sas.sascalc.data_util"] = os.path.join("src", "sas", "sascalc", "data_util") |
---|
[b699768] | 266 | packages.append("sas.sascalc.data_util") |
---|
[d6bc28cf] | 267 | |
---|
| 268 | # Plottools |
---|
[d7bb526] | 269 | package_dir["sas.sasgui.plottools"] = os.path.join("src", "sas", "sasgui", "plottools") |
---|
| 270 | packages.append("sas.sasgui.plottools") |
---|
[d6bc28cf] | 271 | |
---|
[9274711] | 272 | # # Last of the sas.models |
---|
| 273 | # package_dir["sas.models"] = os.path.join("src", "sas", "models") |
---|
| 274 | # packages.append("sas.models") |
---|
[2d1b700] | 275 | |
---|
[d6bc28cf] | 276 | EXTENSIONS = [".c", ".cpp"] |
---|
| 277 | |
---|
| 278 | def append_file(file_list, dir_path): |
---|
| 279 | """ |
---|
| 280 | Add sources file to sources |
---|
| 281 | """ |
---|
| 282 | for f in os.listdir(dir_path): |
---|
| 283 | if os.path.isfile(os.path.join(dir_path, f)): |
---|
| 284 | _, ext = os.path.splitext(f) |
---|
[4c29e4d] | 285 | if ext.lower() in EXTENSIONS: |
---|
[9e531f2] | 286 | file_list.append(os.path.join(dir_path, f)) |
---|
[d6bc28cf] | 287 | elif os.path.isdir(os.path.join(dir_path, f)) and \ |
---|
| 288 | not f.startswith("."): |
---|
| 289 | sub_dir = os.path.join(dir_path, f) |
---|
| 290 | for new_f in os.listdir(sub_dir): |
---|
| 291 | if os.path.isfile(os.path.join(sub_dir, new_f)): |
---|
| 292 | _, ext = os.path.splitext(new_f) |
---|
[4c29e4d] | 293 | if ext.lower() in EXTENSIONS: |
---|
[9e531f2] | 294 | file_list.append(os.path.join(sub_dir, new_f)) |
---|
[820df88] | 295 | |
---|
| 296 | # Comment out the following to avoid rebuilding all the models |
---|
[9e531f2] | 297 | file_sources = [] |
---|
| 298 | append_file(file_sources, gen_dir) |
---|
[820df88] | 299 | |
---|
[5881b17] | 300 | #Wojtek's hacky way to add doc files while bundling egg |
---|
| 301 | #def add_doc_files(directory): |
---|
| 302 | # paths = [] |
---|
| 303 | # for (path, directories, filenames) in os.walk(directory): |
---|
| 304 | # for filename in filenames: |
---|
| 305 | # paths.append(os.path.join(path, filename)) |
---|
| 306 | # return paths |
---|
| 307 | |
---|
| 308 | #doc_files = add_doc_files('doc') |
---|
| 309 | |
---|
[c329f4d] | 310 | # SasView |
---|
[3a39c2e] | 311 | package_dir["sas.sasview"] = "sasview" |
---|
[5881b17] | 312 | package_data['sas.sasview'] = ['images/*', |
---|
[bbb8a56] | 313 | 'media/*', |
---|
[d4c88e24] | 314 | 'test/*.txt', |
---|
[bbb8a56] | 315 | 'test/1d_data/*', |
---|
| 316 | 'test/2d_data/*', |
---|
| 317 | 'test/save_states/*', |
---|
[18e7309] | 318 | 'test/upcoming_formats/*', |
---|
[27b7acc] | 319 | 'default_categories.json'] |
---|
[3a39c2e] | 320 | packages.append("sas.sasview") |
---|
[d6bc28cf] | 321 | |
---|
[9f32c57] | 322 | required = [ |
---|
[243fbc0] | 323 | 'bumps>=0.7.5.9', 'periodictable>=1.3.1', 'pyparsing<2.0.0', |
---|
[9f32c57] | 324 | |
---|
| 325 | # 'lxml>=2.2.2', |
---|
[db74ee8] | 326 | 'lxml', 'h5py', |
---|
[9f32c57] | 327 | |
---|
| 328 | ## The following dependecies won't install automatically, so assume them |
---|
| 329 | ## The numbers should be bumped up for matplotlib and wxPython as well. |
---|
| 330 | # 'numpy>=1.4.1', 'scipy>=0.7.2', 'matplotlib>=0.99.1.1', |
---|
| 331 | # 'wxPython>=2.8.11', 'pil', |
---|
| 332 | ] |
---|
[213b445] | 333 | |
---|
[95fe70d] | 334 | if os.name=='nt': |
---|
[7a211030] | 335 | required.extend(['html5lib', 'reportlab']) |
---|
[7f59928e] | 336 | else: |
---|
[775d06f] | 337 | # 'pil' is now called 'pillow' |
---|
[5f6336f] | 338 | required.extend(['pillow']) |
---|
[5881b17] | 339 | |
---|
[18e7309] | 340 | # Set up SasView |
---|
[d6bc28cf] | 341 | setup( |
---|
[c329f4d] | 342 | name="sasview", |
---|
[5548954] | 343 | version = VERSION, |
---|
[c329f4d] | 344 | description = "SasView application", |
---|
[038ccfe6] | 345 | author = "SasView Team", |
---|
| 346 | author_email = "developers@sasview.org", |
---|
[5980b1a] | 347 | url = "http://sasview.org", |
---|
[d6bc28cf] | 348 | license = "PSF", |
---|
[c329f4d] | 349 | keywords = "small-angle x-ray and neutron scattering analysis", |
---|
[038ccfe6] | 350 | download_url = "https://github.com/SasView/sasview.git", |
---|
[d6bc28cf] | 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':[ |
---|
[3a39c2e] | 359 | "sasview = sas.sasview.sasview:run", |
---|
[a7b774d] | 360 | ] |
---|
[13f00a0] | 361 | }, |
---|
[968aa6e] | 362 | cmdclass = {'build_ext': build_ext_subclass, |
---|
[5972029] | 363 | 'docs': BuildSphinxCommand, |
---|
| 364 | 'disable_openmp': DisableOpenMPCommand} |
---|
[18e7309] | 365 | ) |
---|