chore: add ruff checks

This commit is contained in:
chengma
2026-07-07 15:11:40 +08:00
parent 862f791fde
commit 6e2347e1c8
13 changed files with 81 additions and 16 deletions
+7 -1
View File
@@ -24,6 +24,7 @@
| 运行日志 | SQLite `run_logs` / `run_log_events` | 已定 | ③ dry-run 与真实更新都留痕;结构化内容走脱敏 |
| 图片处理 | `requests`(下载)+ `Pillow`(按分辨率/jpg质量存盘) | 部分待定 | 下载旧封面;新封面按 resolution 生成、jpg_quality 存盘 |
| 测试 | `python -m compileall app main.py` + `unittest` + 手动 CDP/AI 验证 | 已定(分层) | 配置/DB/Excel/prompts 用单测;CDP/Shopee 与真实 AI 属集成验证或 mock |
| 代码质量 | `ruff`(lint + format 可用) | 已定 | T-525 引入开发检查依赖;CI 先强制安全类 lint,不做全仓格式化重排 |
| 打包分发 | PyInstaller onedir(`cmshopee.spec`) | 已定 | 产出 Windows 免安装文件夹;不内置配置、DB、图片、日志、Chrome 登录态或提示词等本地数据;运行时统一写入程序同级 `data/` |
## 二、决策记录与演进
@@ -48,7 +49,10 @@
| 用途 | 命令 |
| --- | --- |
| 安装依赖 | `py -3.10 -m pip install -r requirements.txt` |
| 安装开发检查依赖 | `py -3.10 -m pip install -r requirements-dev.txt` |
| 检查 PySide6 | `python -c "import PySide6; print(PySide6.__version__)"` |
| ruff 安全检查 | `py -3.10 -m ruff check app tests main.py` |
| ruff 格式化(按需) | `py -3.10 -m ruff format app tests main.py` |
| 语法检查 | `py -3.10 -m compileall app main.py` |
| 启动 GUI | `py -3.10 main.py` / `py -3.10 -m app` |
| 单元测试(T-006 后) | `py -3.10 -m unittest discover -s tests` |
@@ -75,6 +79,7 @@ set AUTO=1 && python prototypes/demo.py
## 四、依赖纪律
- 运行时第三方依赖统一写入根目录 `requirements.txt` 并锁定版本;换机或 CI 使用 `python -m pip install -r requirements.txt` 安装。
- 开发检查依赖写入 `requirements-dev.txt`;当前只包含 ruff,不属于运行时或打包依赖。
- 打包依赖只写入 `requirements-build.txt`;PyInstaller 不属于运行时依赖,不写进 `requirements.txt`。
- 当前直接依赖锁定:PySide6 6.5.3、openpyxl 3.1.3、requests 2.31.0、websocket-client 1.6.1、Pillow 9.5.0。
- 新增第三方依赖前,先在本文说明用途、替代方案和维护成本,并同步更新 `requirements.txt`。
@@ -87,8 +92,9 @@ set AUTO=1 && python prototypes/demo.py
| 层级 | 覆盖对象 | 验证方式 |
| --- | --- | --- |
| 语法 | 正式代码包与入口 | `python -m compileall app main.py` |
| lint | 正式代码、测试与入口 | `python -m ruff check app tests main.py`;当前只开启安全类规则,格式化命令可用但不强制全仓重排 |
| 单元 | `appconfig/db/excel/prompts/config/chrome` 的纯逻辑 | T-006 建立 `tests/` 后运行 `python -m unittest discover -s tests`,使用临时目录/临时 SQLite/样例 Excel |
| GUI 轻测 | PySide6 主窗口可创建、Tab 数量、worker signal 基本行为 | 可用 unittest 构造 `QApplication`,不连真实 Shopee |
| CI | push / pull_request 自动跑语法 + 全量 unittest | `.github/workflows/tests.yml` 安装 `requirements.txt`,运行 `python -m compileall app main.py` 与 `python -m unittest discover -s tests`;不连真实 Shopee/AI |
| CI | push / pull_request 自动跑 ruff + 语法 + 全量 unittest | `.github/workflows/tests.yml` 安装 `requirements.txt` 与 `requirements-dev.txt`,运行 `python -m ruff check app tests main.py`、`python -m compileall app main.py` 与 `python -m unittest discover -s tests`;不连真实 Shopee/AI |
| 集成 | CDP/editor 操作 Shopee 测试商品 | 手动跑 `prototypes/demo.py` 或后续专用集成脚本 |
| 外部 AI | 模型连接、文本/图像生成 | 默认 mock;真实调用只在手动验证时跑,避免成本和限流 |