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