Merged
feat(pre-commit): 拦截类钩子报告统一落盘 pre-commit_reports + 健壮性与策略对齐 #12834
feat(pre-commit): 拦截类钩子报告统一落盘 pre-commit_reports + 健壮性与策略对齐 #12834
Merged
景明Add on Sep 23
景明
景明Collaborators
Sep 23

关联Issue https://gitcode.com/cann/ops-transformer/issues/5016

描述

🐛 Bug 修复 / ✨ 特性增强

围绕既有 pre-commit 体系的三处完善(8 文件 +38/-12,1 笔提交):拦截类钩子报告落盘、脚本健壮性修复、策略与文档对齐。全部经 --all-files 全量实测校准。

一、拦截类钩子报告统一落盘 pre-commit_reports/(不入 git)

改动 内容
scripts/run_codespell.sh(新增) codespell 输出 tee 到 pre-commit_reports/codespell.log(entry 覆写仍跑托管 venv,PIPESTATUS 保退出码)
.pre-commit-config.yaml codespell entry 指向包装脚本
scripts/oat_check.sh 报告落点 oat_reports/result.txt → pre-commit_reports/oat_result.txt(单文件与批量两条写路径同步)
.gitignore oat_reports/ → pre-commit_reports/
docs/zh/develop/pre-commit_guide.md 失败排查节补报告位置说明

自动修类钩子(clang-format/ruff)直接改好文件无需报告;拼写/合规须人工处理,报告落盘便于复查与喂给 agent 修复。

二、健壮性修复(姊妹仓全量实测暴露的同款隐患)

改动 内容
scripts/oat_check.sh eval 拼接改数组传参 + -f 加引——文件名含 ()/&/[]/空格时 eval 会打断 shell 致扫描假死/假过(本仓当前 0 此类文件名,防御性修复)
scripts/format_cpp.sh 目录不存在时原仅打印提示仍继续执行,改为报错退出(exit 1)

三、策略与文档对齐

改动 内容
OAT.xml 豁免 requirements*.txt(依赖清单,双过滤器)、*.info(cmake help,双过滤器)——全量扫描 250→240,残留均为真实缺头债(增量消化)
trailing-whitespace 补 --markdown-linebreak-ext=md(防静默剥掉 md 双空格硬换行语法,实测:双空格保留、三空格收敛、单空格照删)
.clang-format PointerAlignment 改 Left(int* p 指针随类型,领导确认口径;引用 & 同规则);年份 2025→2026

测试

  • 全量 OAT 16 批真实扫描(无双误退出码);缺头 py 拦截有效、豁免类型放行
  • md 双空格保留实测通过;codespell 命中落盘、OAT 报告落盘且目录不被 git 跟踪
  • 本提交自身过全部钩子(含 OAT);yaml/xml/bash 语法全过

留作仓主决策(本 PR 不动)

  • ruff --ignore 现行清单含 F841,F821,F401 等 F 系列——skills-dev 口径为「F 系列全启用抓真 bug」,两仓策略不同,建议仓主确认后另行统一
  • third_party/catlass、third_party/opbase 下同名 oat_check.sh 为上游副本,未动

类型标签

likedislike
Pull Request has been successfully merged by CANN-robot.
(Thank you for 景明's contribution.)
景明景明Collaborators
Sep 23 Created pull request, commit ef1d35fe
景明景明Collaborators
Sep 23 Associated issue: [Bug-Report|缺陷反馈]: matmulAllReduce example编译运行时报错找不到头文件
atomgit-bot
atomgit-bot
Sep 23 Comments:

变更摘要

本 PR 为 pre-commit 拦截类钩子(codespell、OAT)引入报告持久化机制,将原先仅打印到终端的输出统一落盘到 pre-commit_reports/ 目录,便于事后排查拼写与合规问题。核心做法是新增 scripts/run_codespell.sh 包装脚本承接 codespell 输出,调整 scripts/oat_check.sh 的报告落点与文件名,并同步更新 .pre-commit-config.yaml 钩子 entry、.gitignore 忽略规则及开发文档说明。

主要改动

  • 新增 codespell 报告包装脚本: 新增 scripts/run_codespell.sh,将 codespell "$@" 的输出通过 tee 同时写入 pre-commit_reports/codespell.log,并以 exit "${PIPESTATUS[0]}" 保留原始退出码。
  • codespell 钩子 entry 改写: .pre-commit-config.yaml 中 codespell 钩子的 entry 改为 bash scripts/run_codespell.sh,使钩子经包装脚本执行以落盘报告。
  • OAT 报告目录与文件名调整: scripts/oat_check.sh 中 OAT_RESULT_DIR 由 $REPO_ROOT/oat_reports 改为 $REPO_ROOT/pre-commit_reports,报告文件由 result.txt 更名为 oat_result.txt(批量与单文件两条写入路径同步更新)。
  • 忽略规则同步: .gitignore 将 oat_reports/ 替换为 pre-commit_reports/,使新报告目录不被 git 跟踪。
  • format_cpp.sh 目录校验修复: scripts/format_cpp.sh 在目标目录不存在时,由仅打印提示改为输出错误信息到 stderr 并 exit 1 终止执行。
likedislike
Incorrect?
CANN-robotCANN-robotCollaborators
Sep 23 Added label: cann-cla/yes
CANN-robot
CANN-robotCollaborators
Sep 23 Comments:

Thanks for your pull-request.
The full list of commands accepted by me can be found at here.
You can get sig-info at here.
You can self-configure the PR merge rules for this repository. For more details, please refer to Here.
For more, you also can visit HICANN.


PR Approval Progress

✅ Congratulations! All modules have met the lgtm and approve requirements.

Module Approval Details

module lgtm status approve status
OAT.xml ✅ 马兵, 蒋礼锐, wang-minbo (3/2) ✅ 蒋礼锐, wang-minbo, 马兵 (3/1)
docs ✅ 蒋礼锐, wang-minbo, 马兵 (3/2) ✅ wang-minbo, 马兵, 蒋礼锐 (3/1)
scripts ✅ 蒋礼锐, wang-minbo, 马兵 (3/2) ✅ 蒋礼锐, wang-minbo, 马兵 (3/1)
sig-ops-transformer ✅ 蒋礼锐, 马兵 (2/2) ✅ 蒋礼锐, 马兵 (2/1)

💡 Tip:

  • Committer can comment /approve or /lgtm
  • Commenting /approve implies both code review (lgtm) and intent to merge (approve)

CLA Signature Pass

gitcode_lijd, thanks for your pull request. All authors of the commits have signed the CLA. 👍

likedislike
108 messages are collapsed here。 See more
mabingCollaborators
Sep 29 Comments:

/approve
/lgtm

likedislike
CANN-robotCANN-robotCollaborators
Sep 29 Added label: approved
jiang-liruiCollaborators
Sep 29 Comments:

/approve
/lgtm

likedislike
CANN-robotCANN-robotCollaborators
Sep 29 Added label: lgtm
CANN-robotCANN-robotCollaborators
Sep 29 Merged pull request