[e42c8e9d] | 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 | |
---|
[e43fc91] | 27 | SCRIPT_TO_SOURCE = 'sasview.py' |
---|
[e42c8e9d] | 28 | |
---|
| 29 | # Warning! pyinstaller/py2exe etc. don't have the __file__ attribute |
---|
| 30 | # WORK_DIR = os.path.dirname(os.path.realpath(__file__)) |
---|
| 31 | WORK_DIR = os.path.dirname(os.path.realpath(sys.argv[0])) |
---|
| 32 | |
---|
| 33 | #### LOCAL METHODS |
---|
| 34 | def add_data(data): |
---|
| 35 | for component in data: |
---|
| 36 | target = component[0] |
---|
| 37 | for filename in component[1]: |
---|
| 38 | datas.append((filename, target)) |
---|
| 39 | |
---|
| 40 | def add_binary(binary): |
---|
| 41 | return (os.path.join(LIBLOC,binary),'.') |
---|
| 42 | |
---|
| 43 | # ADDITIONAL DATA ############################################################ |
---|
| 44 | datas = [('images', 'images')] |
---|
| 45 | |
---|
| 46 | datas.append(('media','media')) |
---|
| 47 | datas.append(('test','test')) |
---|
| 48 | datas.append(('custom_config.py','.')) |
---|
| 49 | datas.append(('local_config.py','.')) |
---|
| 50 | datas.append(('wxcruft.py','.')) |
---|
| 51 | datas.append(('welcome_panel.py','.')) |
---|
| 52 | |
---|
[985ad94] | 53 | # pyinstaller gets mightily confused by upper/lower case, |
---|
| 54 | # so some modules need to be copied explicitly to avoid |
---|
| 55 | # messages like |
---|
| 56 | # WARNING: Attempted to add Python module twice with different upper/lowercases |
---|
[2a8bd705] | 57 | datas.append((os.path.join(PYTHON_LOC,'Lib','SocketServer.py'),'.')) |
---|
[985ad94] | 58 | datas.append((os.path.join(PYTHON_LOC,'Lib','Queue.py'),'.')) |
---|
[2a8bd705] | 59 | |
---|
[e42c8e9d] | 60 | # TODO |
---|
| 61 | # NEED BETTER WAY TO DEAL WITH THESE RELATIVE PATHS |
---|
| 62 | datas.append((os.path.join('..','..','sasmodels','sasmodels'),'sasmodels')) |
---|
| 63 | datas.append((os.path.join('..','src','sas','sasgui','perspectives','fitting','plugin_models'),'plugin_models')) |
---|
| 64 | |
---|
| 65 | # These depend on whether we have MKL or Atlas numpy |
---|
| 66 | if os.path.exists(os.path.join(LIBLOC, LIBPREFIX + 'mkl_core.' + LIBSUFFIX)): |
---|
| 67 | datas.append(add_binary(LIBPREFIX + 'mkl_avx2.' + LIBSUFFIX)) |
---|
| 68 | datas.append(add_binary(LIBPREFIX + 'mkl_def.' + LIBSUFFIX)) |
---|
| 69 | elif os.path.exists(os.path.join(LIBLOC, LIBPREFIX + 'numpy-atlas.' + LIBSUFFIX)): |
---|
| 70 | datas.append(add_binary(LIBPREFIX + 'numpy-atlas.' + LIBSUFFIX)) |
---|
| 71 | else: |
---|
| 72 | raise Exception("No numerical library for numpy found.") |
---|
| 73 | |
---|
| 74 | import sas.sascalc.dataloader.readers |
---|
| 75 | f = os.path.join(sas.sascalc.dataloader.readers.get_data_path(), 'defaults.json') |
---|
| 76 | datas.append((f, '.')) |
---|
| 77 | |
---|
| 78 | # Add a custom pyopencl hook, as described in |
---|
| 79 | # https://github.com/pyinstaller/pyinstaller/issues/2130 |
---|
| 80 | from PyInstaller.utils.hooks import copy_metadata |
---|
| 81 | datas.append(copy_metadata('pyopencl')[0]) |
---|
| 82 | |
---|
| 83 | import sasmodels |
---|
| 84 | add_data(sasmodels.data_files()) |
---|
| 85 | |
---|
| 86 | try: |
---|
| 87 | import tinycc |
---|
| 88 | add_data(tinycc.data_files()) |
---|
| 89 | except ImportError: |
---|
| 90 | warnings.warn("TinyCC package is not available and will not be included") |
---|
| 91 | |
---|
| 92 | import periodictable |
---|
| 93 | add_data(periodictable.data_files()) |
---|
| 94 | |
---|
| 95 | import matplotlib |
---|
| 96 | matplotlibdatadir = matplotlib.get_data_path() |
---|
| 97 | matplotlibdata = findall(matplotlibdatadir) |
---|
| 98 | for f in matplotlibdata: |
---|
| 99 | dirname = os.path.join('mpl-data', f[len(matplotlibdatadir)+1:]) |
---|
| 100 | datas.append((f, os.path.split(dirname)[0])) |
---|
| 101 | |
---|
| 102 | binaries = [] |
---|
| 103 | |
---|
| 104 | # EXCLUDED FILES ############################################################ |
---|
| 105 | # Spelled out to enable easier editing |
---|
| 106 | excludes = [] |
---|
| 107 | |
---|
| 108 | # Need to explicitly exclude sasmodels here!! |
---|
| 109 | excludes.append('sasmodels') |
---|
| 110 | |
---|
| 111 | # HIDDEN MODULES ############################################################ |
---|
| 112 | hiddenimports = [ |
---|
| 113 | 'periodictable.core', |
---|
| 114 | 'sasmodels.core', |
---|
| 115 | 'pyopencl', |
---|
[2a8bd705] | 116 | 'tinycc', |
---|
| 117 | 'SocketServer' |
---|
[e42c8e9d] | 118 | ] |
---|
| 119 | |
---|
| 120 | a = Analysis([SCRIPT_TO_SOURCE], |
---|
| 121 | pathex=[WORK_DIR], |
---|
| 122 | binaries=binaries, |
---|
| 123 | datas=datas, |
---|
| 124 | hiddenimports=hiddenimports, |
---|
| 125 | hookspath=[], |
---|
| 126 | runtime_hooks=[], |
---|
| 127 | excludes=excludes, |
---|
| 128 | win_no_prefer_redirects=False, |
---|
| 129 | win_private_assemblies=False, |
---|
| 130 | cipher=None) |
---|
| 131 | |
---|
| 132 | pyz = PYZ(a.pure, a.zipped_data, |
---|
| 133 | cipher=None) |
---|
| 134 | |
---|
| 135 | exe = EXE(pyz, |
---|
| 136 | a.scripts, |
---|
| 137 | exclude_binaries=True, |
---|
| 138 | name='sasview', |
---|
| 139 | debug=False, |
---|
| 140 | upx=UPX, |
---|
| 141 | icon=os.path.join("images","ball.ico"), |
---|
| 142 | version="version.txt", |
---|
| 143 | console=False ) |
---|
| 144 | |
---|
| 145 | # COLLECT creates a directory instead of a single file. |
---|
| 146 | coll = COLLECT(exe, |
---|
| 147 | a.binaries, |
---|
| 148 | a.zipfiles, |
---|
| 149 | a.datas, |
---|
| 150 | strip=False, |
---|
| 151 | upx=UPX, |
---|
| 152 | name='sasview') |
---|
| 153 | |
---|
| 154 | if platform.system() == 'Darwin': |
---|
| 155 | app = BUNDLE(exe, |
---|
| 156 | name='SasView.app', |
---|
| 157 | icon='images/ball.ico', |
---|
| 158 | bundle_identifier=None) |
---|
| 159 | |
---|