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