Skip to content

Commit 7c7898c

Browse files
author
Mark P.
committed
Improves build reliability with enhanced debugging and error handling
Adds comprehensive debug output throughout the GitHub Actions build workflow to help diagnose build failures and validate successful packaging. Enhances PyInstaller configuration with better error handling, existence checks for bundled files, and more comprehensive dependency collection for improved standalone execution. Updates main launcher with proper PyInstaller bundle detection, better error reporting, and graceful fallback handling for both development and built environments.
1 parent 5bfd688 commit 7c7898c

3 files changed

Lines changed: 287 additions & 54 deletions

File tree

.github/workflows/build-release.yml

Lines changed: 72 additions & 18 deletions
Original file line numberDiff line numberDiff line change
@@ -26,22 +26,48 @@ jobs:
2626
pip install pyinstaller
2727
pip install -r requirements.txt
2828
29+
- name: Debug environment
30+
run: |
31+
Write-Host "Current directory: $(Get-Location)"
32+
Write-Host "Files in current directory:"
33+
Get-ChildItem
34+
Write-Host "Python version:"
35+
python --version
36+
2937
- name: Build with PyInstaller
3038
run: |
31-
pyinstaller --clean blackjack_game.spec
39+
Write-Host "Building with PyInstaller..."
40+
pyinstaller --clean --noconfirm --log-level=DEBUG blackjack_game.spec
41+
Write-Host "Build completed. Checking dist folder:"
42+
if (Test-Path "dist") {
43+
Get-ChildItem dist/
44+
if (Test-Path "dist/BlackjackGame") {
45+
Write-Host "BlackjackGame folder contents:"
46+
Get-ChildItem dist/BlackjackGame/ | Select-Object -First 10
47+
Write-Host "Checking for custom files:"
48+
Get-ChildItem "dist/BlackjackGame/_internal" | Where-Object {$_.Name -like "*WezTerm*" -or $_.Name -like "*tcss*" -or $_.Name -like "*blackjack*"}
49+
} else {
50+
Write-Host "ERROR: BlackjackGame folder not found"
51+
exit 1
52+
}
53+
} else {
54+
Write-Host "ERROR: dist folder not created"
55+
exit 1
56+
}
3257
3358
- name: Create release package
3459
run: |
35-
# Create a run script for users
60+
if (-not (Test-Path "dist/BlackjackGame/BlackjackGame.exe")) {
61+
Write-Host "ERROR: BlackjackGame.exe not found!"
62+
exit 1
63+
}
3664
echo '@echo off' > dist/BlackjackGame/run_game.bat
3765
echo 'title Blackjack Game' >> dist/BlackjackGame/run_game.bat
3866
echo 'echo Starting Blackjack Game...' >> dist/BlackjackGame/run_game.bat
3967
echo 'BlackjackGame.exe' >> dist/BlackjackGame/run_game.bat
4068
echo 'echo.' >> dist/BlackjackGame/run_game.bat
4169
echo 'echo Game ended. Press any key to close...' >> dist/BlackjackGame/run_game.bat
4270
echo 'pause >nul' >> dist/BlackjackGame/run_game.bat
43-
44-
# Create instructions file
4571
echo 'Blackjack Game - Standalone Version' > dist/BlackjackGame/INSTRUCTIONS.txt
4672
echo '====================================' >> dist/BlackjackGame/INSTRUCTIONS.txt
4773
echo '' >> dist/BlackjackGame/INSTRUCTIONS.txt
@@ -52,19 +78,21 @@ jobs:
5278
echo 'No additional installation required.' >> dist/BlackjackGame/INSTRUCTIONS.txt
5379
echo '' >> dist/BlackjackGame/INSTRUCTIONS.txt
5480
echo 'Enjoy the game!' >> dist/BlackjackGame/INSTRUCTIONS.txt
55-
56-
# Copy README if it exists
5781
if (Test-Path README.md) { Copy-Item README.md dist/BlackjackGame/ }
5882
5983
- name: Create ZIP archive
6084
run: |
61-
Compress-Archive -Path "dist/BlackjackGame/*" -DestinationPath "BlackjackGame-Windows-${{ github.event.release.tag_name }}.zip"
85+
Write-Host "Creating ZIP archive..."
86+
Compress-Archive -Path "dist/BlackjackGame/*" -DestinationPath "BlackjackGame-Windows-${{ github.event.release.tag_name }}.zip" -Force
87+
$size = (Get-Item "BlackjackGame-Windows-${{ github.event.release.tag_name }}.zip").Length / 1MB
88+
Write-Host "ZIP created. Size: $([math]::Round($size, 2)) MB"
6289
6390
- name: Upload release asset
6491
env:
6592
GITHUB_TOKEN: ${{ secrets.GITHUB_TOKEN }}
6693
run: |
67-
gh release upload ${{ github.event.release.tag_name }} "BlackjackGame-Windows-${{ github.event.release.tag_name }}.zip"
94+
Write-Host "Uploading release asset..."
95+
gh release upload ${{ github.event.release.tag_name }} "BlackjackGame-Windows-${{ github.event.release.tag_name }}.zip" --clobber
6896
6997
build-linux:
7098
runs-on: ubuntu-latest
@@ -86,11 +114,25 @@ jobs:
86114
87115
- name: Build with PyInstaller
88116
run: |
89-
pyinstaller --clean blackjack_game.spec
117+
echo "Building with PyInstaller..."
118+
pyinstaller --clean --noconfirm --log-level=DEBUG blackjack_game.spec
119+
echo "Build completed. Checking dist folder:"
120+
ls -la dist/
121+
if [ -d "dist/BlackjackGame" ]; then
122+
echo "BlackjackGame folder contents:"
123+
ls -la dist/BlackjackGame/
124+
else
125+
echo "ERROR: BlackjackGame folder not found in dist/"
126+
exit 1
127+
fi
90128
91129
- name: Create release package
92130
run: |
93-
# Create a run script for users
131+
if [ ! -f "dist/BlackjackGame/BlackjackGame" ]; then
132+
echo "ERROR: BlackjackGame executable not found!"
133+
exit 1
134+
fi
135+
94136
cat > dist/BlackjackGame/run_game.sh << 'EOF'
95137
#!/bin/bash
96138
echo "Starting Blackjack Game..."
@@ -100,7 +142,6 @@ jobs:
100142
EOF
101143
chmod +x dist/BlackjackGame/run_game.sh
102144
103-
# Create instructions file
104145
cat > dist/BlackjackGame/INSTRUCTIONS.txt << 'EOF'
105146
Blackjack Game - Standalone Version
106147
====================================
@@ -114,19 +155,19 @@ jobs:
114155
Enjoy the game!
115156
EOF
116157
117-
# Copy README if it exists
118158
[ -f README.md ] && cp README.md dist/BlackjackGame/
119159
120160
- name: Create TAR archive
121161
run: |
122162
cd dist
123163
tar -czf "../BlackjackGame-Linux-${{ github.event.release.tag_name }}.tar.gz" BlackjackGame/
164+
echo "TAR created. Size: $(du -h "../BlackjackGame-Linux-${{ github.event.release.tag_name }}.tar.gz" | cut -f1)"
124165
125166
- name: Upload release asset
126167
env:
127168
GITHUB_TOKEN: ${{ secrets.GITHUB_TOKEN }}
128169
run: |
129-
gh release upload ${{ github.event.release.tag_name }} "BlackjackGame-Linux-${{ github.event.release.tag_name }}.tar.gz"
170+
gh release upload ${{ github.event.release.tag_name }} "BlackjackGame-Linux-${{ github.event.release.tag_name }}.tar.gz" --clobber
130171
131172
build-macos:
132173
runs-on: macos-latest
@@ -148,11 +189,25 @@ jobs:
148189
149190
- name: Build with PyInstaller
150191
run: |
151-
pyinstaller --clean blackjack_game.spec
192+
echo "Building with PyInstaller..."
193+
pyinstaller --clean --noconfirm --log-level=DEBUG blackjack_game.spec
194+
echo "Build completed. Checking dist folder:"
195+
ls -la dist/
196+
if [ -d "dist/BlackjackGame" ]; then
197+
echo "BlackjackGame folder contents:"
198+
ls -la dist/BlackjackGame/
199+
else
200+
echo "ERROR: BlackjackGame folder not found in dist/"
201+
exit 1
202+
fi
152203
153204
- name: Create release package
154205
run: |
155-
# Create a run script for users
206+
if [ ! -f "dist/BlackjackGame/BlackjackGame" ]; then
207+
echo "ERROR: BlackjackGame executable not found!"
208+
exit 1
209+
fi
210+
156211
cat > dist/BlackjackGame/run_game.sh << 'EOF'
157212
#!/bin/bash
158213
echo "Starting Blackjack Game..."
@@ -162,7 +217,6 @@ jobs:
162217
EOF
163218
chmod +x dist/BlackjackGame/run_game.sh
164219
165-
# Create instructions file
166220
cat > dist/BlackjackGame/INSTRUCTIONS.txt << 'EOF'
167221
Blackjack Game - Standalone Version
168222
====================================
@@ -176,16 +230,16 @@ jobs:
176230
Enjoy the game!
177231
EOF
178232
179-
# Copy README if it exists
180233
[ -f README.md ] && cp README.md dist/BlackjackGame/
181234
182235
- name: Create ZIP archive
183236
run: |
184237
cd dist
185238
zip -r "../BlackjackGame-macOS-${{ github.event.release.tag_name }}.zip" BlackjackGame/
239+
echo "ZIP created. Size: $(du -h "../BlackjackGame-macOS-${{ github.event.release.tag_name }}.zip" | cut -f1)"
186240
187241
- name: Upload release asset
188242
env:
189243
GITHUB_TOKEN: ${{ secrets.GITHUB_TOKEN }}
190244
run: |
191-
gh release upload ${{ github.event.release.tag_name }} "BlackjackGame-macOS-${{ github.event.release.tag_name }}.zip"
245+
gh release upload ${{ github.event.release.tag_name }} "BlackjackGame-macOS-${{ github.event.release.tag_name }}.zip" --clobber

blackjack_game.spec

Lines changed: 119 additions & 28 deletions
Original file line numberDiff line numberDiff line change
@@ -1,27 +1,51 @@
11
# -*- mode: python ; coding: utf-8 -*-
22
import os
3+
import sys
34
from PyInstaller.utils.hooks import collect_data_files, collect_submodules
45

5-
# Get the current directory
6-
current_dir = os.getcwd()
6+
# Get the current directory (where the spec file is located)
7+
current_dir = os.path.dirname(os.path.abspath(SPEC))
8+
9+
print(f"Current directory: {current_dir}")
710

811
# Collect all textual data files
9-
textual_datas = collect_data_files('textual')
12+
try:
13+
textual_datas = collect_data_files('textual')
14+
print(f"Found {len(textual_datas)} textual data files")
15+
except Exception as e:
16+
print(f"Error collecting textual data: {e}")
17+
textual_datas = []
1018

1119
# Define data files to include
12-
datas = [
13-
(os.path.join(current_dir, 'tcss'), 'tcss'),
14-
(os.path.join(current_dir, 'WezTerm'), 'WezTerm'),
15-
(os.path.join(current_dir, 'blackjackModule.py'), '.'),
16-
(os.path.join(current_dir, 'blackjack.py'), '.'),
17-
(os.path.join(current_dir, 'README.md'), '.'),
20+
datas = []
21+
22+
# Add files with existence checks
23+
data_files = [
24+
('tcss', 'tcss'),
25+
('WezTerm', 'WezTerm'),
26+
('blackjackModule.py', '.'),
27+
('blackjack.py', '.'),
28+
('requirements.txt', '.'),
29+
('LICENSE.md', '.'),
30+
('README.md', '.'),
1831
]
1932

33+
for src, dst in data_files:
34+
src_path = os.path.join(current_dir, src)
35+
if os.path.exists(src_path):
36+
datas.append((src_path, dst))
37+
print(f"Added to bundle: {src_path} -> {dst}")
38+
else:
39+
print(f"Warning: File not found: {src_path}")
40+
2041
# Add textual data files
21-
datas.extend(textual_datas)
42+
if textual_datas:
43+
datas.extend(textual_datas)
44+
print(f"Added {len(textual_datas)} textual data files")
2245

23-
# Hidden imports for all dependencies
46+
# Comprehensive hidden imports for standalone execution
2447
hiddenimports = [
48+
# Core textual
2549
'textual',
2650
'textual.app',
2751
'textual.widgets',
@@ -30,36 +54,103 @@ hiddenimports = [
3054
'textual.reactive',
3155
'textual.binding',
3256
'textual.css',
33-
'blackjackModule',
57+
'textual.driver',
58+
'textual._loop',
59+
'textual.geometry',
60+
'textual.color',
61+
'textual.design',
62+
'textual.strip',
63+
'textual.suggestion',
64+
'textual.filter',
65+
'textual.dom',
66+
'textual.css.query',
67+
'textual.css.parse',
68+
'textual.css.styles',
69+
'textual.css.tokenize',
70+
'textual.css.tokenizer',
71+
72+
# Rich dependencies
3473
'rich',
3574
'rich.console',
3675
'rich.text',
3776
'rich.table',
3877
'rich.panel',
3978
'rich.align',
4079
'rich.layout',
80+
'rich.segment',
81+
'rich.style',
82+
'rich.color',
83+
'rich.markup',
84+
'rich.highlighter',
85+
'rich.protocol',
86+
'rich.measure',
87+
'rich.cells',
88+
'rich.region',
89+
'rich.repr',
90+
'rich._loop',
91+
'rich._wrap',
92+
'rich._extension',
93+
94+
# System modules
4195
'typing_extensions',
4296
'importlib_metadata',
97+
'platform',
98+
'subprocess',
99+
'os',
100+
'sys',
101+
'pathlib',
102+
'asyncio',
103+
'threading',
104+
'time',
105+
'random',
106+
'json',
107+
'functools',
108+
'itertools',
109+
110+
# Game modules
111+
'blackjackModule',
43112
]
44113

45-
# Collect all textual submodules
46-
hiddenimports.extend(collect_submodules('textual'))
114+
# Collect all textual and rich submodules
115+
try:
116+
hiddenimports.extend(collect_submodules('textual'))
117+
hiddenimports.extend(collect_submodules('rich'))
118+
print(f"Collected submodules. Total hidden imports: {len(hiddenimports)}")
119+
except Exception as e:
120+
print(f"Error collecting submodules: {e}")
121+
122+
# Define binaries with existence checks
123+
binaries = []
124+
binary_files = [
125+
('WezTerm/wezterm.exe', 'WezTerm'),
126+
('WezTerm/wezterm-gui.exe', 'WezTerm'),
127+
('WezTerm/wezterm-mux-server.exe', 'WezTerm'),
128+
('WezTerm/conpty.dll', 'WezTerm'),
129+
('WezTerm/libEGL.dll', 'WezTerm'),
130+
('WezTerm/libGLESv2.dll', 'WezTerm'),
131+
('WezTerm/OpenConsole.exe', 'WezTerm'),
132+
('WezTerm/strip-ansi-escapes.exe', 'WezTerm'),
133+
('WezTerm/wezterm.pdb', 'WezTerm'),
134+
('WezTerm/mesa/opengl32.dll', 'WezTerm/mesa'),
135+
]
136+
137+
for src, dst in binary_files:
138+
src_path = os.path.join(current_dir, src)
139+
if os.path.exists(src_path):
140+
binaries.append((src_path, dst))
141+
print(f"Added binary: {src_path} -> {dst}")
142+
else:
143+
print(f"Warning: Binary not found: {src_path}")
144+
145+
print(f"\nFinal summary:")
146+
print(f"Data files: {len(datas)}")
147+
print(f"Binaries: {len(binaries)}")
148+
print(f"Hidden imports: {len(hiddenimports)}")
47149

48150
a = Analysis(
49151
['main.py'],
50152
pathex=[current_dir],
51-
binaries=[
52-
(os.path.join(current_dir, 'WezTerm', 'wezterm.exe'), 'WezTerm'),
53-
(os.path.join(current_dir, 'WezTerm', 'wezterm-gui.exe'), 'WezTerm'),
54-
(os.path.join(current_dir, 'WezTerm', 'wezterm-mux-server.exe'), 'WezTerm'),
55-
(os.path.join(current_dir, 'WezTerm', 'conpty.dll'), 'WezTerm'),
56-
(os.path.join(current_dir, 'WezTerm', 'libEGL.dll'), 'WezTerm'),
57-
(os.path.join(current_dir, 'WezTerm', 'libGLESv2.dll'), 'WezTerm'),
58-
(os.path.join(current_dir, 'WezTerm', 'OpenConsole.exe'), 'WezTerm'),
59-
(os.path.join(current_dir, 'WezTerm', 'strip-ansi-escapes.exe'), 'WezTerm'),
60-
(os.path.join(current_dir, 'WezTerm', 'wezterm.pdb'), 'WezTerm'),
61-
(os.path.join(current_dir, 'WezTerm', 'mesa', 'opengl32.dll'), 'WezTerm/mesa'),
62-
],
153+
binaries=binaries,
63154
datas=datas,
64155
hiddenimports=hiddenimports,
65156
hookspath=[],
@@ -80,11 +171,11 @@ exe = EXE(
80171
[],
81172
exclude_binaries=True,
82173
name='BlackjackGame',
83-
debug=False,
174+
debug=True, # Enable debug mode for better error messages
84175
bootloader_ignore_signals=False,
85176
strip=False,
86177
upx=False,
87-
console=True,
178+
console=True, # Keep console for debug output
88179
disable_windowed_traceback=False,
89180
argv_emulation=False,
90181
target_arch=None,

0 commit comments

Comments
 (0)