# engine.spec — PyInstaller config cho daw_engine.exe (sidecar Python) # Chay: pyinstaller engine.spec --clean --noconfirm (tren Windows) # -*- mode: python ; coding: utf-8 -*- import os from PyInstaller.utils.hooks import collect_dynamic_libs, collect_submodules, collect_data_files # Native DLL cho pedalboard va soundfile binaries = collect_dynamic_libs('pedalboard') binaries += collect_dynamic_libs('soundfile') # Root tuyet doi cua thu muc chua spec — dung cho cac datas KHONG nam trong # package 'app' (vd thu muc md/). Cac assets cua app (static/templates/models) # duoc bundle qua collect_data_files('app') — PyInstaller tu tim qua import # system, KHONG phu thuoc CWD/SPECPATH khi chay lenh (da gap 2 lan: chay # pyinstaller tu noi khac -> relative path khong resolve -> app/static thieu # trong bundle -> RuntimeError 'app\\static does not exist' luc chay). _SPEC_ROOT = os.path.abspath(SPECPATH) # Assets cua app: bundle QUA IMPORT SYSTEM (collect_data_files) — an toan nhat. # Loai tru storage (57MB soundfonts/uploads — vo ich trong onefile, config.py # da chuyen storage sang %APPDATA%\\SonicForgeDAW khi frozen) va __pycache__. datas = collect_data_files('app', excludes=['**/storage/**', '**/__pycache__/**', '**/*.pyc']) datas += [ (os.path.join(_SPEC_ROOT, 'md'), 'md'), # /ai-prompt-generator (doc, ngoai package app) ] # librosa 0.11 dùng lazy_loader.attach_stub -> lúc RUNTIME cần file .pyi # ton tai tren disk ('Cannot load imports from non-existent stub ...librosa\__init__.pyi'). # PyInstaller mac dinh KHONG bundle .pyi -> phai collect explicit. datas += collect_data_files('librosa', includes=['**/*.pyi']) # scipy >= 1.18 tach scipy.stats thanh nhieu module con (vd # _ansari_swilk_statistics) import lazy ben trong ham -> hook scipy cua # PyInstaller miss -> ModuleNotFoundError luc runtime. Collect toan bo # submodules cua scipy de khong sot module nao (stats/signal/ndimage...). _scipy_hidden = collect_submodules('scipy') a = Analysis( ['desktop_engine.py'], pathex=[_SPEC_ROOT], binaries=binaries, datas=datas, hiddenimports=collect_submodules('celery.fixups') + _scipy_hidden + [ 'uvicorn.logging', 'uvicorn.loops', 'uvicorn.loops.auto', 'uvicorn.protocols', 'uvicorn.protocols.http', 'uvicorn.protocols.http.auto', 'uvicorn.protocols.websockets', 'uvicorn.protocols.websockets.auto', 'pedalboard', 'soundfile', 'sf2utils', 'mido.backends.rtmidi', ], hookspath=[], hooksconfig={}, runtime_hooks=[], excludes=['tkinter'], win_no_prefer_redirects=False, win_private_assemblies=False, cipher=None, noarchive=False, ) pyz = PYZ(a.pure, a.zipped_data, cipher=None) exe = EXE( pyz, a.scripts, a.binaries, a.zipfiles, a.datas, [], name='daw_engine', debug=False, bootloader_ignore_signals=False, strip=False, upx=True, upx_exclude=[], runtime_tmpdir=None, console=False, # True khi debug (xem log truc tiep), False cho production icon='src-tauri/icons/icon.ico', )