source: sasview/sasview/setup_exe.py @ cd57c7d4

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 cd57c7d4 was cd57c7d4, checked in by krzywon, 3 years ago

Merge branch 'master' into 4_1_issues

# Conflicts:
# src/sas/sascalc/dataloader/readers/cansas_reader.py

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