Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

[CodeStyle] Ruff upgrade and addition of paddle.base check #57367

Closed
gouzil opened this issue Sep 15, 2023 · 9 comments
Closed

[CodeStyle] Ruff upgrade and addition of paddle.base check #57367

gouzil opened this issue Sep 15, 2023 · 9 comments
Assignees
Labels
PFCC Paddle Framework Contributor Club,https://github.com/PaddlePaddle/community/tree/master/pfcc status/close 已关闭

Comments

@gouzil
Copy link
Member

gouzil commented Sep 15, 2023

任务背景

我们已经在 #46039#51729 等分别引入了 Flake8、isort、Ruff 等代码检查工具,但当时因为 python/paddle/fluid 下存在大量代码风格较差的历史遗留代码,因此这些工具的引入都没监控 fluid 目录,而经过近一年的 fluid 清理之后,我们终于已经在 #56576 彻底将 fluid 遗留代码清除,并将剩余核心代码 rename 到 base 下。而这部分剩余的核心代码是需要监控的(即 python/paddle/base 下的)。

本任务主要包含两部分,一部分是 Ruff 工具常规升级,另一部分是移除 Ruff、isort、Flake8 配置中对 python/paddle/base 的 ignore,使该目录也列入代码风格监控之列。

⭐️ 提交PR标题 ⭐️:[CodeStyle][task $N] enable $TOOL $ERRNO rule in python/paddle/base

  • 这里 $N 代表任务序号,$TOOL 代表工具名(RuffisortFlake8 其一),$ERRNO 代表错误码,比如任务 3 标题为 [CodeStyle][task 3] enable Ruff PLR1711 rule in python/paddle/base
  • 请在 PR 描述里 @gouzil,并链接本 issue #57367,会由任务 Leader @gouzil 进行任务一审,一审通过后由 @SigureMo 进行二审

整体进度(39/39)

按 merge 的时间顺序,排名不分先后: @gouzil (6) @ooooo-create (10) @linzeyang (4) @zrr1999 (2) @ccsuzzh (2) @enkilee (6) @zade23 (2) @Kaedeharai (3) @longranger2 (1) @RedContritio (1) @yuchen202 (1) @Liyulingyue (1)

✅ ruff

删除 ignore 中的 ./python/paddle/base/** 选项的错误码,并修复已存在的所有检查

序号 错误码 存量 认领人 完成 PR 备注
1 ✅UP032 983 @Liyulingyue #57408✅, #57409#58175 base存量 / 升级存量
2 ✅F401 165 @zrr1999 #57388 base存量, 查看isort部分
3 ✅PLR1711 144 @zrr1999 #57444 新增检查
4 ✅NPY003 64 @enkilee #57428 新增检查
5 ✅ PLR1701 64 @linzeyang #57391 新增检查
6 ✅UP018 43 @enkilee #57436 升级存量
7 ✅UP031 33 @Kaedeharai #57665 base存量
8 ✅C408 28 @Kaedeharai #57864 base存量
9 ✅UP030 23 @Kaedeharai #58162 base存量
10 ✅B017 15 @enkilee #58185 升级存量
11 ✅ F403 11 @ooooo-create #57379#57501 base存量
12 ✅UP028 11 @ooooo-create #57405 base存量 / 升级存量
13 ✅F522 5 @ooooo-create #57402 base存量
14 ✅PLR1722 4 @ooooo-create #57401 base存量
15 ✅ PLW3301 4 @ooooo-create #57400 新增检查
16 ✅B010 4 @ooooo-create #57399 base存量
17 ✅ F811 3 @ooooo-create #57398 base存量
18 ✅C403 3 @ooooo-create #57397 base存量
19 ✅UP034 3 @ooooo-create #57395 base存量
20 ✅ B011 2 @ooooo-create #57376 base存量
21 ✅C405 2 @yuchen202 #57377 base存量
22 ✅ C417 2 @zade23 #57634 base存量
23 ✅PLR0402 2 @zade23 #57607 base存量
24 ✅ F401 2 @gouzil #57145 升级存量
25 ✅ PLR1722 2 @gouzil #57145 升级存量
26 ✅ B004 1 @linzeyang #57708 base存量
27 ✅ B009 1 @linzeyang #57709 base存量
28 ✅ B016 1 @linzeyang #57710 base存量
29 ✅ B019 1 @enkilee #58186 base存量
30 ✅ C411 1 @longranger2 #57707 base存量
31 ✅ C416 1 @enkilee #58186 base存量
32 ✅ F821 1 @enkilee #58186 base存量
33 ✅PLC0414 1 @RedContritio #57876 base存量
34 ✅ F811 1 @gouzil #57145 升级存量

任务说明

对应文件pyproject.toml

base存量: 在tool.ruff.per-file-ignores下删除对应的错误码

"python/paddle/base/**" = [
-    "F401",
...
    "PLC0414",
]

升级存量:解开select中的注释

select = [
...
    "PLR0402",
-    # "PLR1701",
+    "PLR1701",
...
]

base存量:在tool.ruff.per-file-ignores下删除所有错误码

-# UP018
-"python/paddle/distributed/fleet/meta_optimizers/localsgd_optimizer.py" = ["UP018"]
-"python/paddle/distributed/fleet/meta_optimizers/sharding/utils.py" = ["UP018", "UP032"]
+"python/paddle/distributed/fleet/meta_optimizers/sharding/utils.py" = ["UP032"]
-...

常用命令

# 安装 ruff v0.0.289
pip install ruff==0.0.289
# 自动修复
ruff --select NPY003 . --fix

# 手动修复
ruff --select PLR5501 .
# 手动修复中...

相关文档

flake8

删除 per-file-ignores 中的 # tmp ignore 下对应的错误码,并修复已存在的所有检查

序号 错误码 存量 认领人 完成 PR
35 ✅E712 14 @gouzil #58319
36 ✅E266 4 @gouzil #58319
37 ✅E714 1 @gouzil #58319
38 ✅ E713 1 @ccsuzzh #57412

任务说明

删除.flake8文件中删除对应的错误码

per-file-ignores =
    # These files need tabs for testing.
    test/dygraph_to_static/test_error.py:E101,W191
    # temp ignore base directory
    python/paddle/base/*:
        E713,
-        E712,
        E266,
        E714

常用命令

# 安装 flake8 v5.0.4
pip install flake8==5.0.4
# 自动修复
flake8 --config .flake8

相关文档

✅ isort

需要等待F401引入完成后操作

序号 存量 认领人 完成 PR 备注
39✅ 29 @ccsuzzh #57413#57686#57839 需要等待 ruff 中的 F401 完成
extend_skip_glob = [
    # These files do not need to be formatted,
    # see .flake8 for more details
-    "python/paddle/base/**",
    "python/paddle/utils/gast/**",
]

手动触发自动修复

isort python/paddle/base/
# 或者
isort ./
@gouzil gouzil added status/new-issue 新建 type/others 其他问题 labels Sep 15, 2023
@SigureMo SigureMo changed the title [CodeStyle] Ruff upgrade and addition of paddle.base check [CodeStyle] Ruff upgrade and addition of paddle.base check Sep 15, 2023
@luotao1 luotao1 moved this to In Progress in Call for Contributions Sep 15, 2023
@longranger2
Copy link
Contributor

认领30

@whisky-12
Copy link
Contributor

认领 31 32

@Kaedeharai
Copy link
Contributor

认领 7-9

@linzeyang
Copy link
Contributor

linzeyang commented Sep 15, 2023

认领 No.5: PLR1701

relevant PR: #57391

@Ligoml Ligoml added PFCC Paddle Framework Contributor Club,https://github.com/PaddlePaddle/community/tree/master/pfcc and removed status/new-issue 新建 type/others 其他问题 labels Sep 15, 2023
@entired
Copy link
Contributor

entired commented Sep 15, 2023

认领35-37

@ccsuzzh
Copy link
Contributor

ccsuzzh commented Sep 15, 2023

认领 38、39

@linzeyang
Copy link
Contributor

意向认领 task 26, 27, 28

@liyongchao911 如果你还在这些任务上,还请你回复一下

@liyongchao911
Copy link
Contributor

意向认领 task 26, 27, 28

@liyongchao911 如果你还在这些任务上,还请你回复一下

OK!

@luotao1
Copy link
Contributor

luotao1 commented Nov 3, 2023

[CodeStyle] Ruff upgrade and addition of paddle.base check 已全部完成,感谢参与的小伙伴们!

按 merge 的时间顺序,排名不分先后: @gouzil (6) @ooooo-create (10) @linzeyang (4) @zrr1999 (2) @ccsuzzh (2) @enkilee (6) @zade23 (2) @Kaedeharai (3) @longranger2 (1) @RedContritio (1) @yuchen202 (1) @Liyulingyue (1)

欢迎继续参与快乐开源的其他任务

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
PFCC Paddle Framework Contributor Club,https://github.com/PaddlePaddle/community/tree/master/pfcc status/close 已关闭
Projects
Development

No branches or pull requests