Files
yml2213 a3c3a46b9c fix(tooling): 修复 pyright 解释器配置与类型守卫,补齐 ruff 门禁与两处历史 bug
- pyrightconfig.json 钉死 Python 3.12 虚拟环境,消除由于查找系统 Python 3.9 带来的假性报错
- 修复 huya/login.py 引用不存在函数的问题并补充单元测试
- 修复 browser_harvest.py 对 set 下标访问的错误并提升报错信息质量
- 虎牙 6 个子路由显式导入依赖,消除 import * 带来的未定义变量报警
- 规范化 Pydantic Field(default=...) 默认值声明
- 完善 solver.py / app_login.py 等核心路径类型守卫与 @overload 重载
- 在 pyproject.toml 中显式锁定 ruff lint 规则集 (E4, E7, E9, F, B, I, BLE)
- 门禁脚本同步增加 ruff check 检查并在 AGENTS.md 补齐实践经验总结
2026-10-08 12:33:39 +08:00

65 lines
1.8 KiB
Bash
Executable File

#!/usr/bin/env bash
set -euo pipefail
cd "$(git rev-parse --show-toplevel)"
push_lines="$(cat)"
while read -r local_ref local_sha remote_ref remote_sha; do
if [ "$local_sha" = "0000000000000000000000000000000000000000" ]; then
echo "[pre-push] 分支删除推送,跳过测试"
exit 0
fi
done <<< "$push_lines"
if [ "${SKIP_TESTS:-0}" = "1" ]; then
echo "[pre-push] SKIP_TESTS=1,跳过测试"
exit 0
fi
python_files=()
frontend_changed=0
while read -r local_ref local_sha remote_ref remote_sha; do
[ -z "$local_sha" ] && continue
if [ "$local_sha" = "0000000000000000000000000000000000000000" ]; then
continue
fi
if [ "$remote_sha" = "0000000000000000000000000000000000000000" ]; then
changed_paths="$(git diff-tree --no-commit-id --name-only -r --root "$local_sha")"
else
changed_paths="$(git diff --name-only "$remote_sha..$local_sha")"
fi
while IFS= read -r path; do
[ -z "$path" ] && continue
case "$path" in
*.py)
[ -f "$path" ] && python_files+=("$path")
;;
web/frontend/*)
frontend_changed=1
;;
esac
done <<< "$changed_paths"
done <<< "$push_lines"
if [ "${#python_files[@]}" -gt 0 ]; then
echo "[pre-push] 检查 Python 格式..."
uv run --group dev ruff format --check "${python_files[@]}"
echo "[pre-push] 检查 Python lint..."
uv run --group dev ruff check "${python_files[@]}"
echo "[pre-push] Python 格式 + lint 通过"
fi
if [ "$frontend_changed" -eq 1 ]; then
.githooks/run-frontend-tsc.sh
fi
if [ "${TYPECHECK:-0}" = "1" ]; then
echo "[pre-push] 运行 Pyright 类型检查..."
uv run --group dev pyright
echo "[pre-push] Pyright 通过"
fi
echo "[pre-push] 运行 pytest..."
./dev.sh test -q
echo "[pre-push] pytest 通过"