Merged
style: ruff 配置行宽 120 并关闭 magic trailing comma #6286
style: ruff 配置行宽 120 并关闭 magic trailing comma #6286
Merged
zhangyujia77Add on Sep 21
zhangyujia77
zhangyujia77Collaborators
Sep 21

描述

ruff.toml 新增两项配置并据此重排全仓 Python 代码:

line-length = 120                 行宽从默认 88 放宽到 120
[format]
skip-magic-trailing-comma = true  忽略末尾逗号的强制展开语义

为什么改 line-length

ruff 的 line-length 此前从未在仓库任何地方配置过 —— ruff.toml 只设了target-version,全仓搜 line-length 零命中,pre-commit 的 ruff hook 也没传参。
所以生效值 88 是 ruff 内置默认(沿用 Black 的约定),不是评估过的技术决策:

$ ruff check --show-settings
Settings path: ".../asc-devkit/ruff.toml"
linter.line_length = 88

120 有三层依据:

  1. 本仓 C++ 侧已定 120 —— .clang-format: ColumnLimit: 120。同一仓库 C++ 120、Python 88 本身不一致。
  2. CANN 生态其余 Python 仓统一为 120 —— pyasc、pypto、pto-isa、ops-test-kit、vllm-ascend(ruff),torch_npu、pytorch(flake8)。asc-devkit 是其中唯一没配的。
  3. 本仓 Python 历史上事实遵守 120 —— ruff-format 落地前,非空行 P99.5 = 119,99.82% 的行 ≤ 120;超 120 的 38 行基本是嵌在 Python 里的 C++ 模板与宏定义。

88 列会把多参数调用强制拆成逐参数一行,一条语句常常变 3-5 行:

# 前(1 行)
raise RuntimeError("Length of ASCENDC_TPL_UINT_{} {} is too short.".format(self.macro_type, self.name))
# 后(5 行)
raise RuntimeError(
    "Length of ASCENDC_TPL_UINT_{} {} is too short.".format(
        self.macro_type, self.name
    )
)

为什么关 magic trailing comma

末尾逗号会让 ruff-format 强制保持展开,即使该行放得下。统计范围内现存 886 处此类逗号,绝大多数是 88 列时期 ruff 自己折行时补上的,并非作者意图 ——换到 120 列后这些调用本可收拢,却因那个自动留下的逗号继续保持展开。

关联的Issue

测试

文档更新

类型标签

likedislike
Pull Request has been successfully merged by CANN-robot.
(Thank you for zhangyujia77's contribution.)
zhangyujia77zhangyujia77Collaborators
Sep 21 Created pull request, commit 4257ff1b
atomgit-bot
atomgit-bot
Sep 21 Comments:

🤖 正在生成合并请求摘要,请稍候…

likedislike
Incorrect?
atomgit-bot
atomgit-bot
Sep 21 Comments:

🤖 AI 代码检视正在进行中,请稍候…

likedislike
Incorrect?
CANN-robotCANN-robotCollaborators
Sep 21 Added label: cann-cla/yes
CANN-robot
CANN-robotCollaborators
Sep 21 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
cmake ✅ 诸葛洵, hujiawen_kaven (2/2) ✅ 诸葛洵 (1/1)
docs ✅ ai_xin, 诸葛洵, hujiawen_kaven (3/2) ✅ ai_xin (1/1)
examples ✅ 诸葛洵, ai_xin, hujiawen_kaven (3/2) ✅ ai_xin, 诸葛洵 (2/1)
repo-cann/asc-devkit ✅ 诸葛洵, hujiawen_kaven (2/2) ✅ 诸葛洵, hujiawen_kaven (2/1)
scripts ✅ 诸葛洵, hujiawen_kaven (2/2) ✅ 诸葛洵 (1/1)
tools ✅ 诸葛洵, hujiawen_kaven (2/2) ✅ 诸葛洵 (1/1)
tools/build ✅ hujiawen_kaven, 诸葛洵 (2/2) ✅ hujiawen_kaven (1/1)

💡 Tip:

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

CLA Signature Pass

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

likedislike
CANN-robotCANN-robotCollaborators
Sep 21 Set zengjuan,zhanghao_0689,suqwe,kevin365,wulinyu,qin437231,kong0808,dengjing_aoe,YeZZzzz1,bluesky901,yangbinhua,zhudi22,chenyiyuan,xun_zhuge,XuebinYang,sjtulxh,bianque,houyuyang,Lycheeeee,YANXI_ZHAO,chentianyu19,shi_nanxiang,wuyang_hw,jiangxinyu3,munanhw,ai_xin,ascendhjh,hujiawen_kaven,wangxiaozhi,DragonBornHD84,louyuxuan,changxianyu,hyolee,yukangchen as approver
11 event messages are collapsed here。 See more
CANN-robotCANN-robotCollaborators
Sep 21 Added label: cann-cla/yes
zhangyujia77
zhangyujia77Collaborators
Sep 21 Comments:

compile

likedislike
zhangyujia77zhangyujia77Collaborators
Sep 21 Pre merge succeeded (commit_id: 93640b09519f015c0bc701ab2c6fd5c30aa20663)
zhangyujia77zhangyujia77Collaborators
Sep 21 Modify description of pull request
CANN-robot
CANN-robotCollaborators
Sep 21 Comments:
🚀 CI 流水线已启动
📋 执行详情: 点击查看流水线
likedislike
CANN-robotCANN-robotCollaborators
Sep 21 Added label: ci-pipeline-running
zhangyujia77zhangyujia77Collaborators
Sep 21 Modify description of pull request
zhugexun_sjtu
zhugexun_sjtuCollaborators
Sep 21 Comments:

/lgtm

likedislike
zhugexun_sjtu
zhugexun_sjtuCollaborators
Sep 21 Comments:

/approve

likedislike
hujiawen_kaven
hujiawen_kavenCollaborators
Sep 21 Comments:

/approve
/lgtm

likedislike
CANN-robotCANN-robotCollaborators
Sep 21 Added label: lgtm
ai_xin
ai_xinCollaborators
Sep 21 Comments:

/approve

likedislike
CANN-robotCANN-robotCollaborators
Sep 21 Added label: approved
CANN-robotCANN-robotCollaborators
Sep 21 Removed label: ci-pipeline-running
CANN-robotCANN-robotCollaborators
Sep 21 Added label: ci-pipeline-passed
CANN-robotCANN-robotCollaborators
Sep 21 Merged pull request