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] add pre-commit hook remove-tabs for python files #46290

Merged
merged 23 commits into from
Sep 27, 2022
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
22 changes: 15 additions & 7 deletions .flake8
Original file line number Diff line number Diff line change
@@ -1,22 +1,30 @@
[flake8]
select = C,E,F,W
exclude = ./build
exclude =
./build,
# A trick to exclude fluid/ but keep fluid/tests/, see more at
# https://github.com/PaddlePaddle/Paddle/pull/46290#discussion_r976392010
./python/paddle/fluid/[!t]**,
./python/paddle/fluid/tra**
ignore =
# E, see https://pycodestyle.pycqa.org/en/latest/intro.html#error-codes
E101,E121,E122,E123,E124,E125,E126,E127,E128,E129,E131,
E201,E202,E203,E221,E225,E226,E228,E231,E241,E251,E261,E262,E265,E266,E271,E272,E275,
E121,E122,E123,E125,E126,E127,E128,E129,E131,
E201,E202,E203,E225,E226,E228,E231,E241,E251,E261,E262,E265,E266,E271,E272,
E301,E302,E303,E305,E306,
E401,E402,
E501,E502,
E701,E711,E712,E713,E714,E721,E722,E731,E741,

# F, see https://flake8.pycqa.org/en/latest/user/error-codes.html
F401,F402,F403,F404,F405,
Copy link
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

E124 和 F404 是原本不存在的问题,统计出错是因为 #46014 (comment) 统计时候包含了 autopep8 产生的增量,因此这里把这俩也删掉了

此前现存问题应该是 68 个,已在 tracking issue 中更新

Copy link
Member Author

@SigureMo SigureMo Sep 25, 2022

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

根据最新统计,又移除了 E221、E275、F523、F823,部分应该是由于排除掉了 fluid,另外一部分应该是因为 #46410 移除了部分 disable 掉的格式化,重新格式化后部分错误码消失了

之后在 tracking issue 更新

F522,F523,F524,F541,
F401,F402,F403,F405,
F522,F524,F541,
F601,F631,F632,
F811,F821,F823,F841,
F811,F821,F841,

# W, see https://pycodestyle.pycqa.org/en/latest/intro.html#error-codes
W191,
W503,W504
W601,W605
per-file-ignores =
# These files need tabs for testing.
python/paddle/fluid/tests/unittests/dygraph_to_static/test_error.py:E101,W191
python/paddle/fluid/tests/unittests/collective/fleet/test_hdfs1.py:E101,W191
15 changes: 14 additions & 1 deletion .pre-commit-config.yaml
Original file line number Diff line number Diff line change
@@ -1,8 +1,10 @@
# Exclude all third-party libraries globally
exclude: |
(?x)^(
patches/.+|
paddle/fluid/framework/fleet/heter_ps/cudf/.+|
paddle/fluid/distributed/ps/thirdparty/round_robin.h
paddle/fluid/distributed/ps/thirdparty/round_robin.h|
python/paddle/utils/gast/.+
SigureMo marked this conversation as resolved.
Show resolved Hide resolved
)$
repos:
- repo: https://github.com/Lucas-C/pre-commit-hooks.git
Expand All @@ -12,6 +14,17 @@ repos:
- id: remove-tabs
files: \.(c|cc|cxx|cpp|cu|h|hpp|hxx|xpu|kps)$
args: [--whitespaces-count, '2']
- id: remove-tabs
files: (.*\.(py|bzl)|BUILD|.*\.BUILD|WORKSPACE)$
args: [--whitespaces-count, '4']
# Exclude the fluid directory but keep the fluid/tests directory.
# And exclude some unit test files that require tabs.
exclude: |
(?x)^(
python/paddle/fluid/(?!tests).+|
python/paddle/fluid/tests/unittests/collective/fleet/test_hdfs1.py|
python/paddle/fluid/tests/unittests/dygraph_to_static/test_error.py
)$
- repo: https://github.com/google/yapf
rev: v0.32.0
hooks:
Expand Down