source: sasview/installers/setup_exe.py @ 3388337

ticket-1094-headless
Last change on this file since 3388337 was 3da8692, checked in by Piotr Rozyczko <rozyczko@…>, 7 years ago

force numpy-atlas.dll on win64 as well

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