[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 | |
---|
| 152 | if is_64bits: |
---|
| 153 | msvcrtdll = glob(r"C:\Program Files\Microsoft Visual Studio 9.0\VC\redist\x86\Microsoft.VC90.CRT\*.*") |
---|
| 154 | else: |
---|
| 155 | msvcrtdll = glob(r"C:\Program Files (x86)\Microsoft Visual Studio 9.0\VC\redist\x86\Microsoft.VC90.CRT\*.*") |
---|
[0046c6a] | 156 | msvcrtdll_data_files = ("Microsoft.VC90.CRT", msvcrtdll) if msvcrtdll else None |
---|
[c971c98] | 157 | |
---|
[2eeca83] | 158 | class Target: |
---|
| 159 | def __init__(self, **kw): |
---|
| 160 | self.__dict__.update(kw) |
---|
| 161 | # for the versioninfo resources |
---|
| 162 | self.version = local_config.__version__ |
---|
| 163 | self.company_name = "SasView.org" |
---|
[9bbc074] | 164 | self.copyright = "copyright 2009 - 2016" |
---|
[2eeca83] | 165 | self.name = "SasView" |
---|
[f36e01f] | 166 | |
---|
[2eeca83] | 167 | # |
---|
| 168 | # Adapted from http://www.py2exe.org/index.cgi/MatPlotLib |
---|
| 169 | # to use the MatPlotLib. |
---|
| 170 | # |
---|
| 171 | matplotlibdatadir = matplotlib.get_data_path() |
---|
| 172 | matplotlibdata = findall(matplotlibdatadir) |
---|
[230178b] | 173 | |
---|
[0046c6a] | 174 | data_files = [] |
---|
[9528caa] | 175 | |
---|
| 176 | if tinycc: |
---|
[0046c6a] | 177 | data_files += tinycc.data_files() |
---|
[9528caa] | 178 | |
---|
[0046c6a] | 179 | # Include data for supporting packages |
---|
[2eeca83] | 180 | import periodictable |
---|
[0046c6a] | 181 | data_files += periodictable.data_files() |
---|
[2eeca83] | 182 | |
---|
[0046c6a] | 183 | for f in matplotlibdata: |
---|
| 184 | dirname = os.path.join('mpl-data', f[len(matplotlibdatadir)+1:]) |
---|
| 185 | data_files.append((os.path.split(dirname)[0], [f])) |
---|
[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. |
---|
[0046c6a] | 227 | images_dir = local_config.icon_path |
---|
[2eeca83] | 228 | for f in findall(images_dir): |
---|
[0046c6a] | 229 | data_files.append(("images", [f])) |
---|
[2eeca83] | 230 | |
---|
| 231 | # Copying the HTML help docs |
---|
[0046c6a] | 232 | media_dir = local_config.media_path |
---|
[2eeca83] | 233 | for f in findall(media_dir): |
---|
[0046c6a] | 234 | data_files.append(("media", [f])) |
---|
[0c17d96] | 235 | |
---|
| 236 | # Copying the sample data user data |
---|
[0046c6a] | 237 | test_dir = local_config.test_path |
---|
| 238 | for f in findall(os.path.join(test_dir, "1d_data")): |
---|
| 239 | data_files.append((os.path.join("test", "1d_data"), [f])) |
---|
| 240 | for f in findall(os.path.join(test_dir, "2d_data")): |
---|
| 241 | data_files.append((os.path.join("test", "2d_data"), [f])) |
---|
| 242 | for f in findall(os.path.join(test_dir, "save_states")): |
---|
| 243 | data_files.append((os.path.join("test", "save_states"), [f])) |
---|
| 244 | for f in findall(os.path.join(test_dir, "upcoming_formats")): |
---|
| 245 | data_files.append((os.path.join("test", "upcoming_formats"), [f])) |
---|
[0c17d96] | 246 | |
---|
[0046c6a] | 247 | # See if the documentation has been built, and if so include it. |
---|
| 248 | if os.path.exists(doc_path): |
---|
| 249 | for dirpath, dirnames, filenames in os.walk(doc_path): |
---|
| 250 | for filename in filenames: |
---|
| 251 | sub_dir = os.path.join("doc", os.path.relpath(dirpath, doc_path)) |
---|
| 252 | data_files.append((sub_dir, [os.path.join(dirpath, filename)])) |
---|
| 253 | else: |
---|
| 254 | raise Exception("You must first build the documentation before creating an installer.") |
---|
[0c17d96] | 255 | |
---|
[230178b] | 256 | # Copying opencl include files |
---|
[3aa2f3c] | 257 | site_loc = get_python_lib() |
---|
| 258 | opencl_include_dir = os.path.join(site_loc, "pyopencl", "cl") |
---|
[230178b] | 259 | for f in findall(opencl_include_dir): |
---|
[0046c6a] | 260 | data_files.append((os.path.join("includes", "pyopencl"), [f])) |
---|
[2eeca83] | 261 | |
---|
[914ba0a] | 262 | # Numerical libraries |
---|
| 263 | python_root = os.path.dirname(os.path.abspath(sys.executable)) |
---|
| 264 | def dll_check(dll_path, dlls): |
---|
| 265 | dll_includes = [os.path.join(dll_path, dll+'.dll') for dll in dlls] |
---|
| 266 | return [dll for dll in dll_includes if os.path.exists(dll)] |
---|
| 267 | |
---|
| 268 | # Check for ATLAS |
---|
| 269 | numpy_path = os.path.join(python_root, 'lib', 'site-packages', 'numpy', 'core') |
---|
| 270 | atlas_dlls = dll_check(numpy_path, ['numpy-atlas']) |
---|
| 271 | |
---|
| 272 | # Check for MKL |
---|
| 273 | mkl_path = os.path.join(python_root, 'Library', 'bin') |
---|
| 274 | mkl_dlls = dll_check(mkl_path, ['mkl_core', 'mkl_def', 'libiomp5md']) |
---|
| 275 | |
---|
| 276 | if atlas_dlls: |
---|
[0046c6a] | 277 | data_files.append(('.', atlas_dlls)) |
---|
[914ba0a] | 278 | elif mkl_dlls: |
---|
[0046c6a] | 279 | data_files.append(('.', mkl_dlls)) |
---|
[2eeca83] | 280 | |
---|
[9528caa] | 281 | if msvcrtdll_data_files is not None: |
---|
[2eeca83] | 282 | # install the MSVC 9 runtime dll's into the application folder |
---|
[0046c6a] | 283 | data_files.append(msvcrtdll_data_files) |
---|
[2eeca83] | 284 | |
---|
| 285 | # NOTE: |
---|
| 286 | # need an empty __init__.py in site-packages/numpy/distutils/tests and site-packages/mpl_toolkits |
---|
| 287 | |
---|
| 288 | # packages |
---|
| 289 | # |
---|
| 290 | packages = [ |
---|
[abb02db] | 291 | 'matplotlib', 'scipy', 'encodings', 'comtypes', 'h5py', |
---|
[25a42f99] | 292 | 'win32com', 'xhtml2pdf', 'bumps', 'sasmodels', 'sas', |
---|
[2eeca83] | 293 | ] |
---|
| 294 | packages.extend([ |
---|
| 295 | 'reportlab', |
---|
| 296 | 'reportlab.graphics.charts', |
---|
| 297 | 'reportlab.graphics.samples', |
---|
| 298 | 'reportlab.graphics.widgets', |
---|
| 299 | 'reportlab.graphics.barcode', |
---|
| 300 | 'reportlab.graphics', |
---|
| 301 | 'reportlab.lib', |
---|
| 302 | 'reportlab.pdfbase', |
---|
| 303 | 'reportlab.pdfgen', |
---|
| 304 | 'reportlab.platypus', |
---|
| 305 | ]) |
---|
[c971c98] | 306 | packages.append('periodictable.core') # not found automatically |
---|
[914ba0a] | 307 | |
---|
[0046c6a] | 308 | # For the interactive interpreter SasViewCom make sure ipython is available |
---|
[87fc3b6] | 309 | #packages.extend(['IPython', 'pyreadline', 'pyreadline.unicode_helper']) |
---|
[899e084] | 310 | |
---|
| 311 | # individual models |
---|
[4cf8db9] | 312 | includes = ['site', 'lxml._elementpath', 'lxml.etree'] |
---|
[2eeca83] | 313 | |
---|
[9528caa] | 314 | if tinycc: |
---|
| 315 | packages.append('tinycc') |
---|
| 316 | |
---|
[2eeca83] | 317 | # Exclude packages that are not needed but are often found on build systems |
---|
[0046c6a] | 318 | excludes = ['Tkinter', 'PyQt4', '_tkagg', 'sip', 'pytz', 'sympy'] |
---|
| 319 | |
---|
| 320 | dll_excludes = [ |
---|
[2eeca83] | 321 | # Various matplotlib backends we are not using |
---|
| 322 | 'libgdk_pixbuf-2.0-0.dll', 'libgobject-2.0-0.dll', 'libgdk-win32-2.0-0.dll', |
---|
| 323 | 'tcl84.dll', 'tk84.dll', 'QtGui4.dll', 'QtCore4.dll', |
---|
| 324 | # numpy 1.8 openmp bindings (still seems to use all the cores without them) |
---|
[899e084] | 325 | # ... but we seem to need them when building from anaconda, so don't exclude ... |
---|
| 326 | #'libiomp5md.dll', 'libifcoremd.dll', 'libmmd.dll', 'svml_dispmd.dll','libifportMD.dll', |
---|
[c3e4e213] | 327 | 'numpy-atlas.dll', |
---|
[2eeca83] | 328 | # microsoft C runtime (not allowed to ship with the app; need to ship vcredist |
---|
| 329 | 'msvcp90.dll', |
---|
| 330 | # 32-bit windows console piping |
---|
| 331 | 'w9xpopen.exe', |
---|
| 332 | # accidental links to msys/cygwin binaries; shouldn't be needed |
---|
| 333 | 'cygwin1.dll', |
---|
[0c10782] | 334 | # no need to distribute OpenCL.dll - users should have their own copy |
---|
| 335 | 'OpenCL.dll' |
---|
[2eeca83] | 336 | ] |
---|
| 337 | |
---|
| 338 | target_wx_client = Target( |
---|
[25a42f99] | 339 | description='SasView', |
---|
| 340 | script='sasview_gui.py', |
---|
| 341 | icon_resources=[(1, local_config.SetupIconFile_win)], |
---|
| 342 | other_resources=[(24, 1, manifest)], |
---|
| 343 | dest_base="SasView" |
---|
[f36e01f] | 344 | ) |
---|
[2eeca83] | 345 | |
---|
[899e084] | 346 | target_console_client = Target( |
---|
[25a42f99] | 347 | description='SasView console', |
---|
| 348 | script='sasview_console.py', |
---|
| 349 | icon_resources=[(1, local_config.SetupIconFile_win)], |
---|
| 350 | other_resources=[(24, 1, manifest)], |
---|
| 351 | dest_base="SasViewCom" |
---|
[899e084] | 352 | ) |
---|
| 353 | |
---|
[914ba0a] | 354 | bundle_option = 3 if is_64bits else 2 |
---|
[9528caa] | 355 | generate_installer() |
---|
[2eeca83] | 356 | #initialize category stuff |
---|
[d85c194] | 357 | #from sas.sasgui.guiframe.CategoryInstaller import CategoryInstaller |
---|
[0c17d96] | 358 | #CategoryInstaller.check_install(s) |
---|
| 359 | |
---|
[2eeca83] | 360 | setup( |
---|
| 361 | windows=[target_wx_client], |
---|
[899e084] | 362 | console=[target_console_client], |
---|
[2eeca83] | 363 | options={ |
---|
| 364 | 'py2exe': { |
---|
| 365 | 'dll_excludes': dll_excludes, |
---|
[c971c98] | 366 | 'packages': packages, |
---|
| 367 | 'includes': includes, |
---|
| 368 | 'excludes': excludes, |
---|
[2eeca83] | 369 | "compressed": 1, |
---|
| 370 | "optimize": 0, |
---|
[c971c98] | 371 | "bundle_files": bundle_option, |
---|
[2eeca83] | 372 | }, |
---|
| 373 | }, |
---|
[0046c6a] | 374 | data_files=data_files, |
---|
[2eeca83] | 375 | ) |
---|