1 | # -*- mode: python -*- |
---|
2 | # Modifiable location |
---|
3 | import sys |
---|
4 | import os |
---|
5 | import platform |
---|
6 | |
---|
7 | import warnings |
---|
8 | from distutils.filelist import findall |
---|
9 | |
---|
10 | PYTHON_LOC = sys.exec_prefix |
---|
11 | # Portability settings |
---|
12 | if 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 |
---|
21 | else: |
---|
22 | LIBPREFIX='' |
---|
23 | LIBSUFFIX='dll' |
---|
24 | LIBLOC = os.path.join(PYTHON_LOC,'Library','bin') |
---|
25 | UPX=True |
---|
26 | |
---|
27 | SCRIPT_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__)) |
---|
31 | WORK_DIR = os.path.dirname(os.path.realpath(sys.argv[0])) |
---|
32 | |
---|
33 | #### LOCAL METHODS |
---|
34 | def add_data(data): |
---|
35 | for component in data: |
---|
36 | target = component[0] |
---|
37 | for filename in component[1]: |
---|
38 | datas.append((filename, target)) |
---|
39 | |
---|
40 | def add_binary(binary): |
---|
41 | return (os.path.join(LIBLOC,binary),'.') |
---|
42 | |
---|
43 | # ADDITIONAL DATA ############################################################ |
---|
44 | datas = [('images', 'images')] |
---|
45 | |
---|
46 | datas.append(('media','media')) |
---|
47 | datas.append(('test','test')) |
---|
48 | datas.append(('custom_config.py','.')) |
---|
49 | datas.append(('local_config.py','.')) |
---|
50 | datas.append(('wxcruft.py','.')) |
---|
51 | datas.append(('welcome_panel.py','.')) |
---|
52 | |
---|
53 | # TODO |
---|
54 | # NEED BETTER WAY TO DEAL WITH THESE RELATIVE PATHS |
---|
55 | datas.append((os.path.join('..','..','sasmodels','sasmodels'),'sasmodels')) |
---|
56 | datas.append((os.path.join('..','src','sas','sasgui','perspectives','fitting','plugin_models'),'plugin_models')) |
---|
57 | |
---|
58 | # precompile sas models into the sasview build path; doesn't matter too much |
---|
59 | # where it is so long as it is a place that will get cleaned up afterwards. |
---|
60 | import sasmodels.core |
---|
61 | dll_path = 'compiled_models' |
---|
62 | if not (os.path.exists(dll_path)): |
---|
63 | os.mkdir(dll_path) |
---|
64 | dll_path2 = os.path.join(dll_path, dll_path) |
---|
65 | if not (os.path.exists(dll_path2)): |
---|
66 | os.mkdir(dll_path2) |
---|
67 | |
---|
68 | compiled_dlls = sasmodels.core.precompile_dlls(dll_path, dtype='double') |
---|
69 | |
---|
70 | # include the compiled models as data; coordinate the target path for the |
---|
71 | # data with installer_generator.py |
---|
72 | datas.append((os.path.join('compiled_models','compiled_models'),'compiled_models')) |
---|
73 | |
---|
74 | # These depend on whether we have MKL or Atlas numpy |
---|
75 | if os.path.exists(os.path.join(LIBLOC, LIBPREFIX + 'mkl_core.' + LIBSUFFIX)): |
---|
76 | datas.append(add_binary(LIBPREFIX + 'mkl_avx2.' + LIBSUFFIX)) |
---|
77 | datas.append(add_binary(LIBPREFIX + 'mkl_def.' + LIBSUFFIX)) |
---|
78 | elif os.path.exists(os.path.join(LIBLOC, LIBPREFIX + 'numpy-atlas.' + LIBSUFFIX)): |
---|
79 | datas.append(add_binary(LIBPREFIX + 'numpy-atlas.' + LIBSUFFIX)) |
---|
80 | else: |
---|
81 | raise Exception("No numerical library for numpy found.") |
---|
82 | |
---|
83 | import sas.sascalc.dataloader.readers |
---|
84 | f = os.path.join(sas.sascalc.dataloader.readers.get_data_path(), 'defaults.json') |
---|
85 | datas.append((f, '.')) |
---|
86 | |
---|
87 | # Add a custom pyopencl hook, as described in |
---|
88 | # https://github.com/pyinstaller/pyinstaller/issues/2130 |
---|
89 | from PyInstaller.utils.hooks import copy_metadata |
---|
90 | datas.append(copy_metadata('pyopencl')[0]) |
---|
91 | |
---|
92 | import sasmodels |
---|
93 | add_data(sasmodels.data_files()) |
---|
94 | |
---|
95 | try: |
---|
96 | import tinycc |
---|
97 | add_data(tinycc.data_files()) |
---|
98 | except ImportError: |
---|
99 | warnings.warn("TinyCC package is not available and will not be included") |
---|
100 | |
---|
101 | import periodictable |
---|
102 | add_data(periodictable.data_files()) |
---|
103 | |
---|
104 | import matplotlib |
---|
105 | matplotlibdatadir = matplotlib.get_data_path() |
---|
106 | matplotlibdata = findall(matplotlibdatadir) |
---|
107 | for f in matplotlibdata: |
---|
108 | dirname = os.path.join('mpl-data', f[len(matplotlibdatadir)+1:]) |
---|
109 | datas.append((f, os.path.split(dirname)[0])) |
---|
110 | |
---|
111 | binaries = [] |
---|
112 | |
---|
113 | # EXCLUDED FILES ############################################################ |
---|
114 | # Spelled out to enable easier editing |
---|
115 | excludes = [] |
---|
116 | excludes.append('libzmq') |
---|
117 | excludes.append('IPython') |
---|
118 | excludes.append('PyQt4') |
---|
119 | excludes.append('PySide') |
---|
120 | excludes.append('Qt4') |
---|
121 | excludes.append('Tkinter') |
---|
122 | excludes.append('tk') |
---|
123 | excludes.append('tcl') |
---|
124 | # Seems we cannot build on Linux without bundling sip |
---|
125 | if not platform.system() == 'Linux': |
---|
126 | excludes.append('sip') |
---|
127 | excludes.append('sympy') |
---|
128 | excludes.append('pytz') |
---|
129 | excludes.append('sklearn') |
---|
130 | excludes.append('zmq') |
---|
131 | |
---|
132 | # Need to explicitly exclude sasmodels here!! |
---|
133 | excludes.append('sasmodels') |
---|
134 | |
---|
135 | # HIDDEN MODULES ############################################################ |
---|
136 | hiddenimports = [ |
---|
137 | 'periodictable.core', |
---|
138 | 'sasmodels.core', |
---|
139 | 'pyopencl', |
---|
140 | 'tinycc', |
---|
141 | 'xhtml2pdf' |
---|
142 | ] |
---|
143 | |
---|
144 | a = Analysis([SCRIPT_TO_SOURCE], |
---|
145 | pathex=[WORK_DIR], |
---|
146 | binaries=binaries, |
---|
147 | datas=datas, |
---|
148 | hiddenimports=hiddenimports, |
---|
149 | hookspath=[], |
---|
150 | runtime_hooks=[], |
---|
151 | excludes=excludes, |
---|
152 | win_no_prefer_redirects=False, |
---|
153 | win_private_assemblies=False, |
---|
154 | cipher=None) |
---|
155 | |
---|
156 | pyz = PYZ(a.pure, a.zipped_data, |
---|
157 | cipher=None) |
---|
158 | |
---|
159 | exe = EXE(pyz, |
---|
160 | a.scripts, |
---|
161 | exclude_binaries=True, |
---|
162 | name='sasview', |
---|
163 | debug=False, |
---|
164 | upx=UPX, |
---|
165 | icon=os.path.join("images","ball.ico"), |
---|
166 | version="version.txt", |
---|
167 | console=False ) |
---|
168 | |
---|
169 | # COLLECT creates a directory instead of a single file. |
---|
170 | coll = COLLECT(exe, |
---|
171 | a.binaries, |
---|
172 | a.zipfiles, |
---|
173 | a.datas, |
---|
174 | strip=False, |
---|
175 | upx=UPX, |
---|
176 | name='sasview') |
---|
177 | |
---|
178 | if platform.system() == 'Darwin': |
---|
179 | app = BUNDLE(exe, |
---|
180 | name='SasView.app', |
---|
181 | icon='images/ball.ico', |
---|
182 | bundle_identifier=None) |
---|
183 | |
---|