build(windows): fix PyInstaller packaging\n\n- Add spec file with hiddenimports and data dirs\n- Use spec in release workflow; fallback to --paths code\n- Insert ./code into sys.path when frozen to resolve local imports

This commit is contained in:
mwisnowski 2025-08-25 09:57:02 -07:00
parent e52dfd7bb5
commit 8fa040a05a
3 changed files with 46 additions and 2 deletions

View file

@ -29,7 +29,12 @@ jobs:
- name: Build executable (PyInstaller)
shell: powershell
run: |
pyinstaller --onefile --name mtg-deckbuilder code/main.py
# Build using spec for reliable packaging
pyinstaller mtg_deckbuilder.spec
if (!(Test-Path dist/mtg-deckbuilder.exe)) {
Write-Host 'Spec build failed; retrying simple build with --paths code'
pyinstaller --onefile --name mtg-deckbuilder --paths code code/main.py
}
if (!(Test-Path dist/mtg-deckbuilder.exe)) { throw 'Build failed: dist/mtg-deckbuilder.exe not found' }
- name: Upload artifact (Windows EXE)

View file

@ -11,12 +11,19 @@ from pathlib import Path
import json
from typing import NoReturn
# Ensure local package resolution in frozen builds
import os
if getattr(sys, 'frozen', False): # PyInstaller frozen
base = os.path.dirname(sys.executable)
code_dir = os.path.join(base, 'code')
if os.path.isdir(code_dir) and code_dir not in sys.path:
sys.path.insert(0, code_dir)
# Local imports
from deck_builder import DeckBuilder
from file_setup.setup import initial_setup
from tagging import tagger
import logging_util
import os
from settings import CSV_DIRECTORY
# Create logger for this module

32
mtg_deckbuilder.spec Normal file
View file

@ -0,0 +1,32 @@
# PyInstaller spec to build mtg-deckbuilder reliably with code package
import sys
from PyInstaller.utils.hooks import collect_submodules
block_cipher = None
hiddenimports = collect_submodules('code')
a = Analysis(
['code/main.py'],
pathex=['.','code'],
binaries=[],
datas=[('csv_files/*', 'csv_files'), ('deck_files/*', 'deck_files'), ('logs/*', 'logs'), ('config/*', 'config')],
hiddenimports=hiddenimports,
hookspath=[],
runtime_hooks=[],
excludes=[],
noarchive=False,
)
pyz = PYZ(a.pure, a.zipped_data, cipher=block_cipher)
exe = EXE(
pyz,
a.scripts,
a.binaries,
a.zipfiles,
a.datas,
name='mtg-deckbuilder',
debug=False,
strip=False,
upx=True,
console=True,
)