mirror of
https://github.com/mwisnowski/mtg_python_deckbuilder.git
synced 2025-09-21 20:40:47 +02:00
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:
parent
e52dfd7bb5
commit
8fa040a05a
3 changed files with 46 additions and 2 deletions
7
.github/workflows/github-release.yml
vendored
7
.github/workflows/github-release.yml
vendored
|
@ -29,7 +29,12 @@ jobs:
|
||||||
- name: Build executable (PyInstaller)
|
- name: Build executable (PyInstaller)
|
||||||
shell: powershell
|
shell: powershell
|
||||||
run: |
|
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' }
|
if (!(Test-Path dist/mtg-deckbuilder.exe)) { throw 'Build failed: dist/mtg-deckbuilder.exe not found' }
|
||||||
|
|
||||||
- name: Upload artifact (Windows EXE)
|
- name: Upload artifact (Windows EXE)
|
||||||
|
|
|
@ -11,12 +11,19 @@ from pathlib import Path
|
||||||
import json
|
import json
|
||||||
from typing import NoReturn
|
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
|
# Local imports
|
||||||
from deck_builder import DeckBuilder
|
from deck_builder import DeckBuilder
|
||||||
from file_setup.setup import initial_setup
|
from file_setup.setup import initial_setup
|
||||||
from tagging import tagger
|
from tagging import tagger
|
||||||
import logging_util
|
import logging_util
|
||||||
import os
|
|
||||||
from settings import CSV_DIRECTORY
|
from settings import CSV_DIRECTORY
|
||||||
|
|
||||||
# Create logger for this module
|
# Create logger for this module
|
||||||
|
|
32
mtg_deckbuilder.spec
Normal file
32
mtg_deckbuilder.spec
Normal 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,
|
||||||
|
)
|
Loading…
Add table
Add a link
Reference in a new issue