-
Notifications
You must be signed in to change notification settings - Fork 5.6k
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
CINN 代码风格改进计划 #54953
Labels
status/close
已关闭
Comments
任务拆分✅ 第一阶段 (已完成 🎉)
✅ 第二阶段 (已完成 🎉)✅ CINN 单测
|
序号 | 任务名 | 认领人 | 提交 PR |
---|---|---|---|
11 | ✅ 单测 np.assertTrue 替换 |
@zrr1999 | #55038 |
✅ Flake8 / Ruff 代码风格修复
序号 | 错误码 | 错误数量 | 认领人 | 提交 PR |
---|---|---|---|---|
- | ✅ Ruff - pyflakes | |||
12 | ✅ F401 | 364 | @Liyulingyue | #55012, #55013, #55182 |
13 | ✅ F403 | 272 | @Liyulingyue | #55182, #55255 |
14 | ✅ F632 | 4 | @Liyulingyue | #55013 |
15 | ✅ F811 | 2 | @Liyulingyue | #55013 |
16 | ✅ F821 | 1 | @Liyulingyue | #55103 |
17 | ✅ F901 | 1 | @Liyulingyue | #55103 |
- | ✅ Ruff - flake8-comprehensions | |||
18 | ✅ C408 | 30 | @enkilee | #55087 |
19 | ✅ C416 | 1 | @enkilee | #55087 |
20 | ✅ C417 | 2 | @enkilee | #55087 |
- | ✅ Ruff - pyupgrade | |||
21 | ✅ UP004 | 6 | @gouzil | #54988 |
22 | ✅ UP008 | 4 | @gouzil | #54988 |
23 | ✅ UP027 | 5 | @gouzil | #54988 |
24 | ✅ UP031 | 2 | @gouzil | #54988 |
25 | ✅ UP032 | 29 | @gouzil | #54988 |
26 | ✅ UP034 | 1 | @gouzil | #54988 |
- | ✅ Ruff - pylint | |||
27 | ✅ PLR0402 | 26 | @gouzil | #54990 |
28 | ✅ PLC0414 | 9 | @gouzil | #54990 |
29 | ✅ PLE1205 | 2 | @gouzil | #54990 |
- | ✅ Flake8 - pycodestyle | |||
30 | ✅ E265 | 1 | @ccsuzzh | #55074 |
31 | ✅ E266 | 4 | @ccsuzzh | #55074 |
32 | ✅ E711 | 4 | @ccsuzzh | #55074 |
Note
- F403 为大存量,无法自动修复的任务,需要分批量、根据情况手动修复(
部分目录,比如,看情况吧,这个目录看看好不好整,优先做其他目录,其他目录做完如果这个好整的话,还是建议做一下的)python/cinn
应该直接 ignore 掉,不应该修复 - 统计方式为,首先在配置里删除 exclude 掉的 CINN 目录,然后运行
ruff . --statistics
/flake8 . --statistics
- 如需修复某一错误码,需要先手动删除 [CodeStyle][CINN] exclude cinn files in flake8 and ruff config #54974 中 ignore 掉的该错误码,然后运行工具复现问题
- F403 建议在 F401 全部完成后做,可考虑自动替换,比如
cinn.common
全部成员为Int, String, Target, Type
(举个例子而已,实际肯定比这多),之后一键替换from cinn.common import *
为from cinn.common import Int, String, Target, Type
,利用 F401 即可自动剪掉无用 imports,全部成员可考虑编译 CINN 直接运行时获取或者直接参考源码(大多数是直接写在 pybind 里的)
✅ CMake Lint 代码风格修复
序号 | 错误码 | 错误数量 | 认领人 | 提交 PR |
---|---|---|---|---|
33 | ✅ [readability/logic] |
15 | @ccsuzzh | #54975, #54993 |
本表单由 @GreatV 统计~
✅ Cpplint 代码风格修复
序号 | 错误码 | 错误数量 | 认领人 | 提交 PR |
---|---|---|---|---|
34 | ✅ [runtime/references] |
183 | @GreatV, @zyfncg | #55068, #55009, #55107 |
35 | ✅ [readability/casting] |
76 | @GreatV | #55069 |
36 | ✅ [whitespace/line_length] |
70 | @Difers | #55020 |
37 | ✅ [runtime/explicit] |
51 | @Difers | #55036 |
38 | ✅ [readability/braces] |
25 | @GreatV | #55049 |
39 | ✅ [runtime/int] |
19 | @huangjiyi | #55006 |
40 | ✅ [build/namespaces] |
16 | @GreatV | #55051 |
41 | ✅ [runtime/threadsafe_fn] |
15 | @huangjiyi | #55006 |
42 | ✅ [readability/todo] |
15 | @Sahala08 | #55022 |
43 | ✅ [readability/check] |
11 | @Sahala08 | #55022 |
44 | ✅ [runtime/string] |
6 | @huangjiyi | #55006 |
45 | ✅ [build/include_order] |
6 | @enkilee | #55085 |
46 | ✅ [build/header_guard] |
6 | @enkilee | #55085 |
47 | ✅ [build/include_subdir] |
5 | @enkilee | #55085 |
48 | ✅ [build/include] |
5 | @enkilee | #55085 |
49 | ✅ [whitespace/semicolon] |
4 | @Liyulingyue | #55046 |
50 | ✅ [whitespace/empty_if_body] |
3 | @gouzil | #55021 |
51 | ✅ [whitespace/comments] |
2 | @gouzil | #55021 |
52 | ✅ [whitespace/blank_line] |
2 | @gouzil | #55021 |
53 | ✅ [runtime/init] |
1 | @gouzil | #55021 |
54 | ✅ [runtime/casting] |
1 | @gouzil | #55021 |
55 | ✅ [build/storage_class] |
1 | @gouzil | #55021 |
本表单由 @GreatV 统计~
Note
- 可参考 [CodeStyle][CINN] fix cinn cpplint codestyle #55006,先注释掉
.pre-commit-hooks.yaml
中的 cpplint exclude,之后运行pre-commit run cpplint-cpp-source --all-files | grep "runtime/int"
来查找自己认领的错误码 [readability/todo]
这类可以考虑在原 repo https://github.com/PaddlePaddle/CINN 找到原作者,并在 TODO 后填写 GitHub id- 框架内其他地方仍遗留一些 cpplint 问题,本任务不涉及非 CINN 部分,当然如果有能力可以一起修改
1,2, 3 |
5 6 |
11 |
This was referenced Jun 28, 2023
统计信息已更新至表单~ Cpplint 代码风格修复Cpplint 代码风格修复
|
统计信息已更新至表单~ CMake Lint 代码风格修复
|
This was referenced Jun 28, 2023
This was referenced Jun 29, 2023
Closed
21-26 |
27-29 |
统计信息已更新至表单~ Update: Cpplint 代码风格修复
|
42, 43 |
45 46 47 48 |
36, 37 |
49 |
39, 41, 44 |
认领 30,31,32 |
This was referenced Jun 29, 2023
This was referenced Jun 30, 2023
This was referenced Jul 3, 2023
github-project-automation
bot
moved this from In Progress
to Done
in Call for Contributions
Jul 11, 2023
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
背景
目前 CINN 已于 #54749 合入 Paddle 主框架,但 CINN 原 repo 的代码风格与 Paddle 不一致,缺少很多用于检查代码风格的工具,因此第一个 PR 只能强行豁免合入,但代码风格的问题应当尽快解决,否则会一直阻塞流水线。
#54749 有三条流水线暴露了代码风格相关问题:
PR-CI-APPROVAL log: PR-CI-APPROVAL.log
主要问题:CINN 侧未检查使用
self.assertTrue
,而 Paddle 侧建议使用np.testing.assert_allclose
来进行替代,详情见 框架易用性提升——单测报错信息优化PR-CI-Codestyle-Check log: PR-CI-Codestyle-Chceck.log
end-of-file-fixer
,直接修复即可trailing-whitespace
,直接修复即可black
,一个 PR 全量格式化即可isort
,一个 PR 全量格式化即可flake8
,拆分任务ruff
,拆分任务pylint
,无效 Linter,可忽略clang-format
,一个 PR 全量格式化即可cpplint
,拆分任务cmake-format
,一个 PR 全量格式化即可cmake-lint
,拆分任务PR-CI-Static-Check log: PR-CI-Static-Check.log
std::cout
和print
,也许需要和 LOG 改进专项结合(本任务不涉及)推进方式
第一阶段,解决全量 Formatter 类问题,配置中 exclude 掉全量 CINN 的 Linter 类问题,保证 CodeStyle 流水线不失败,不阻塞在 Paddle 中进行 CINN 的开发(7.10 之前)
Formatter
end-of-file-fixer
trailing-whitespace
black
,可参考 python 代码检查工具 yapf 升级 black 方案、[CodeStyle][black] use black instead of yapf #46014、bump black to 2023 style #54523isort
,可参考 Python 引入 import 区域自动重排工具 isort 方案、[CodeStyle][isort] introducingisort
(part1) #46475,注意 isort 排序后可能对代码语义进行修改,需要确保不会影响代码逻辑clang-format
cmake-format
相关 hook 可直接运行
pre-commit run <hook_name> --all-files
来格式化Linter
flake8
配置中 exclude 掉 CINN 相关目录ruff
配置中 exclude 掉 CINN 相关目录可参考 bump ruff to 0.0.272 and update config #54449
第二阶段,推进解决 Linter 类问题,逐步解决遗留 Linter 类问题
flake8
,可参考 代码风格检查工具 Flake8 引入计划、[CodeStyle] Flake8 tracking issue #46039ruff
,可参考 Python 端引入 ruff 作为代码风格检查/自动修复工具、Introducing Ruff tracking issue #51729np.assertTrue
替换,可参考 框架易用性提升——单测报错信息优化、框架易用性提升——单测报错信息优化 call for contribution(含相关 PR)cpplint
cmake-lint
The text was updated successfully, but these errors were encountered: