[2eeca83] | 1 | #!/usr/bin/env python |
---|
| 2 | |
---|
| 3 | # |
---|
| 4 | # The setup to create a Windows executable. |
---|
| 5 | # Inno Setup can then be used with the installer.iss file |
---|
| 6 | # in the top source directory to create an installer. |
---|
| 7 | # |
---|
| 8 | # Setuptools clashes with py2exe 0.6.8 (and probably later too). |
---|
| 9 | # For that reason, most of the code needs to have direct imports |
---|
| 10 | # that are not going through pkg_resources. |
---|
| 11 | # |
---|
| 12 | # Attention should be paid to dynamic imports. Data files can |
---|
| 13 | # be added to the distribution directory for that purpose. |
---|
| 14 | # See for example the 'images' directory below. |
---|
| 15 | |
---|
[c971c98] | 16 | import os |
---|
| 17 | import sys |
---|
[2eeca83] | 18 | |
---|
| 19 | # put the build directory at the front of the path |
---|
| 20 | if os.path.abspath(os.path.dirname(__file__)) != os.path.abspath(os.getcwd()): |
---|
| 21 | raise RuntimeError("Must run setup_exe from the sasview directory") |
---|
| 22 | from distutils.util import get_platform |
---|
| 23 | root = os.path.dirname(os.path.dirname(os.path.abspath(__file__))) |
---|
[c971c98] | 24 | platform = '%s-%s'%(get_platform(), sys.version[:3]) |
---|
| 25 | build_path = os.path.join(root, 'build', 'lib.'+platform) |
---|
[2eeca83] | 26 | sys.path.insert(0, build_path) |
---|
| 27 | |
---|
| 28 | import local_config |
---|
| 29 | |
---|
| 30 | if len(sys.argv) == 1: |
---|
| 31 | sys.argv.append('py2exe') |
---|
| 32 | # When using the SasView build script, we need to be able to pass |
---|
| 33 | # an extra path to be added to the python path. The extra arguments |
---|
| 34 | # should be removed from the list so that the setup processing doesn't |
---|
| 35 | # fail. |
---|
| 36 | try: |
---|
| 37 | if sys.argv.count('--extrapath'): |
---|
| 38 | path_flag_idx = sys.argv.index('--extrapath') |
---|
| 39 | extra_path = sys.argv[path_flag_idx+1] |
---|
| 40 | sys.path.insert(0, extra_path) |
---|
| 41 | del sys.argv[path_flag_idx+1] |
---|
| 42 | sys.argv.remove('--extrapath') |
---|
| 43 | except: |
---|
| 44 | print "Error processing extra python path needed to build SasView\n %s" % \ |
---|
| 45 | sys.exc_value |
---|
| 46 | |
---|
| 47 | from distutils.core import setup |
---|
| 48 | from distutils.filelist import findall |
---|
| 49 | import matplotlib |
---|
| 50 | |
---|
| 51 | # Solution taken from here: http://www.py2exe.org/index.cgi/win32com.shell |
---|
| 52 | # ModuleFinder can't handle runtime changes to __path__, but win32com uses them |
---|
| 53 | win32_folder = "win32comext" |
---|
| 54 | try: |
---|
| 55 | # py2exe 0.6.4 introduced a replacement modulefinder. |
---|
| 56 | # This means we have to add package paths there, not to the built-in |
---|
| 57 | # one. If this new modulefinder gets integrated into Python, then |
---|
| 58 | # we might be able to revert this some day. |
---|
| 59 | # if this doesn't work, try import modulefinder |
---|
| 60 | try: |
---|
| 61 | import py2exe.mf as modulefinder |
---|
| 62 | except ImportError: |
---|
| 63 | import modulefinder |
---|
[c971c98] | 64 | import win32com |
---|
[2eeca83] | 65 | for p in win32com.__path__[1:]: |
---|
| 66 | modulefinder.AddPackagePath(win32_folder, p) |
---|
| 67 | for extra in ["win32com.shell", "win32com.adsi", "win32com.axcontrol", |
---|
| 68 | "win32com.axscript", "win32com.bits", "win32com.ifilter", |
---|
| 69 | "win32com.internet", "win32com.mapi", "win32com.propsys", |
---|
| 70 | "win32com.taskscheduler"]: |
---|
| 71 | |
---|
| 72 | __import__(extra) |
---|
| 73 | m = sys.modules[extra] |
---|
| 74 | for p in m.__path__[1:]: |
---|
| 75 | modulefinder.AddPackagePath(extra, p) |
---|
| 76 | |
---|
| 77 | except ImportError: |
---|
| 78 | # no build path setup, no worries. |
---|
| 79 | pass |
---|
| 80 | |
---|
| 81 | import py2exe |
---|
| 82 | import shutil |
---|
| 83 | # Remove the build folder |
---|
| 84 | shutil.rmtree("build", ignore_errors=True) |
---|
| 85 | # do the same for dist folder |
---|
| 86 | shutil.rmtree("dist", ignore_errors=True) |
---|
| 87 | |
---|
| 88 | if sys.version_info < (2, 6): |
---|
| 89 | is_64bits = False |
---|
| 90 | origIsSystemDLL = py2exe.build_exe.isSystemDLL |
---|
| 91 | def isSystemDLL(pathname): |
---|
| 92 | if os.path.basename(pathname).lower() in ("msvcp71.dll", "comctl32.dll"): |
---|
| 93 | return 0 |
---|
| 94 | return origIsSystemDLL(pathname) |
---|
| 95 | py2exe.build_exe.isSystemDLL = isSystemDLL |
---|
| 96 | else: |
---|
| 97 | is_64bits = sys.maxsize > 2**32 |
---|
| 98 | |
---|
| 99 | if is_64bits and sys.version_info >= (2, 6): |
---|
| 100 | manifest = """ |
---|
| 101 | <?xml version="1.0" encoding="UTF-8" standalone="yes"?> |
---|
| 102 | <assembly xmlns="urn:schemas-microsoft-com:asm.v1" |
---|
| 103 | manifestVersion="1.0"> |
---|
| 104 | <assemblyIdentity |
---|
| 105 | version="0.64.1.0" |
---|
| 106 | processorArchitecture="amd64" |
---|
| 107 | name="Controls" |
---|
| 108 | type="win32" |
---|
| 109 | /> |
---|
| 110 | <description>SasView</description> |
---|
| 111 | <dependency> |
---|
| 112 | <dependentAssembly> |
---|
| 113 | <assemblyIdentity |
---|
| 114 | type="win32" |
---|
| 115 | name="Microsoft.Windows.Common-Controls" |
---|
| 116 | version="6.0.0.0" |
---|
| 117 | processorArchitecture="amd64" |
---|
| 118 | publicKeyToken="6595b64144ccf1df" |
---|
| 119 | language="*" |
---|
| 120 | /> |
---|
| 121 | </dependentAssembly> |
---|
| 122 | </dependency> |
---|
| 123 | </assembly> |
---|
| 124 | """ |
---|
| 125 | else: |
---|
| 126 | manifest_for_python26 = """ |
---|
| 127 | <?xml version="1.0" encoding="UTF-8" standalone="yes"?> |
---|
| 128 | <assembly xmlns="urn:schemas-microsoft-com:asm.v1" manifestVersion="1.0"> |
---|
| 129 | <assemblyIdentity |
---|
| 130 | version="5.0.0.0" |
---|
| 131 | processorArchitecture="x86" |
---|
| 132 | name="SasView" |
---|
| 133 | type="win32"> |
---|
| 134 | </assemblyIdentity> |
---|
| 135 | <description>SasView</description> |
---|
| 136 | <trustInfo xmlns="urn:schemas-microsoft-com:asm.v3"> |
---|
| 137 | <security> |
---|
| 138 | <requestedPrivileges> |
---|
| 139 | <requestedExecutionLevel |
---|
| 140 | level="asInvoker" |
---|
| 141 | uiAccess="false"> |
---|
| 142 | </requestedExecutionLevel> |
---|
| 143 | </requestedPrivileges> |
---|
| 144 | </security> |
---|
| 145 | </trustInfo> |
---|
| 146 | <dependency> |
---|
| 147 | <dependentAssembly> |
---|
| 148 | <assemblyIdentity |
---|
| 149 | type="win32" |
---|
| 150 | name="Microsoft.VC90.CRT" |
---|
| 151 | version="9.0.21022.8" |
---|
| 152 | processorArchitecture="x86" |
---|
| 153 | publicKeyToken="1fc8b3b9a1e18e3b"> |
---|
| 154 | </assemblyIdentity> |
---|
| 155 | </dependentAssembly> |
---|
| 156 | </dependency> |
---|
| 157 | <dependency> |
---|
| 158 | <dependentAssembly> |
---|
| 159 | <assemblyIdentity |
---|
| 160 | type="win32" |
---|
| 161 | name="Microsoft.Windows.Common-Controls" |
---|
| 162 | version="6.0.0.0" |
---|
| 163 | processorArchitecture="x86" |
---|
| 164 | publicKeyToken="6595b64144ccf1df" |
---|
| 165 | language="*"> |
---|
| 166 | </assemblyIdentity> |
---|
| 167 | </dependentAssembly> |
---|
| 168 | </dependency> |
---|
| 169 | </assembly> |
---|
| 170 | """ |
---|
| 171 | manifest_for_python25 = """ |
---|
| 172 | <?xml version="1.0" encoding="UTF-8" standalone="yes"?> |
---|
| 173 | <assembly xmlns="urn:schemas-microsoft-com:asm.v1" |
---|
| 174 | manifestVersion="1.0"> |
---|
| 175 | <assemblyIdentity |
---|
| 176 | version="0.64.1.0" |
---|
| 177 | processorArchitecture="x86" |
---|
| 178 | name="Controls" |
---|
| 179 | type="win32" |
---|
| 180 | /> |
---|
| 181 | <description>SasView</description> |
---|
| 182 | <dependency> |
---|
| 183 | <dependentAssembly> |
---|
| 184 | <assemblyIdentity |
---|
| 185 | type="win32" |
---|
| 186 | name="Microsoft.Windows.Common-Controls" |
---|
| 187 | version="6.0.0.0" |
---|
| 188 | processorArchitecture="X86" |
---|
| 189 | publicKeyToken="6595b64144ccf1df" |
---|
| 190 | language="*" |
---|
| 191 | /> |
---|
| 192 | </dependentAssembly> |
---|
| 193 | </dependency> |
---|
| 194 | </assembly> |
---|
| 195 | """ |
---|
| 196 | |
---|
| 197 | # Select the appropriate manifest to use. |
---|
| 198 | py26MSdll_x86 = None |
---|
[6a698c0] | 199 | if sys.version_info >= (3, 0) or sys.version_info < (2, 6): |
---|
| 200 | print "*** This script only works with Python 2.6 or 2.7." |
---|
[2eeca83] | 201 | sys.exit() |
---|
| 202 | elif sys.version_info >= (2, 6): |
---|
| 203 | manifest = manifest_for_python26 |
---|
| 204 | from glob import glob |
---|
| 205 | py26MSdll = glob(r"C:\Program Files\Microsoft Visual Studio 9.0\VC\redist\x86\Microsoft.VC90.CRT\*.*") |
---|
| 206 | try: |
---|
| 207 | py26MSdll_x86 = glob(r"C:\Program Files (x86)\Microsoft Visual Studio 9.0\VC\redist\x86\Microsoft.VC90.CRT\*.*") |
---|
| 208 | except: |
---|
| 209 | pass |
---|
[c971c98] | 210 | |
---|
| 211 | |
---|
[2eeca83] | 212 | class Target: |
---|
| 213 | def __init__(self, **kw): |
---|
| 214 | self.__dict__.update(kw) |
---|
| 215 | # for the versioninfo resources |
---|
| 216 | self.version = local_config.__version__ |
---|
| 217 | self.company_name = "SasView.org" |
---|
| 218 | self.copyright = "copyright 2009 - 2013" |
---|
| 219 | self.name = "SasView" |
---|
| 220 | |
---|
| 221 | # |
---|
| 222 | # Adapted from http://www.py2exe.org/index.cgi/MatPlotLib |
---|
| 223 | # to use the MatPlotLib. |
---|
| 224 | # |
---|
| 225 | path = os.getcwd() |
---|
| 226 | |
---|
| 227 | media_dir = os.path.join(path, "media") |
---|
| 228 | images_dir = os.path.join(path, "images") |
---|
| 229 | test_dir = os.path.join(path, "test") |
---|
[0c17d96] | 230 | test_1d_dir = os.path.join(path, "test\\1d_data") |
---|
| 231 | test_2d_dir = os.path.join(path, "test\\2d_data") |
---|
| 232 | test_save_dir = os.path.join(path, "test\\save_states") |
---|
| 233 | test_upcoming_dir = os.path.join(path, "test\\upcoming_formats") |
---|
[2eeca83] | 234 | |
---|
| 235 | matplotlibdatadir = matplotlib.get_data_path() |
---|
| 236 | matplotlibdata = findall(matplotlibdatadir) |
---|
| 237 | data_files = [] |
---|
| 238 | # Copying SLD data |
---|
| 239 | import periodictable |
---|
| 240 | import logging |
---|
| 241 | data_files += periodictable.data_files() |
---|
| 242 | |
---|
[d85c194] | 243 | import sas.sasgui.perspectives.fitting as fitting |
---|
[2eeca83] | 244 | data_files += fitting.data_files() |
---|
| 245 | |
---|
[d85c194] | 246 | import sas.sasgui.perspectives.calculator as calculator |
---|
[2eeca83] | 247 | data_files += calculator.data_files() |
---|
| 248 | |
---|
[d85c194] | 249 | import sas.sasgui.perspectives.invariant as invariant |
---|
[2eeca83] | 250 | data_files += invariant.data_files() |
---|
| 251 | |
---|
[d85c194] | 252 | import sas.sasgui.guiframe as guiframe |
---|
[2eeca83] | 253 | data_files += guiframe.data_files() |
---|
| 254 | |
---|
[6a698c0] | 255 | # precompile sas models into the sasview build path; doesn't matter too much |
---|
| 256 | # where it is so long as it is a place that will get cleaned up afterwards. |
---|
| 257 | import sasmodels.core |
---|
| 258 | dll_path = os.path.join(build_path, 'compiled_models') |
---|
| 259 | compiled_dlls += sasmodels.core.precompile_dlls(dll_path, dtype='double') |
---|
| 260 | |
---|
| 261 | # include the compiled models as data; coordinate the target path for the |
---|
| 262 | # data with installer_generator.py |
---|
| 263 | datafiles.append('compiled_models', compiled_dlls) |
---|
| 264 | |
---|
| 265 | import sasmodels |
---|
| 266 | data_files += sasmodels.data_files() |
---|
[2eeca83] | 267 | |
---|
| 268 | for f in matplotlibdata: |
---|
| 269 | dirname = os.path.join('mpl-data', f[len(matplotlibdatadir)+1:]) |
---|
| 270 | data_files.append((os.path.split(dirname)[0], [f])) |
---|
| 271 | |
---|
| 272 | # Copy the settings file for the sas.dataloader file extension associations |
---|
[b699768] | 273 | import sas.sascalc.dataloader.readers |
---|
[40fc798] | 274 | f = os.path.join(sas.sascalc.dataloader.readers.get_data_path(), 'defaults.json') |
---|
[2eeca83] | 275 | if os.path.isfile(f): |
---|
| 276 | data_files.append(('.', [f])) |
---|
| 277 | f = 'custom_config.py' |
---|
| 278 | if os.path.isfile(f): |
---|
| 279 | data_files.append(('.', [f])) |
---|
| 280 | data_files.append(('config', [f])) |
---|
| 281 | f = 'local_config.py' |
---|
| 282 | if os.path.isfile(f): |
---|
| 283 | data_files.append(('.', [f])) |
---|
| 284 | |
---|
| 285 | f = 'default_categories.json' |
---|
| 286 | if os.path.isfile(f): |
---|
| 287 | data_files.append(('.', [f])) |
---|
| 288 | |
---|
| 289 | if os.path.isfile("BUILD_NUMBER"): |
---|
[c971c98] | 290 | data_files.append(('.', ["BUILD_NUMBER"])) |
---|
[2eeca83] | 291 | |
---|
| 292 | # Copying the images directory to the distribution directory. |
---|
| 293 | for f in findall(images_dir): |
---|
| 294 | if not ".svn" in f: |
---|
| 295 | data_files.append(("images", [f])) |
---|
| 296 | |
---|
| 297 | # Copying the HTML help docs |
---|
| 298 | for f in findall(media_dir): |
---|
| 299 | if not ".svn" in f: |
---|
| 300 | data_files.append(("media", [f])) |
---|
| 301 | |
---|
| 302 | # Copying the sample data user data |
---|
[0c17d96] | 303 | for f in findall(test_1d_dir): |
---|
[2eeca83] | 304 | if not ".svn" in f: |
---|
[0c17d96] | 305 | data_files.append(("test\\1d_data", [f])) |
---|
| 306 | |
---|
| 307 | # Copying the sample data user data |
---|
| 308 | for f in findall(test_2d_dir): |
---|
| 309 | if not ".svn" in f: |
---|
| 310 | data_files.append(("test\\2d_data", [f])) |
---|
| 311 | |
---|
| 312 | # Copying the sample data user data |
---|
| 313 | for f in findall(test_save_dir): |
---|
| 314 | if not ".svn" in f: |
---|
| 315 | data_files.append(("test\\save_states", [f])) |
---|
| 316 | |
---|
| 317 | # Copying the sample data user data |
---|
| 318 | for f in findall(test_upcoming_dir): |
---|
| 319 | if not ".svn" in f: |
---|
| 320 | data_files.append(("test\\upcoming_formats", [f])) |
---|
| 321 | |
---|
[2eeca83] | 322 | |
---|
| 323 | # See if the documentation has been built, and if so include it. |
---|
| 324 | doc_path = os.path.join(build_path, "doc") |
---|
| 325 | if os.path.exists(doc_path): |
---|
| 326 | for dirpath, dirnames, filenames in os.walk(doc_path): |
---|
| 327 | for filename in filenames: |
---|
| 328 | sub_dir = os.path.join("doc", os.path.relpath(dirpath, doc_path)) |
---|
| 329 | data_files.append((sub_dir, [os.path.join(dirpath, filename)])) |
---|
| 330 | else: |
---|
| 331 | raise Exception("You must first build the documentation before creating an installer.") |
---|
| 332 | |
---|
[c971c98] | 333 | if py26MSdll is not None: |
---|
[2eeca83] | 334 | # install the MSVC 9 runtime dll's into the application folder |
---|
| 335 | data_files.append(("Microsoft.VC90.CRT", py26MSdll)) |
---|
[c971c98] | 336 | if py26MSdll_x86 is not None: |
---|
[2eeca83] | 337 | # install the MSVC 9 runtime dll's into the application folder |
---|
| 338 | data_files.append(("Microsoft.VC90.CRT", py26MSdll_x86)) |
---|
| 339 | |
---|
| 340 | # NOTE: |
---|
| 341 | # need an empty __init__.py in site-packages/numpy/distutils/tests and site-packages/mpl_toolkits |
---|
| 342 | |
---|
| 343 | # packages |
---|
| 344 | # |
---|
| 345 | packages = [ |
---|
| 346 | 'matplotlib', 'scipy', 'encodings', 'comtypes', |
---|
[a7c4ad2] | 347 | 'win32com', 'xhtml2pdf', 'bumps','sasmodels', 'sas', |
---|
[2eeca83] | 348 | ] |
---|
| 349 | packages.extend([ |
---|
| 350 | 'reportlab', |
---|
| 351 | 'reportlab.graphics.charts', |
---|
| 352 | 'reportlab.graphics.samples', |
---|
| 353 | 'reportlab.graphics.widgets', |
---|
| 354 | 'reportlab.graphics.barcode', |
---|
| 355 | 'reportlab.graphics', |
---|
| 356 | 'reportlab.lib', |
---|
| 357 | 'reportlab.pdfbase', |
---|
| 358 | 'reportlab.pdfgen', |
---|
| 359 | 'reportlab.platypus', |
---|
| 360 | ]) |
---|
[c971c98] | 361 | packages.append('periodictable.core') # not found automatically |
---|
[2eeca83] | 362 | #packages.append('IPython') |
---|
[4cf8db9] | 363 | includes = ['site', 'lxml._elementpath', 'lxml.etree'] |
---|
[2eeca83] | 364 | |
---|
| 365 | # Exclude packages that are not needed but are often found on build systems |
---|
[24d3a40] | 366 | excludes = ['Tkinter', 'PyQt4', '_tkagg', 'sip', 'pytz'] |
---|
[2eeca83] | 367 | |
---|
| 368 | |
---|
| 369 | dll_excludes = [ |
---|
| 370 | # Various matplotlib backends we are not using |
---|
| 371 | 'libgdk_pixbuf-2.0-0.dll', 'libgobject-2.0-0.dll', 'libgdk-win32-2.0-0.dll', |
---|
| 372 | 'tcl84.dll', 'tk84.dll', 'QtGui4.dll', 'QtCore4.dll', |
---|
| 373 | # numpy 1.8 openmp bindings (still seems to use all the cores without them) |
---|
| 374 | 'libiomp5md.dll', 'libifcoremd.dll', 'libmmd.dll', 'svml_dispmd.dll','libifportMD.dll', |
---|
| 375 | # microsoft C runtime (not allowed to ship with the app; need to ship vcredist |
---|
| 376 | 'msvcp90.dll', |
---|
| 377 | # 32-bit windows console piping |
---|
| 378 | 'w9xpopen.exe', |
---|
| 379 | # accidental links to msys/cygwin binaries; shouldn't be needed |
---|
| 380 | 'cygwin1.dll', |
---|
| 381 | ] |
---|
| 382 | |
---|
| 383 | target_wx_client = Target( |
---|
| 384 | description = 'SasView', |
---|
| 385 | script = 'sasview.py', |
---|
| 386 | icon_resources = [(1, os.path.join(images_dir, "ball.ico"))], |
---|
[c971c98] | 387 | other_resources = [(24, 1, manifest)], |
---|
[2eeca83] | 388 | dest_base = "SasView" |
---|
| 389 | ) |
---|
| 390 | |
---|
| 391 | bundle_option = 2 |
---|
| 392 | if is_64bits: |
---|
| 393 | bundle_option = 3 |
---|
| 394 | import installer_generator as gen |
---|
| 395 | gen.generate_installer() |
---|
| 396 | #initialize category stuff |
---|
[d85c194] | 397 | #from sas.sasgui.guiframe.CategoryInstaller import CategoryInstaller |
---|
[0c17d96] | 398 | #CategoryInstaller.check_install(s) |
---|
| 399 | |
---|
[2eeca83] | 400 | setup( |
---|
| 401 | windows=[target_wx_client], |
---|
| 402 | console=[], |
---|
| 403 | options={ |
---|
| 404 | 'py2exe': { |
---|
| 405 | 'dll_excludes': dll_excludes, |
---|
[c971c98] | 406 | 'packages': packages, |
---|
| 407 | 'includes': includes, |
---|
| 408 | 'excludes': excludes, |
---|
[2eeca83] | 409 | "compressed": 1, |
---|
| 410 | "optimize": 0, |
---|
[c971c98] | 411 | "bundle_files": bundle_option, |
---|
[2eeca83] | 412 | }, |
---|
| 413 | }, |
---|
| 414 | data_files=data_files, |
---|
| 415 | ) |
---|