Pull Request has been successfully merged by CANN-robot.
(Thank you for 景明's contribution.)变更摘要
本 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 与HEADdone-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等豁免项。


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
/approveor/lgtm- Commenting
/approveimplies 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. 👍


compile


| 🚀 CI 流水线已启动 |
|---|
| 📋 执行详情: 点击查看流水线 |


/lgtm
/approve


/lgtm
/approve


关联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--skip补*.asc(与 py/cpp/h 同口径:代码标识符主导)OAT.xml*.excalidraw(绘图 JSON)、requirements*.txt豁免scripts/.clang-formatdocs/pre-commit_guide.md.gitignore校准结果(--all-files 实测)
私钥/JSON/YAML/OAT 全过(263 png 走豁免);codespell 豁免 asc 后通过;ruff 仅 14 条残留(E712×9/F841×4/E731×1);残留债务为 asc/cc/h/CMakeLists 缺头(增量消化)。
检视意见驱动的后续修复(已并入本提交)
-fargv 逗号串超 MAX_ARG_STRLEN 即 E2BIG 且异常退出曾被当"通过"(大文件量静默失效),改为 120KB 自动分批 + 失败阻塞;②eval改数组传参加引(防()/&/[]路径打断 shell);③ done-marker 补第四处守卫("无报告"分支限无参落盘,防 args 子集冒充全量)find -path永不匹配、prune 失效(@Huang-Peng 检视)——去尾斜杠.clang-format:PointerAlignment: Left(int* p指针随类型,领导确认口径,引用同规则)+ 年份 2026??→→;OAT.xml*.mjs重复豁免去重测试
--all-files翻旧账)类型标签