[aefde77] | 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 | |
---|
[a0ed202] | 45 | datas = [('../src/sas/sasview/images/ball.png', '.')] |
---|
| 46 | |
---|
[aefde77] | 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','.')) |
---|
[a0ed202] | 53 | datas.append(('../src/sas/logging.ini','.')) |
---|
[aefde77] | 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','zmq','libzmq.cp36-win_amd64.pyd'),'.')) |
---|
| 68 | |
---|
| 69 | # These depend on whether we have MKL or Atlas numpy |
---|
| 70 | if os.path.exists(os.path.join(LIBLOC, LIBPREFIX + 'mkl_core.' + LIBSUFFIX)): |
---|
| 71 | datas.append(add_binary(LIBPREFIX + 'mkl_avx2.' + LIBSUFFIX)) |
---|
| 72 | datas.append(add_binary(LIBPREFIX + 'mkl_def.' + LIBSUFFIX)) |
---|
| 73 | elif os.path.exists(os.path.join(LIBLOC, LIBPREFIX + 'numpy-atlas.' + LIBSUFFIX)): |
---|
| 74 | datas.append(add_binary(LIBPREFIX + 'numpy-atlas.' + LIBSUFFIX)) |
---|
| 75 | else: |
---|
| 76 | raise Exception("No numerical library for numpy found.") |
---|
| 77 | |
---|
| 78 | #import sas.sascalc.dataloader.readers |
---|
| 79 | #f = os.path.join(sas.sascalc.dataloader.readers.get_data_path(), 'defaults.json') |
---|
| 80 | #datas.append((f, '.')) |
---|
| 81 | |
---|
| 82 | # Add a custom pyopencl hook, as described in |
---|
| 83 | # https://github.com/pyinstaller/pyinstaller/issues/2130 |
---|
| 84 | from PyInstaller.utils.hooks import copy_metadata |
---|
| 85 | datas.append(copy_metadata('pyopencl')[0]) |
---|
| 86 | |
---|
| 87 | import sasmodels |
---|
| 88 | add_data(sasmodels.data_files()) |
---|
| 89 | |
---|
| 90 | try: |
---|
| 91 | import tinycc |
---|
| 92 | add_data(tinycc.data_files()) |
---|
| 93 | except ImportError: |
---|
| 94 | warnings.warn("TinyCC package is not available and will not be included") |
---|
| 95 | |
---|
| 96 | import periodictable |
---|
| 97 | add_data(periodictable.data_files()) |
---|
| 98 | |
---|
| 99 | import matplotlib |
---|
| 100 | matplotlibdatadir = matplotlib.get_data_path() |
---|
| 101 | matplotlibdata = findall(matplotlibdatadir) |
---|
| 102 | for f in matplotlibdata: |
---|
| 103 | dirname = os.path.join('mpl-data', f[len(matplotlibdatadir)+1:]) |
---|
| 104 | datas.append((f, os.path.split(dirname)[0])) |
---|
| 105 | |
---|
| 106 | binaries = [] |
---|
| 107 | |
---|
| 108 | # EXCLUDED FILES ############################################################ |
---|
| 109 | # Spelled out to enable easier editing |
---|
| 110 | excludes = [] |
---|
| 111 | |
---|
| 112 | # Need to explicitly exclude sasmodels here!! |
---|
| 113 | excludes.append('sasmodels') |
---|
| 114 | |
---|
| 115 | # HIDDEN MODULES ############################################################ |
---|
| 116 | hiddenimports = [ |
---|
| 117 | 'PyQt5', |
---|
| 118 | 'periodictable.core', |
---|
| 119 | 'sasmodels.core', |
---|
| 120 | 'pyopencl', |
---|
| 121 | 'tinycc', |
---|
| 122 | 'SocketServer', |
---|
| 123 | 'logging', |
---|
| 124 | 'logging.config', |
---|
[a0ed202] | 125 | 'reportlab', 'reportlab.graphics', |
---|
| 126 | 'reportlab.graphics.barcode.common', |
---|
| 127 | 'reportlab.graphics.barcode.code128', |
---|
| 128 | 'reportlab.graphics.barcode.code93', |
---|
| 129 | 'reportlab.graphics.barcode.code39', |
---|
| 130 | 'reportlab.graphics.barcode.lto', |
---|
| 131 | 'reportlab.graphics.barcode.qr', |
---|
| 132 | 'reportlab.graphics.barcode.usps', |
---|
| 133 | 'reportlab.graphics.barcode.usps4s', |
---|
| 134 | 'reportlab.graphics.barcode.eanbc', |
---|
| 135 | 'reportlab.graphics.barcode.ecc200datamatrix', |
---|
| 136 | 'reportlab.graphics.barcode.fourstate', |
---|
[aefde77] | 137 | 'ipykernel', 'ipykernel.datapub', |
---|
[a3221b6] | 138 | 'pygments', 'pygments.lexers','pygments.lexers.python', |
---|
| 139 | 'pygments.styles','pygments.styles.default', |
---|
[aefde77] | 140 | 'atexit', 'cython', 'sip', 'xhtml2pdf', |
---|
[a3221b6] | 141 | 'zmq', 'zmq.utils', 'zmq.utils.strtypes', |
---|
| 142 | 'zmq.utils.jsonapi','zmq.utils.garbage', |
---|
[aefde77] | 143 | 'zmq.backend.cython','zmq.backend.cffi', |
---|
| 144 | 'site','lxml._elementpath','lxml.etree', |
---|
| 145 | 'scipy._lib.messagestream', |
---|
| 146 | ] |
---|
| 147 | |
---|
| 148 | a = Analysis([SCRIPT_TO_SOURCE], |
---|
| 149 | pathex=[WORK_DIR], |
---|
| 150 | binaries=binaries, |
---|
| 151 | datas=datas, |
---|
| 152 | hiddenimports=hiddenimports, |
---|
| 153 | hookspath=[], |
---|
| 154 | runtime_hooks=[], |
---|
| 155 | excludes=excludes, |
---|
| 156 | win_no_prefer_redirects=False, |
---|
| 157 | win_private_assemblies=False, |
---|
| 158 | cipher=None) |
---|
| 159 | |
---|
| 160 | pyz = PYZ(a.pure, a.zipped_data, |
---|
| 161 | cipher=None) |
---|
| 162 | |
---|
| 163 | exe = EXE(pyz, |
---|
| 164 | a.scripts, |
---|
| 165 | exclude_binaries=True, |
---|
| 166 | name='sasview', |
---|
| 167 | debug=False, |
---|
| 168 | upx=UPX, |
---|
| 169 | icon=os.path.join("../src/sas/sasview/images","ball.ico"), |
---|
| 170 | version="version.txt", |
---|
| 171 | console=False ) |
---|
| 172 | |
---|
| 173 | # COLLECT creates a directory instead of a single file. |
---|
| 174 | coll = COLLECT(exe, |
---|
| 175 | a.binaries, |
---|
| 176 | a.zipfiles, |
---|
| 177 | a.datas, |
---|
| 178 | strip=False, |
---|
| 179 | upx=UPX, |
---|
| 180 | name='sasview') |
---|
| 181 | |
---|
| 182 | if platform.system() == 'Darwin': |
---|
| 183 | app = BUNDLE(exe, |
---|
| 184 | name='SasView.app', |
---|
| 185 | icon='../src/sas/sasview/images/ball.ico', |
---|
| 186 | bundle_identifier=None) |
---|
| 187 | |
---|