source: sasview/installers/setup_exe.py @ 87fc3b6

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 87fc3b6 was 87fc3b6, checked in by Paul Kienzle <pkienzle@…>, 3 years ago

suppress ipython dependency for windows build

  • 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
152if is_64bits:
153    msvcrtdll = glob(r"C:\Program Files\Microsoft Visual Studio 9.0\VC\redist\x86\Microsoft.VC90.CRT\*.*")
154else:
155    msvcrtdll = glob(r"C:\Program Files (x86)\Microsoft Visual Studio 9.0\VC\redist\x86\Microsoft.VC90.CRT\*.*")
156msvcrtdll_data_files = ("Microsoft.VC90.CRT", msvcrtdll) if msvcrtdll else None
157
158class 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"
164        self.copyright = "copyright 2009 - 2016"
165        self.name = "SasView"
166
167#
168# Adapted from http://www.py2exe.org/index.cgi/MatPlotLib
169# to use the MatPlotLib.
170#
171matplotlibdatadir = matplotlib.get_data_path()
172matplotlibdata = findall(matplotlibdatadir)
173
174data_files = []
175
176if tinycc:
177    data_files += tinycc.data_files()
178
179# Include data for supporting packages
180import periodictable
181data_files += periodictable.data_files()
182
183for f in matplotlibdata:
184    dirname = os.path.join('mpl-data', f[len(matplotlibdatadir)+1:])
185    data_files.append((os.path.split(dirname)[0], [f]))
186
187import sasmodels
188data_files += sasmodels.data_files()
189
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.
192import sasmodels.core
193dll_path = os.path.join(build_path, 'compiled_models')
194compiled_dlls = sasmodels.core.precompile_dlls(dll_path, dtype='double')
195
196# include the compiled models as data; coordinate the target path for the
197# data with installer_generator.py
198data_files.append(('compiled_models', compiled_dlls))
199
200# Data files for the different perspectives
201from sas.sasgui.perspectives import fitting
202data_files += fitting.data_files()
203
204from sas.sasgui.perspectives import calculator
205data_files += calculator.data_files()
206
207from sas.sasgui.perspectives import invariant
208data_files += invariant.data_files()
209
210from sas.sasgui import guiframe
211data_files += guiframe.data_files()
212
213# Copy the config files
214sasview_path = os.path.join('..', 'src', 'sas', 'sasview')
215data_files.append(('.', [os.path.join(sasview_path, 'custom_config.py')]))
216data_files.append(('config', [os.path.join(sasview_path, 'custom_config.py')]))
217data_files.append(('.', [os.path.join(sasview_path, 'local_config.py')]))
218
219# Copy the logging config
220sas_path = os.path.join('..', 'src', 'sas')
221data_files.append(('.', [os.path.join(sas_path, 'logging.ini')]))
222
223if os.path.isfile("BUILD_NUMBER"):
224    data_files.append(('.', ["BUILD_NUMBER"]))
225
226# Copying the images directory to the distribution directory.
227images_dir = local_config.icon_path
228for f in findall(images_dir):
229    data_files.append(("images", [f]))
230
231# Copying the HTML help docs
232media_dir = local_config.media_path
233for f in findall(media_dir):
234    data_files.append(("media", [f]))
235
236# Copying the sample data user data
237test_dir = local_config.test_path
238for f in findall(os.path.join(test_dir, "1d_data")):
239    data_files.append((os.path.join("test", "1d_data"), [f]))
240for f in findall(os.path.join(test_dir, "2d_data")):
241    data_files.append((os.path.join("test", "2d_data"), [f]))
242for f in findall(os.path.join(test_dir, "save_states")):
243    data_files.append((os.path.join("test", "save_states"), [f]))
244for f in findall(os.path.join(test_dir, "upcoming_formats")):
245    data_files.append((os.path.join("test", "upcoming_formats"), [f]))
246
247# See if the documentation has been built, and if so include it.
248if 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)]))
253else:
254    raise Exception("You must first build the documentation before creating an installer.")
255
256# Copying opencl include files
257site_loc = get_python_lib()
258opencl_include_dir = os.path.join(site_loc, "pyopencl", "cl")
259for f in findall(opencl_include_dir):
260    data_files.append((os.path.join("includes", "pyopencl"), [f]))
261
262# Numerical libraries
263python_root = os.path.dirname(os.path.abspath(sys.executable))
264def 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
269numpy_path = os.path.join(python_root, 'lib', 'site-packages', 'numpy', 'core')
270atlas_dlls = dll_check(numpy_path, ['numpy-atlas'])
271
272# Check for MKL
273mkl_path = os.path.join(python_root, 'Library', 'bin')
274mkl_dlls = dll_check(mkl_path, ['mkl_core', 'mkl_def', 'libiomp5md'])
275
276if atlas_dlls:
277    data_files.append(('.', atlas_dlls))
278elif mkl_dlls:
279    data_files.append(('.', mkl_dlls))
280
281if msvcrtdll_data_files is not None:
282    # install the MSVC 9 runtime dll's into the application folder
283    data_files.append(msvcrtdll_data_files)
284
285# NOTE:
286#  need an empty __init__.py in site-packages/numpy/distutils/tests and site-packages/mpl_toolkits
287
288# packages
289#
290packages = [
291    'matplotlib', 'scipy', 'encodings', 'comtypes', 'h5py',
292    'win32com', 'xhtml2pdf', 'bumps', 'sasmodels', 'sas',
293    ]
294packages.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    ])
306packages.append('periodictable.core') # not found automatically
307
308# For the interactive interpreter SasViewCom make sure ipython is available
309#packages.extend(['IPython', 'pyreadline', 'pyreadline.unicode_helper'])
310
311# individual models
312includes = ['site', 'lxml._elementpath', 'lxml.etree']
313
314if tinycc:
315    packages.append('tinycc')
316
317# Exclude packages that are not needed but are often found on build systems
318excludes = ['Tkinter', 'PyQt4', '_tkagg', 'sip', 'pytz', 'sympy']
319
320dll_excludes = [
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)
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',
327    'numpy-atlas.dll',
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',
334    # no need to distribute OpenCL.dll - users should have their own copy
335    'OpenCL.dll'
336    ]
337
338target_wx_client = Target(
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"
344)
345
346target_console_client = Target(
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"
352)
353
354bundle_option = 3 if is_64bits else 2
355generate_installer()
356#initialize category stuff
357#from sas.sasgui.guiframe.CategoryInstaller import CategoryInstaller
358#CategoryInstaller.check_install(s)
359
360setup(
361    windows=[target_wx_client],
362    console=[target_console_client],
363    options={
364        'py2exe': {
365            'dll_excludes': dll_excludes,
366            'packages': packages,
367            'includes': includes,
368            'excludes': excludes,
369            "compressed": 1,
370            "optimize": 0,
371            "bundle_files": bundle_option,
372            },
373    },
374    data_files=data_files,
375)
Note: See TracBrowser for help on using the repository browser.