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