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