Merged
infra(pre-commit): 引入 pre-commit/OAT 检查体系(样式统一覆盖) #526
infra(pre-commit): 引入 pre-commit/OAT 检查体系(样式统一覆盖) #526
Merged
景明Add on Oct 19
景明
景明
Oct 19

关联Issue https://gitcode.com/cann/cann-samples/issues/303

描述

✨ 特性增强

仓内无提交期检查(Issue #303)。引入 pre-commit + OAT 检查体系(skills-dev PR#191 同款实现,经本仓 --all-files 全量实测校准),8 文件 +877/-22。

件 内容
.pre-commit-config.yaml 五套钩子(同上体系);codespell --skip 补 *.asc(与 py/cpp/h 同口径:代码标识符主导)
OAT.xml Huawei 版权策略项 + 类型豁免;licensematcher 统一 CANN-2.0;后补 *.excalidraw(绘图 JSON)、requirements*.txt 豁免
scripts/ 三件套(oat_check.sh / run_codespell.sh / format_cpp.sh,同上)
.clang-format 覆盖为体系统一样式(Google 基线 + 指针左对齐——与本仓原生 Left 惯例一致)
docs/pre-commit_guide.md 使用指南
.gitignore 忽略 pre-commit_reports/

校准结果(--all-files 实测)

私钥/JSON/YAML/OAT 全过(263 png 走豁免);codespell 豁免 asc 后通过;ruff 仅 14 条残留(E712×9/F841×4/E731×1);残留债务为 asc/cc/h/CMakeLists 缺头(增量消化)。

检视意见驱动的后续修复(已并入本提交)

  • oat_check.sh:① 批扫描修复——-f argv 逗号串超 MAX_ARG_STRLEN 即 E2BIG 且异常退出曾被当"通过"(大文件量静默失效),改为 120KB 自动分批 + 失败阻塞;② eval 改数组传参加引(防 ()/&/[] 路径打断 shell);③ done-marker 补第四处守卫("无报告"分支限无参落盘,防 args 子集冒充全量)
  • format_cpp.sh:排除目录尾斜杠致 find -path 永不匹配、prune 失效(@Huang-Peng 检视)——去尾斜杠
  • .clang-format:PointerAlignment: Left(int* p 指针随类型,领导确认口径,引用同规则)+ 年份 2026
  • 顺带:脚本乱码 ??→→;OAT.xml *.mjs 重复豁免去重

测试

  • 本提交自身过全部钩子(含 OAT 分批真实扫描);yaml/xml/bash 语法全过
  • 残留命中均为真实存量债(缺头),按增量消化(不建议 --all-files 翻旧账)

类型标签

likedislike
Pull Request has been successfully merged by CANN-robot.
(Thank you for 景明's contribution.)
景明景明
Oct 19 Created pull request, commit 3b44a699
景明景明
Oct 19 Associated issue: [Bug-Report|缺陷反馈]: 针对GMM-HIF8的编程实践的样例中在group_list为3 m k n 438 316 203时执行精度失败,仓库缺乏 pre-commit 代码检查与开源合规体系
atomgit-bot
atomgit-bot
Oct 19 Comments:

变更摘要

本 PR 为仓库引入 pre-commit + OAT 提交期检查体系,新增 .pre-commit-config.yaml 配置五套钩子(pre-commit 基础检查、clang-format、ruff、codespell、OAT 合规扫描),并配套新增 scripts/ 下的 oat_check.sh、run_codespell.sh、format_cpp.sh 三个脚本;同时调整 .clang-format 为体系统一样式、扩展 OAT.xml 的版权策略与文件豁免规则,并忽略 pre-commit_reports/ 报告目录。目标是补齐仓内缺失的提交期检查能力,统一代码样式与合规口径。

主要改动

  • 新增 pre-commit 钩子配置:.pre-commit-config.yaml 定义 trailing-whitespace、end-of-file-fixer、check-yaml、check-json、detect-private-key、clang-format、ruff-check/ruff-format、codespell 及本地 oat-check 等钩子,通过 exclude/--skip 对 *.asc、kb/、*.jsonl 等做豁免,codespell 经 entry: bash scripts/run_codespell.sh 包装输出留证。
  • 新增 OAT 合规检查脚本:scripts/oat_check.sh 自动定位 Python 3.7+、按需安装 oat-py 并用 flock 串行化,实现 PR 范围去重(基于 merge-base 与 HEAD done-marker)、并行调用去重,并在文件清单超过 120KB 时按 _MAX_F_LEN 自动分批扫描,扫描执行失败时阻塞提交而非静默通过。
  • 新增 C++ 格式化脚本:scripts/format_cpp.sh 以 CLANG_FORMAT 环境变量可覆盖的方式调用 clang-format -i --style=file,通过 EXCLUDE_DIRS(build、build_out、third_party、.git)构造 find -path ... -prune 表达式排除目录。
  • 覆盖 .clang-format 样式:将样式调整为 CLI 体系中统一口径,改为 PointerAlignment: Left、AlignAfterOpenBracket: Align、AfterEnum: false、AllowShortFunctionsOnASingleLine: Empty、IndentWidth/TabWidth: 4,并新增 SortUsingDeclarations、PackConstructorInitializers、PenaltyBreakAssignment 等配置项。
  • 扩展 OAT.xml 合规策略与豁免:新增 Huawei 版权 policyitem、将 licensematcher 名称统一为 CANN-2.0,并在各 filefilter 中补充 *.mjs、requirements*.txt、*.excalidraw、*.yaml/*.yml、*.csv、*.png 等豁免项。
likedislike
Incorrect?
atomgit-bot
atomgit-bot
Oct 19 Comments:

代码审查

✅ 未发现问题

likedislike
Incorrect?
CANN-robotCANN-robotCollaborators
Oct 19 Added label: cann-cla/yes
CANN-robot
CANN-robotCollaborators
Oct 19 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
repo-cann/cann-samples ✅ 杨阳, 汤平川 (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
CANN-robotCANN-robotCollaborators
Oct 19 Set yangyang016,zhou-qilong,rxtfeng,loov1,zhangzijie,zl_hw,pingchuantang,llimwang,gubaocheng as approver
CANN-robotCANN-robotCollaborators
Oct 19 Set yangyang016,zhou-qilong,rxtfeng,loov1,zhangzijie,zl_hw,pingchuantang,llimwang,gubaocheng as approver
景明
景明
Oct 19 Comments:

compile

likedislike
景明景明
Oct 19 Pre merge succeeded (commit_id: c8f452a5e96bfe1e012ae304018f3a591d7e5332)
CANN-robot
CANN-robotCollaborators
Oct 19 Comments:
🚀 CI 流水线已启动
📋 执行详情: 点击查看流水线
likedislike
CANN-robotCANN-robotCollaborators
Oct 19 Added label: ci-pipeline-running
CANN-robotCANN-robotCollaborators
Oct 19 Removed label: ci-pipeline-running
CANN-robotCANN-robotCollaborators
Oct 19 Added label: ci-pipeline-passed
yangyang016
yangyang016Collaborators
Oct 19 Comments:

/lgtm
/approve

likedislike
CANN-robotCANN-robotCollaborators
Oct 19 Added label: approved
TangPC
TangPCCollaborators
Oct 19 Comments:

/lgtm
/approve

likedislike
CANN-robotCANN-robotCollaborators
Oct 19 Added label: lgtm
CANN-robotCANN-robotCollaborators
Oct 19 Merged pull request