source: sasview/sasview/sasview.spec @ 2a8bd705

ESS_GUIESS_GUI_DocsESS_GUI_batch_fittingESS_GUI_bumps_abstractionESS_GUI_iss1116ESS_GUI_iss879ESS_GUI_iss959ESS_GUI_openclESS_GUI_orderingESS_GUI_sync_sascalc
Last change on this file since 2a8bd705 was 2a8bd705, checked in by Piotr Rozyczko <rozyczko@…>, 7 years ago

Changes to allow pyinstaller builds

  • Property mode set to 100644
File size: 4.5 KB
Line 
1# -*- mode: python -*-
2# Modifiable location
3import sys
4import os
5import platform
6
7import warnings
8from distutils.filelist import findall
9
10PYTHON_LOC = sys.exec_prefix
11# Portability settings
12if os.name == 'posix':
13    LIBPREFIX='lib'
14    LIBSUFFIX='so'
15    LIBLOC = os.path.join(PYTHON_LOC,'lib')
16    # Darwin needs UPX=False, Linux actually builds with both...
17    if platform.system() == 'Darwin':
18        UPX=False
19    else:
20        UPX=True
21else:
22    LIBPREFIX=''
23    LIBSUFFIX='dll'
24    LIBLOC = os.path.join(PYTHON_LOC,'Library','bin')
25    UPX=True
26
27SCRIPT_TO_SOURCE = 'sasview.py'
28
29# Warning! pyinstaller/py2exe etc. don't have the __file__ attribute
30# WORK_DIR = os.path.dirname(os.path.realpath(__file__))
31WORK_DIR = os.path.dirname(os.path.realpath(sys.argv[0]))
32
33#### LOCAL METHODS
34def add_data(data):
35    for component in data:
36        target = component[0]
37        for filename in component[1]:
38           datas.append((filename, target))
39
40def add_binary(binary):
41    return (os.path.join(LIBLOC,binary),'.')
42
43# ADDITIONAL DATA ############################################################
44datas = [('images', 'images')]
45
46datas.append(('media','media'))
47datas.append(('test','test'))
48datas.append(('custom_config.py','.'))
49datas.append(('local_config.py','.'))
50datas.append(('wxcruft.py','.'))
51datas.append(('welcome_panel.py','.'))
52
53datas.append((os.path.join(PYTHON_LOC,'Lib','SocketServer.py'),'.'))
54
55# TODO
56# NEED BETTER WAY TO DEAL WITH THESE RELATIVE PATHS
57datas.append((os.path.join('..','..','sasmodels','sasmodels'),'sasmodels'))
58datas.append((os.path.join('..','src','sas','sasgui','perspectives','fitting','plugin_models'),'plugin_models'))
59
60# These depend on whether we have MKL or Atlas numpy
61if os.path.exists(os.path.join(LIBLOC, LIBPREFIX + 'mkl_core.' + LIBSUFFIX)):
62    datas.append(add_binary(LIBPREFIX + 'mkl_avx2.' + LIBSUFFIX))
63    datas.append(add_binary(LIBPREFIX + 'mkl_def.' + LIBSUFFIX))
64elif os.path.exists(os.path.join(LIBLOC, LIBPREFIX + 'numpy-atlas.' + LIBSUFFIX)):
65    datas.append(add_binary(LIBPREFIX + 'numpy-atlas.' + LIBSUFFIX))
66else:
67    raise Exception("No numerical library for numpy found.")
68
69import sas.sascalc.dataloader.readers
70f = os.path.join(sas.sascalc.dataloader.readers.get_data_path(), 'defaults.json')
71datas.append((f, '.'))
72
73# Add a custom pyopencl hook, as described in
74# https://github.com/pyinstaller/pyinstaller/issues/2130
75from PyInstaller.utils.hooks import copy_metadata
76datas.append(copy_metadata('pyopencl')[0])
77
78import sasmodels
79add_data(sasmodels.data_files())
80
81try:
82    import tinycc
83    add_data(tinycc.data_files())
84except ImportError:
85    warnings.warn("TinyCC package is not available and will not be included")
86
87import periodictable
88add_data(periodictable.data_files())
89
90import matplotlib
91matplotlibdatadir = matplotlib.get_data_path()
92matplotlibdata = findall(matplotlibdatadir)
93for f in matplotlibdata:
94    dirname = os.path.join('mpl-data', f[len(matplotlibdatadir)+1:])
95    datas.append((f, os.path.split(dirname)[0]))
96
97binaries = []
98
99# EXCLUDED FILES ############################################################
100# Spelled out to enable easier editing
101excludes = []
102
103# Need to explicitly exclude sasmodels here!!
104excludes.append('sasmodels')
105
106# HIDDEN MODULES ############################################################
107hiddenimports = [
108 'periodictable.core',
109 'sasmodels.core',
110 'pyopencl',
111 'tinycc',
112 'SocketServer'
113]
114
115a = Analysis([SCRIPT_TO_SOURCE],
116             pathex=[WORK_DIR],
117             binaries=binaries,
118             datas=datas,
119             hiddenimports=hiddenimports,
120             hookspath=[],
121             runtime_hooks=[],
122             excludes=excludes,
123             win_no_prefer_redirects=False,
124             win_private_assemblies=False,
125             cipher=None)
126
127pyz = PYZ(a.pure, a.zipped_data,
128             cipher=None)
129
130exe = EXE(pyz,
131          a.scripts,
132          exclude_binaries=True,
133          name='sasview',
134          debug=False,
135          upx=UPX,
136          icon=os.path.join("images","ball.ico"),
137          version="version.txt",
138          console=False )
139
140# COLLECT creates a directory instead of a single file.
141coll = COLLECT(exe,
142               a.binaries,
143               a.zipfiles,
144               a.datas,
145               strip=False,
146               upx=UPX,
147               name='sasview')
148
149if platform.system() == 'Darwin':
150    app = BUNDLE(exe,
151        name='SasView.app',
152        icon='images/ball.ico',
153        bundle_identifier=None)
154
Note: See TracBrowser for help on using the repository browser.