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