source: sasview/sasview/setup_exe.py @ 0615d54

ESS_GUIESS_GUI_DocsESS_GUI_batch_fittingESS_GUI_bumps_abstractionESS_GUI_iss1116ESS_GUI_iss879ESS_GUI_iss959ESS_GUI_openclESS_GUI_orderingESS_GUI_sync_sascalccostrafo411magnetic_scattrelease-4.2.2ticket-1009ticket-1094-headlessticket-1242-2d-resolutionticket-1243ticket-1249ticket885unittest-saveload
Last change on this file since 0615d54 was 7a5d066, checked in by krzywon, 7 years ago

Replace defaults.json file with constant to eliminate json dependency

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