# -*- mode: python ; coding: utf-8 -*- # # LabelPrinter PyInstaller spec file. # # GhostScript bundling # -------------------- # Run build_windows.bat (or prepare_ghostscript.bat) BEFORE pyinstaller. # That script copies the following directories from the system # GhostScript installation into conf\ghostscript\: # # conf\ghostscript\bin\ <- gswin64c.exe + gsdll64.dll # conf\ghostscript\lib\ <- all .ps init files # # This spec detects those directories automatically and adds them to the # bundle under ghostscript\bin\ and ghostscript\lib\ inside _MEIPASS so # that print_label.py can find and launch the bundled executable. # If the directories are absent the build still succeeds (prints will fall # back to SumatraPDF on the target machine). import os import glob as _glob # ── GhostScript: collect binaries and lib init files ────────────────────── _gs_bin_src = os.path.join('conf', 'ghostscript', 'bin') _gs_lib_src = os.path.join('conf', 'ghostscript', 'lib') gs_binaries = [] # (src_path, dest_folder_in_bundle) gs_datas = [] # (src_path, dest_folder_in_bundle) if os.path.isdir(_gs_bin_src): for _fn in ['gswin64c.exe', 'gsdll64.dll', 'gswin32c.exe', 'gsdll32.dll']: _fp = os.path.join(_gs_bin_src, _fn) if os.path.exists(_fp): # Put executables/DLLs in binaries so PyInstaller handles deps gs_binaries.append((_fp, 'ghostscript/bin')) print(f'[spec] Bundling GhostScript binaries from: {_gs_bin_src}') else: print('[spec] WARNING: conf/ghostscript/bin not found.' ' GhostScript will NOT be bundled in the exe.') if os.path.isdir(_gs_lib_src): for _fp in _glob.glob(os.path.join(_gs_lib_src, '*')): if os.path.isfile(_fp): gs_datas.append((_fp, 'ghostscript/lib')) print(f'[spec] Bundling GhostScript lib from: {_gs_lib_src}') # ── Base data files ──────────────────────────────────────────────────────── base_datas = [ ('conf\\SumatraPDF.exe', '.'), ('conf\\SumatraPDF-settings.txt', 'conf'), ('conf\\label_template_ok.svg', 'conf'), ('conf\\label_template_nok.svg', 'conf'), ('conf\\label_template.svg', 'conf'), ] a = Analysis( ['label_printer_gui.py'], pathex=[], binaries=gs_binaries, datas=base_datas + gs_datas, hiddenimports=[ 'kivy', 'PIL', 'barcode', 'reportlab', 'print_label', 'print_label_pdf', 'svglib', 'cairosvg', 'watchdog', 'watchdog.observers', 'watchdog.events', 'pystray', 'win32api', 'win32print', 'win32timezone', ], hookspath=[], hooksconfig={}, runtime_hooks=[], excludes=[], noarchive=False, optimize=0, ) pyz = PYZ(a.pure) exe = EXE( pyz, a.scripts, a.binaries, a.datas, [], name='LabelPrinter', debug=False, bootloader_ignore_signals=False, strip=False, upx=True, upx_exclude=[], runtime_tmpdir=None, console=False, disable_windowed_traceback=False, argv_emulation=False, target_arch=None, codesign_identity=None, entitlements_file=None, )