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