From cef2d6666b3ce30f49bbbda219600f000d77ae43 Mon Sep 17 00:00:00 2001 From: locpham Date: Sat, 8 Aug 2026 14:37:38 +0000 Subject: [PATCH] =?UTF-8?q?FIX=20(lan=203=20-=20goc=20root):=20chen=20=5FS?= =?UTF-8?q?PEC=5FROOT=20vao=20sys.path=20truoc=20collect=5Fdata=5Ffiles('a?= =?UTF-8?q?pp')=20=E2=80=94=20'pyinstaller'=20entry=20point=20khong=20them?= =?UTF-8?q?=20CWD=20vao=20sys.path?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- engine.spec | 24 ++++++++++++++++++++---- wiki.md | 8 ++++++++ 2 files changed, 28 insertions(+), 4 deletions(-) diff --git a/engine.spec b/engine.spec index ec6f7ed..6772a1b 100644 --- a/engine.spec +++ b/engine.spec @@ -11,16 +11,32 @@ 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). +# duoc bundle qua collect_data_files('app'). _SPEC_ROOT = os.path.abspath(SPECPATH) +# ⚠️ GOC ROOT CUA MOI LOI 'app\static does not exist' (gap 3 lan): +# lenh `pyinstaller engine.spec` (entry-point script) KHONG them CWD vao +# sys.path (chi `python -m PyInstaller` moi them). collect_data_files('app') +# import package qua sys.path -> khong thay 'app' -> tra ve [] AM THAM -> +# bundle thieu static/templates -> exe crash luc chay. Fix: chen _SPEC_ROOT +# vao sys.path TRUOC khi collect de import 'app' luon hoạt dong. +import sys as _sys +if _SPEC_ROOT not in _sys.path: + _sys.path.insert(0, _SPEC_ROOT) + # 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']) +# Fallback cuoi cung: neu collect_data_files van tra ve rong (phong moi truong +# hop ky la), dung datas TINH absolute — tinh huong xau nhat van co du assets. +if not datas: + print("WARN: collect_data_files('app') tra ve rong - dung datas tinh absolute") + datas = [ + (os.path.join(_SPEC_ROOT, 'app', 'templates'), 'app/templates'), # index.html, favicon.svg + (os.path.join(_SPEC_ROOT, 'app', 'static'), 'app/static'), # js/css/processors + (os.path.join(_SPEC_ROOT, 'app', 'models'), 'app/models'), # project_schema.json (projects.py) + ] datas += [ (os.path.join(_SPEC_ROOT, 'md'), 'md'), # /ai-prompt-generator (doc, ngoai package app) ] diff --git a/wiki.md b/wiki.md index 4b75764..ab487e2 100644 --- a/wiki.md +++ b/wiki.md @@ -1,3 +1,11 @@ +### [2026-08-08] FIX (LAN 3 - GOC ROOT): 'app\static does not exist' — sys.path thieu CWD khi chay 'pyinstaller' (entry point) +- **Tóm tắt thay đổi:** Lỗi 'app\static does not exist' vẫn tái diễn dù đã 2 lần sửa datas (absolute path roi collect_data_files). Lần này tìm ra GOC ROOT THẬT SỰ: lệnh `pyinstaller engine.spec` (entry-point script cua PyInstaller) KHONG them CWD vao sys.path — chi `python -m PyInstaller` moi them. `collect_data_files('app')` import package 'app' qua sys.path -> khong thay -> tra ve [] AM THAM -> bundle thieu static/templates (dung canh: tren may dev chay `python -m PyInstaller` nen CWD co trong sys.path -> tuong da dung; may Windows chay `pyinstaller` -> CWD khong co -> collect rong -> TOC khong co app/static — dung voi loi verify cua user). Fix trong `engine.spec`: + 1. `sys.path.insert(0, _SPEC_ROOT)` TRUOC khi goi collect_data_files — import 'app' luon hoạt dong bat ke CWD. + 2. Fallback cuoi: neu collect_data_files van tra ve rong -> datas TINH absolute (app/templates, app/static, app/models) + in WARN de debug. +- **Cac file anh huong:** `engine.spec` (sys.path insert + fallback datas tinh) +- **Ghi chu/Test (neu co):** VERIFY DUNG DIEU KIEN THAT BAI: build tu /tmp (CWD khac project root — giong `pyinstaller` entry point khong co CWD trong sys.path) -> TOC co app/static (124) + app/templates (12), khong co WARN "tra ve rong"; tools/verify_bundle.py -> OK exit 0; chay binary frozen -> /health OK, index 200, static js 200. pytest 86 passed. User: pull engine.spec moi roi chay lai build_windows.ps1. + +--- ### [2026-08-08] FIX (lan 2): ERR_MODULE_NOT_FOUND '@babel/standalone' vẫn xảy ra — build_windows.ps1 TỰ cài dep nếu thiếu - **Tóm tắt thay đổi:** User vẫn gặp ERR_MODULE_NOT_FOUND '@babel/standalone' dù đã thêm vào package.json — máy Windows chưa pull package.json mới hoặc npm install chưa cài. Fix: `build_windows.ps1` bước [2/6] — sau `npm install`, TỰ KIỂM TRA `node_modules\@babel\standalone`; thiếu → `npm install @babel/standalone --no-audit --no-fund`; vẫn thiếu → ERROR + exit 1. Không còn phụ thuộc package.json mới trên máy user. - **Các file ảnh hưởng:** `build_windows.ps1` (bước 2 tự cài @babel/standalone)