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