build: add pyinstaller packaging
Tests / Python 3.11 / Windows (push) Has been cancelled

This commit is contained in:
chengma
2026-07-03 09:26:27 +08:00
parent dd2a8e3360
commit 6d4f60fcdb
12 changed files with 309 additions and 12 deletions
+8
View File
@@ -1087,3 +1087,11 @@
- 边界:不自动登录、不填密码、不绕过验证码;未改商品页、上传、提交逻辑。
- 测试:`tests/test_editor_login.py` 增加真实 accounts 登录 URL 覆盖。
- 验证:`python -m unittest discover -s tests -p "test_editor_login.py"` 通过(37 tests)。
## 【2026-07-03】T-524 完成 · PyInstaller 打包为免安装 exe
- 代码/配置:新增 `cmshopee.spec`、`scripts/build_exe.ps1`、`requirements-build.txt`;`main.py` 在 PyInstaller frozen 模式下把工作目录切到 `cmshopee.exe` 所在目录,确保配置、DB、图片、日志、登录态和提示词在 exe 同级目录生成/读取;`.gitignore` 新增 `build/`、`dist/`、`db.sqlite`、`prompts/`、`title_prompt.txt`。
- 打包安全:`cmshopee.spec` 不声明本地数据 `datas`;构建脚本打包后检查 `dist\cmshopee`,发现 `config.json`、`config/ai_models.json`、`cmshopee.db*`、`db.sqlite`、`chrome_user_data_dir/`、`images/`、`logs/`、`prompts/`、`title_prompt.txt` 会直接失败;脚本会打印当前 Python 版本,低于项目目标 3.10 时给出警告。
- 文档:新增 `docs/packaging.md`,同步 `docs/README.md`、`docs/03-tech-stack.md`、`docs/06-tasks.md`、`docs/current-state.md`;T-524 标为 DONE,下一个可领取任务更新为 T-525。
- 测试:新增 `tests/test_packaging.py` 覆盖 frozen 入口路径、spec 不打包本地数据、构建脚本排除列表。
- 验证:`python -m compileall app main.py` 通过;`python -m unittest discover -s tests -p "test_packaging.py"` 通过(3 tests);`python -m unittest discover -s tests` 通过(170 tests);`git diff --check` 无空白错误(仅 LF/CRLF 提示);`powershell -ExecutionPolicy Bypass -File scripts\build_exe.ps1` 成功产出 `dist\cmshopee\cmshopee.exe`,脚本确认未混入本地数据。本机当前 `python` 为 3.7.9,构建脚本已提示低于项目目标;正式发布建议切到 Python 3.10+ 环境后重新打包。