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