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(sys.argv[0])) |
---|
31 | |
---|
32 | #### LOCAL METHODS |
---|
33 | def add_data(data): |
---|
34 | for component in data: |
---|
35 | target = component[0] |
---|
36 | for filename in component[1]: |
---|
37 | datas.append((filename, target)) |
---|
38 | |
---|
39 | def add_binary(binary): |
---|
40 | return (os.path.join(LIBLOC,binary),'.') |
---|
41 | |
---|
42 | # ADDITIONAL DATA ############################################################ |
---|
43 | datas = [('../src/sas/sasview/images', 'images')] |
---|
44 | |
---|
45 | # datas = [('../src/sas/sasview/images/ball.png', '.')] |
---|
46 | datas = [('../src/sas/sasview/images/ball.ico', '.')] |
---|
47 | |
---|
48 | |
---|
49 | datas.append(('../src/sas/sasview/media','media')) |
---|
50 | datas.append(('../src/sas/sasview/test','test')) |
---|
51 | datas.append(('../src/sas/sasview/custom_config.py','.')) |
---|
52 | datas.append(('../src/sas/sasview/local_config.py','.')) |
---|
53 | # TRN COMMENT OUT |
---|
54 | #datas.append(('../src/sas/sasview/wxcruft.py','.')) |
---|
55 | datas.append(('../src/sas/logger_config.py','.')) |
---|
56 | datas.append(('../src/sas/logging.ini','.')) |
---|
57 | |
---|
58 | # pyinstaller gets mightily confused by upper/lower case, |
---|
59 | # so some modules need to be copied explicitly to avoid |
---|
60 | # messages like |
---|
61 | # WARNING: Attempted to add Python module twice with different upper/lowercases |
---|
62 | # TRN COMMENT OsUT |
---|
63 | # datas.append((os.path.join(PYTHON_LOC,'Lib','SocketServer.py'),'.')) |
---|
64 | # datas.append((os.path.join(PYTHON_LOC,'Lib','Queue.py'),'.')) |
---|
65 | |
---|
66 | # TODO |
---|
67 | # NEED BETTER WAY TO DEAL WITH THESE RELATIVE PATHS |
---|
68 | datas.append((os.path.join('..', '..','sasmodels','sasmodels'),'sasmodels')) |
---|
69 | datas.append((os.path.join('..', 'src','sas','sasgui','perspectives','fitting','plugin_models'),'plugin_models')) |
---|
70 | datas.append((os.path.join(PYTHON_LOC,'lib','python3.6', 'site-packages','jedi'),'jedi')) |
---|
71 | |
---|
72 | # TRN COMMENT OUT |
---|
73 | # datas.append((os.path.join(PYTHON_LOC,'Library','plugins','platforms'),'platforms')) |
---|
74 | #sdatas.append((os.path.join(PYTHON_LOC,'Lib','site-packages','zmq','libzmq.cp36-win_amd64.pyd'),'.')) |
---|
75 | |
---|
76 | # These depend on whether we have MKL or Atlas numpy |
---|
77 | if os.path.exists(os.path.join(LIBLOC, LIBPREFIX + 'mkl_core.' + LIBSUFFIX)): |
---|
78 | datas.append(add_binary(LIBPREFIX + 'mkl_avx2.' + LIBSUFFIX)) |
---|
79 | datas.append(add_binary(LIBPREFIX + 'mkl_def.' + LIBSUFFIX)) |
---|
80 | elif os.path.exists(os.path.join(LIBLOC, LIBPREFIX + 'numpy-atlas.' + LIBSUFFIX)): |
---|
81 | datas.append(add_binary(LIBPREFIX + 'numpy-atlas.' + LIBSUFFIX)) |
---|
82 | else: |
---|
83 | raise Exception("No numerical library for numpy found.") |
---|
84 | |
---|
85 | #import sas.sascalc.dataloader.readers |
---|
86 | #f = os.path.join(sas.sascalc.dataloader.readers.get_data_path(), 'defaults.json') |
---|
87 | #datas.append((f, '.')) |
---|
88 | |
---|
89 | # # Add a custom pyopencl hook, as described in |
---|
90 | # # https://github.com/pyinstaller/pyinstaller/issues/2130 |
---|
91 | # from PyInstaller.utils.hooks import copy_metadata |
---|
92 | # datas.append(copy_metadata('pyopencl')[0]) |
---|
93 | |
---|
94 | import sasmodels |
---|
95 | add_data(sasmodels.data_files()) |
---|
96 | |
---|
97 | try: |
---|
98 | import tinycc |
---|
99 | add_data(tinycc.data_files()) |
---|
100 | except ImportError: |
---|
101 | warnings.warn("TinyCC package is not available and will not be included") |
---|
102 | |
---|
103 | import periodictable |
---|
104 | add_data(periodictable.data_files()) |
---|
105 | |
---|
106 | import matplotlib |
---|
107 | matplotlibdatadir = matplotlib.get_data_path() |
---|
108 | matplotlibdata = findall(matplotlibdatadir) |
---|
109 | for f in matplotlibdata: |
---|
110 | dirname = os.path.join('mpl-data', f[len(matplotlibdatadir)+1:]) |
---|
111 | datas.append((f, os.path.split(dirname)[0])) |
---|
112 | |
---|
113 | binaries = [] |
---|
114 | |
---|
115 | # EXCLUDED FILES ############################################################ |
---|
116 | # Spelled out to enable easier editing |
---|
117 | excludes = [] |
---|
118 | |
---|
119 | # Need to explicitly exclude sasmodels here!! |
---|
120 | excludes.append('sasmodels') |
---|
121 | |
---|
122 | # HIDDEN MODULES ############################################################ |
---|
123 | hiddenimports = [ |
---|
124 | 'PyQt5', |
---|
125 | 'periodictable.core', |
---|
126 | 'sasmodels.core', |
---|
127 | #'pyopencl', |
---|
128 | #'tinycc', |
---|
129 | #'SocketServer', |
---|
130 | 'logging', |
---|
131 | 'logging.config', |
---|
132 | 'reportlab', 'reportlab.graphics', |
---|
133 | 'reportlab.graphics.barcode.common', |
---|
134 | 'reportlab.graphics.barcode.code128', |
---|
135 | 'reportlab.graphics.barcode.code93', |
---|
136 | 'reportlab.graphics.barcode.code39', |
---|
137 | 'reportlab.graphics.barcode.lto', |
---|
138 | 'reportlab.graphics.barcode.qr', |
---|
139 | 'reportlab.graphics.barcode.usps', |
---|
140 | 'reportlab.graphics.barcode.usps4s', |
---|
141 | 'reportlab.graphics.barcode.eanbc', |
---|
142 | 'reportlab.graphics.barcode.ecc200datamatrix', |
---|
143 | 'reportlab.graphics.barcode.fourstate', |
---|
144 | 'ipykernel', 'ipykernel.datapub', |
---|
145 | 'pygments', 'pygments.lexers','pygments.lexers.python', |
---|
146 | 'pygments.styles','pygments.styles.default', |
---|
147 | 'atexit', 'cython', 'sip', 'xhtml2pdf', |
---|
148 | 'zmq', 'zmq.utils', 'zmq.utils.strtypes', |
---|
149 | 'zmq.utils.jsonapi','zmq.utils.garbage', |
---|
150 | 'zmq.backend.cython','zmq.backend.cffi', |
---|
151 | 'site','lxml._elementpath','lxml.etree', |
---|
152 | 'scipy._lib.messagestream', |
---|
153 | ] |
---|
154 | |
---|
155 | a = Analysis([SCRIPT_TO_SOURCE], |
---|
156 | pathex=[WORK_DIR], |
---|
157 | binaries=binaries, |
---|
158 | datas=datas, |
---|
159 | hiddenimports=hiddenimports, |
---|
160 | hookspath=[], |
---|
161 | runtime_hooks=[], |
---|
162 | excludes=excludes, |
---|
163 | win_no_prefer_redirects=False, |
---|
164 | win_private_assemblies=False, |
---|
165 | cipher=None) |
---|
166 | |
---|
167 | pyz = PYZ(a.pure, a.zipped_data, |
---|
168 | cipher=None) |
---|
169 | |
---|
170 | exe = EXE(pyz, |
---|
171 | a.scripts, |
---|
172 | exclude_binaries=True, |
---|
173 | name='sasview', |
---|
174 | debug=False, |
---|
175 | upx=UPX, |
---|
176 | icon=os.path.join("../src/sas/sasview/images","ball.ico"), |
---|
177 | version="version.txt", |
---|
178 | console=False ) |
---|
179 | |
---|
180 | # COLLECT creates a directory instead of a single file. |
---|
181 | coll = COLLECT(exe, |
---|
182 | a.binaries, |
---|
183 | a.zipfiles, |
---|
184 | a.datas, |
---|
185 | strip=False, |
---|
186 | upx=UPX, |
---|
187 | name='sasview') |
---|
188 | |
---|
189 | if platform.system() == 'Darwin': |
---|
190 | app = BUNDLE(exe, |
---|
191 | name='SasView.app', |
---|
192 | icon='../src/sas/sasview/images/ball.ico', |
---|
193 | bundle_identifier=None) |
---|
194 | |
---|