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