-
Notifications
You must be signed in to change notification settings - Fork 10
Expand file tree
/
Copy pathtest_bundled_app.sh
More file actions
executable file
·317 lines (275 loc) · 9.51 KB
/
test_bundled_app.sh
File metadata and controls
executable file
·317 lines (275 loc) · 9.51 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
314
315
316
317
#!/bin/bash
# ---------------------------------------------------------------------------
# Test Bundled App Generation Locally
#
# This script builds the macOS app bundle and tests generation using
# the actual frozen binary. This catches all PyInstaller bundling issues
# at once instead of discovering them one by one.
#
# Usage:
# ./test_bundled_app.sh
# ---------------------------------------------------------------------------
set -e # Exit on error
echo "=================================================="
echo "AceForge - Bundled App Generation Test"
echo "=================================================="
echo ""
# Check if we're in the right directory
if [ ! -f "CDMF.spec" ]; then
echo "Error: CDMF.spec not found. Please run this script from the project root."
exit 1
fi
# Check if Python is available (prefer 3.11, fallback to python3)
PYTHON_CMD=""
if command -v python3.11 &> /dev/null; then
PYTHON_CMD="python3.11"
elif command -v python3 &> /dev/null; then
PYTHON_VERSION=$(python3 --version 2>&1 | grep -oE '[0-9]+\.[0-9]+' | head -1)
PYTHON_MAJOR=$(echo $PYTHON_VERSION | cut -d. -f1)
PYTHON_MINOR=$(echo $PYTHON_VERSION | cut -d. -f2)
if [ "$PYTHON_MAJOR" -eq 3 ] && [ "$PYTHON_MINOR" -ge 11 ]; then
PYTHON_CMD="python3"
else
echo "⚠ Warning: Python $PYTHON_VERSION found, but Python 3.11+ is recommended."
echo " Some dependencies may not work with Python 3.14+."
echo " Consider installing Python 3.11: brew install python@3.11"
echo ""
read -p "Continue anyway? (y/N) " -n 1 -r
echo
if [[ ! $REPLY =~ ^[Yy]$ ]]; then
exit 1
fi
PYTHON_CMD="python3"
fi
else
echo "Error: python3 not found. Please install Python 3.11 or later."
exit 1
fi
# Check if we're in a virtual environment, or use venv_test if it exists
if [ -z "$VIRTUAL_ENV" ]; then
if [ -d "venv_test" ]; then
echo "Activating venv_test virtual environment..."
source venv_test/bin/activate
elif [ -d "venv_ace" ]; then
echo "Activating venv_ace virtual environment..."
source venv_ace/bin/activate
else
echo "⚠ No virtual environment detected."
echo " Creating venv_test..."
$PYTHON_CMD -m venv venv_test
source venv_test/bin/activate
fi
else
echo "Using existing virtual environment: $VIRTUAL_ENV"
fi
# After venv activation, use 'python' command if available, otherwise use the original PYTHON_CMD
if command -v python &> /dev/null; then
PYTHON_CMD="python"
elif [ -n "$VIRTUAL_ENV" ] && [ -f "$VIRTUAL_ENV/bin/python" ]; then
PYTHON_CMD="$VIRTUAL_ENV/bin/python"
fi
PYTHON_VERSION=$($PYTHON_CMD --version)
echo "Python: $PYTHON_VERSION"
echo ""
# Step 1: Check dependencies
echo "Step 1: Checking dependencies..."
if ! $PYTHON_CMD -c "import PyInstaller" 2>/dev/null; then
echo "⚠ PyInstaller not found."
echo ""
echo "Please install PyInstaller first:"
if [ -n "$VIRTUAL_ENV" ]; then
echo " pip install pyinstaller==6.17.0"
else
echo " pip3 install pyinstaller==6.17.0"
echo ""
echo "Or create/activate a virtual environment:"
echo " python3 -m venv venv_test"
echo " source venv_test/bin/activate"
echo " pip install pyinstaller==6.17.0"
fi
echo ""
exit 1
else
PYINSTALLER_VERSION=$($PYTHON_CMD -c "import PyInstaller; print(PyInstaller.__version__)" 2>/dev/null || echo "unknown")
echo "✓ PyInstaller found (version: $PYINSTALLER_VERSION)"
fi
# Step 2: Build the app bundle
echo ""
echo "Step 2: Building app bundle with PyInstaller..."
if [ -d "dist/AceForge.app" ] || [ -d "dist/AceForge" ]; then
echo "Removing existing build..."
# NEVER delete build/macos/ — it contains AceForge.icns (app icon), codesign.sh, pyinstaller hooks.
rm -rf dist/AceForge.app dist/AceForge build/AceForge
fi
if [ ! -f "build/macos/AceForge.icns" ]; then
echo "✗ ERROR: build/macos/AceForge.icns not found. build/macos/ must never be deleted."
echo " Restore from main: git checkout main -- build/macos/"
exit 1
fi
$PYTHON_CMD -m PyInstaller CDMF.spec --clean
if [ ! -d "dist/AceForge.app" ]; then
echo "✗ Build failed: dist/AceForge.app not found"
exit 1
fi
echo "✓ App bundle built successfully"
echo ""
# Step 3: Add launcher scripts
echo "Step 3: Setting up launcher scripts..."
cp launch_in_terminal.sh dist/AceForge.app/Contents/MacOS/
chmod +x dist/AceForge.app/Contents/MacOS/launch_in_terminal.sh
cp macos_terminal_launcher.sh dist/AceForge.app/Contents/MacOS/AceForge
chmod +x dist/AceForge.app/Contents/MacOS/AceForge
echo "✓ Launcher scripts configured"
echo ""
# Step 4: Code sign (optional, but recommended)
echo "Step 4: Code signing app bundle..."
if [ -f "build/macos/codesign.sh" ]; then
chmod +x build/macos/codesign.sh
MACOS_SIGNING_IDENTITY="-" ./build/macos/codesign.sh dist/AceForge.app
echo "✓ App bundle signed"
else
echo "⚠ Code signing script not found, skipping..."
fi
echo ""
# Step 5: Test imports
echo "Step 5: Testing bundled app imports..."
BUNDLED_BIN="./dist/AceForge.app/Contents/MacOS/AceForge_bin"
if [ ! -f "$BUNDLED_BIN" ]; then
echo "✗ Bundled binary not found at $BUNDLED_BIN"
exit 1
fi
echo "Testing critical imports..."
"$BUNDLED_BIN" -c "
import sys
print('Python version:', sys.version)
print('Frozen:', getattr(sys, 'frozen', False))
errors = []
try:
import lzma
import _lzma
print('✓ lzma imported successfully')
except Exception as e:
print(f'✗ lzma import failed: {e}')
errors.append(('lzma', str(e)))
try:
from acestep.models.lyrics_utils.lyric_tokenizer import VoiceBpeTokenizer
print('✓ VoiceBpeTokenizer imported successfully')
except Exception as e:
print(f'✗ VoiceBpeTokenizer import failed: {e}')
errors.append(('VoiceBpeTokenizer', str(e)))
try:
from cdmf_pipeline_ace_step import ACEStepPipeline
print('✓ ACEStepPipeline imported successfully')
except Exception as e:
print(f'✗ ACEStepPipeline import failed: {e}')
errors.append(('ACEStepPipeline', str(e)))
if errors:
print('')
print('✗ Import errors detected:')
for module, error in errors:
print(f' - {module}: {error}')
sys.exit(1)
print('✓ All critical imports successful')
" || {
echo ""
echo "✗ Import test failed"
exit 1
}
echo ""
# Step 6: Test generation (if models are available)
echo "Step 6: Testing generation with bundled app..."
echo "Note: This requires ACE-Step models to be downloaded."
echo " Run 'python ace_model_setup.py' first if needed."
echo ""
# Check if models exist
MODELS_EXIST=false
if $PYTHON_CMD -c "from ace_model_setup import get_ace_checkpoint_root, ACE_LOCAL_DIRNAME; from pathlib import Path; root = get_ace_checkpoint_root(); repo = root / ACE_LOCAL_DIRNAME; exit(0 if repo.exists() else 1)" 2>/dev/null; then
MODELS_EXIST=true
echo "✓ Models found, proceeding with generation test..."
else
echo "⚠ Models not found. Skipping generation test."
echo " To test generation, run: python ace_model_setup.py"
echo ""
echo "✓ Bundled app import test PASSED"
echo " (Generation test skipped - models not available)"
exit 0
fi
# Create test script
cat > test_bundled_generation.py << 'TESTSCRIPT'
import sys
import os
from pathlib import Path
# Set environment
os.environ['PYTORCH_MPS_HIGH_WATERMARK_RATIO'] = '0.0'
print("=" * 60)
print("Bundled App Generation Test")
print("=" * 60)
print(f"Python executable: {sys.executable}")
print(f"Frozen: {getattr(sys, 'frozen', False)}")
print("=" * 60)
try:
from generate_ace import generate_track_ace
print("✓ generate_track_ace imported successfully")
except Exception as e:
print(f"✗ Failed to import generate_track_ace: {e}")
import traceback
traceback.print_exc()
sys.exit(1)
print("")
print("Starting generation test (10 seconds, 5 steps)...")
try:
result = generate_track_ace(
genre_prompt="upbeat electronic music, synthwave",
instrumental=True,
target_seconds=10,
steps=5,
guidance_scale=4.0,
seed=42,
out_dir=Path("test_output_bundled"),
basename="local_test_bundled_track"
)
print("")
print("✓ Generation completed successfully")
output_dir = Path("test_output_bundled")
wav_files = list(output_dir.glob("*.wav"))
if not wav_files:
print(f"✗ No WAV files found in {output_dir}")
sys.exit(1)
for wav_file in wav_files:
size = wav_file.stat().st_size
print(f"✓ Generated file: {wav_file.name} ({size:,} bytes)")
if size == 0:
print(f"✗ File is empty: {wav_file.name}")
sys.exit(1)
print("")
print("=" * 60)
print("✓ Bundled app generation test PASSED")
print("=" * 60)
except Exception as e:
print("")
print("=" * 60)
print("✗ Generation failed")
print("=" * 60)
print(f"Error: {e}")
print("")
import traceback
traceback.print_exc()
sys.exit(1)
TESTSCRIPT
# Run generation test
"$BUNDLED_BIN" test_bundled_generation.py || {
echo ""
echo "✗ Generation test failed"
echo "Check the error messages above to identify the issue."
rm -f test_bundled_generation.py
exit 1
}
# Cleanup
rm -f test_bundled_generation.py
echo ""
echo "=================================================="
echo "✓ All tests PASSED"
echo "=================================================="
echo ""
echo "The bundled app is working correctly!"
echo "You can find it at: dist/AceForge.app"