source: sasview/installers/setup_exe.py @ e75de07

ESS_GUIESS_GUI_DocsESS_GUI_batch_fittingESS_GUI_bumps_abstractionESS_GUI_iss1116ESS_GUI_iss879ESS_GUI_iss959ESS_GUI_openclESS_GUI_orderingESS_GUI_sync_sascalcmagnetic_scattrelease-4.2.2ticket-1009ticket-1094-headlessticket-1242-2d-resolutionticket-1243ticket-1249ticket885unittest-saveload
Last change on this file since e75de07 was 460d3a1, checked in by Paul Kienzle <pkienzle@…>, 7 years ago

try fixing OMP problem in reorg by matching bundle option to master

  • Property mode set to 100644
File size: 12.5 KB
Line 
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.
15from __future__ import print_function
16
17import os
18import sys
19from glob import glob
20import warnings
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
27import py2exe
28
29#from idlelib.PyShell import warning_stream
30
31if os.path.abspath(os.path.dirname(__file__)) != os.path.abspath(os.getcwd()):
32    raise RuntimeError("Must run setup_exe from the installers directory")
33
34# put the build directory at the front of the path
35root = os.path.dirname(os.path.dirname(os.path.abspath(__file__)))
36platform = '%s-%s'%(get_platform(), sys.version[:3])
37doc_path = os.path.join(root, 'build', 'lib.'+platform, 'doc')
38build_path = os.path.join(root, 'sasview-install', 'Lib', 'site-packages')
39sys.path.insert(0, build_path)
40
41from sas.sasview import local_config
42from installer_generator import generate_installer
43
44import matplotlib
45try:
46    import tinycc
47except ImportError:
48    warnings.warn("TinyCC package is not available and will not be included")
49    tinycc = None
50
51if len(sys.argv) == 1:
52    sys.argv.append('py2exe')
53
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.
58try:
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')
65except Exception:
66    print("Error processing extra python path needed to build SasView\n  %s" %
67          sys.exc_value)
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
72win32_folder = "win32comext"
73try:
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
83    import win32com
84    for p in win32com.__path__[1:]:
85        modulefinder.AddPackagePath(win32_folder, p)
86    for extra in ["win32com.shell", "win32com.adsi", "win32com.axcontrol",
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)
94
95except ImportError:
96    # no build path setup, no worries.
97    pass
98
99# Remove the build folder
100shutil.rmtree("build", ignore_errors=True)
101# do the same for dist folder
102shutil.rmtree("dist", ignore_errors=True)
103
104is_64bits = sys.maxsize > 2**32
105arch = "amd64" if is_64bits else "x86"
106manifest = """
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>
128          <assemblyIdentity
129            type="win32"
130            name="Microsoft.VC90.CRT"
131            version="9.0.21022.8"
132            processorArchitecture="%(arch)s"
133            publicKeyToken="1fc8b3b9a1e18e3b">
134          </assemblyIdentity>
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
152class 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"
158        self.copyright = "copyright 2009 - 2016"
159        self.name = "SasView"
160
161#
162# Adapted from http://www.py2exe.org/index.cgi/MatPlotLib
163# to use the MatPlotLib.
164#
165matplotlibdatadir = matplotlib.get_data_path()
166matplotlibdata = findall(matplotlibdatadir)
167
168data_files = []
169
170if tinycc:
171    data_files += tinycc.data_files()
172
173# Include data for supporting packages
174import periodictable
175data_files += periodictable.data_files()
176
177for f in matplotlibdata:
178    dirname = os.path.join('mpl-data', f[len(matplotlibdatadir)+1:])
179    data_files.append((os.path.split(dirname)[0], [f]))
180
181import sasmodels
182data_files += sasmodels.data_files()
183
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.
186import sasmodels.core
187dll_path = os.path.join(build_path, 'compiled_models')
188compiled_dlls = sasmodels.core.precompile_dlls(dll_path, dtype='double')
189
190# include the compiled models as data; coordinate the target path for the
191# data with installer_generator.py
192data_files.append(('compiled_models', compiled_dlls))
193
194# Data files for the different perspectives
195from sas.sasgui.perspectives import fitting
196data_files += fitting.data_files()
197
198from sas.sasgui.perspectives import calculator
199data_files += calculator.data_files()
200
201from sas.sasgui.perspectives import invariant
202data_files += invariant.data_files()
203
204from sas.sasgui import guiframe
205data_files += guiframe.data_files()
206
207# Copy the config files
208sasview_path = os.path.join('..', 'src', 'sas', 'sasview')
209data_files.append(('.', [os.path.join(sasview_path, 'custom_config.py')]))
210data_files.append(('config', [os.path.join(sasview_path, 'custom_config.py')]))
211data_files.append(('.', [os.path.join(sasview_path, 'local_config.py')]))
212
213# Copy the logging config
214sas_path = os.path.join('..', 'src', 'sas')
215data_files.append(('.', [os.path.join(sas_path, 'logging.ini')]))
216
217if os.path.isfile("BUILD_NUMBER"):
218    data_files.append(('.', ["BUILD_NUMBER"]))
219
220# Copying the images directory to the distribution directory.
221images_dir = local_config.icon_path
222for f in findall(images_dir):
223    data_files.append(("images", [f]))
224
225# Copying the HTML help docs
226media_dir = local_config.media_path
227for f in findall(media_dir):
228    data_files.append(("media", [f]))
229
230# Copying the sample data user data
231test_dir = local_config.test_path
232for f in findall(os.path.join(test_dir, "1d_data")):
233    data_files.append((os.path.join("test", "1d_data"), [f]))
234for f in findall(os.path.join(test_dir, "2d_data")):
235    data_files.append((os.path.join("test", "2d_data"), [f]))
236for f in findall(os.path.join(test_dir, "save_states")):
237    data_files.append((os.path.join("test", "save_states"), [f]))
238for f in findall(os.path.join(test_dir, "upcoming_formats")):
239    data_files.append((os.path.join("test", "upcoming_formats"), [f]))
240
241# See if the documentation has been built, and if so include it.
242if 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)]))
247else:
248    raise Exception("You must first build the documentation before creating an installer.")
249
250# Copying opencl include files
251site_loc = get_python_lib()
252opencl_include_dir = os.path.join(site_loc, "pyopencl", "cl")
253for f in findall(opencl_include_dir):
254    data_files.append((os.path.join("includes", "pyopencl"), [f]))
255
256# Numerical libraries
257python_root = os.path.dirname(os.path.abspath(sys.executable))
258def 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
263numpy_path = os.path.join(python_root, 'lib', 'site-packages', 'numpy', 'core')
264atlas_dlls = dll_check(numpy_path, ['numpy-atlas'])
265
266# Check for MKL
267mkl_path = os.path.join(python_root, 'Library', 'bin')
268mkl_dlls = dll_check(mkl_path, ['mkl_core', 'mkl_def', 'libiomp5md'])
269
270if atlas_dlls:
271    data_files.append(('.', atlas_dlls))
272elif mkl_dlls:
273    data_files.append(('.', mkl_dlls))
274
275if is_64bits:
276    msvcrtdll = glob(r"C:\Program Files\Microsoft Visual Studio 9.0\VC\redist\x86\Microsoft.VC90.CRT\*.*")
277else:
278    msvcrtdll = glob(r"C:\Program Files (x86)\Microsoft Visual Studio 9.0\VC\redist\x86\Microsoft.VC90.CRT\*.*")
279if msvcrtdll:
280    # install the MSVC 9 runtime dll's into the application folder
281    data_files.append(("Microsoft.VC90.CRT", msvcrtdll))
282
283# NOTE:
284#  need an empty __init__.py in site-packages/numpy/distutils/tests and site-packages/mpl_toolkits
285
286# packages
287#
288packages = [
289    'matplotlib', 'scipy', 'encodings', 'comtypes', 'h5py',
290    'win32com', 'xhtml2pdf', 'bumps', 'sasmodels', 'sas',
291    ]
292packages.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    ])
304packages.append('periodictable.core') # not found automatically
305
306# For the interactive interpreter SasViewCom make sure ipython is available
307#packages.extend(['IPython', 'pyreadline', 'pyreadline.unicode_helper'])
308
309# individual models
310includes = ['site', 'lxml._elementpath', 'lxml.etree']
311
312if tinycc:
313    packages.append('tinycc')
314
315# Exclude packages that are not needed but are often found on build systems
316excludes = ['Tkinter', 'PyQt4', '_tkagg', 'sip', 'pytz', 'sympy']
317
318dll_excludes = [
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)
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',
325    'numpy-atlas.dll',
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',
332    # no need to distribute OpenCL.dll - users should have their own copy
333    'OpenCL.dll'
334    ]
335
336target_wx_client = Target(
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"
342)
343
344target_console_client = Target(
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"
350)
351
352#bundle_option = 3 if is_64bits else 2
353bundle_option = 3
354generate_installer()
355#initialize category stuff
356#from sas.sasgui.guiframe.CategoryInstaller import CategoryInstaller
357#CategoryInstaller.check_install(s)
358
359setup(
360    windows=[target_wx_client],
361    console=[target_console_client],
362    options={
363        'py2exe': {
364            'dll_excludes': dll_excludes,
365            'packages': packages,
366            'includes': includes,
367            'excludes': excludes,
368            "compressed": 1,
369            "optimize": 0,
370            "bundle_files": bundle_option,
371            },
372    },
373    data_files=data_files,
374)
Note: See TracBrowser for help on using the repository browser.