From af6fed952111548c5d771bc75fbad6a02e80b948 Mon Sep 17 00:00:00 2001 From: SigureMo Date: Sun, 5 Mar 2023 01:24:46 +0800 Subject: [PATCH 1/5] [CodeStyle] initial ruff config --- .pre-commit-config.yaml | 5 +++++ pyproject.toml | 34 ++++++++++++++++++++++++++++++++++ 2 files changed, 39 insertions(+) diff --git a/.pre-commit-config.yaml b/.pre-commit-config.yaml index f7639a1370aa6d..1245f1b4cb1d8e 100644 --- a/.pre-commit-config.yaml +++ b/.pre-commit-config.yaml @@ -78,6 +78,11 @@ repos: - --ignore-pass-after-docstring - --ignore-init-module-imports - --exclude=python/paddle/fluid/[!t]**,python/paddle/fluid/tra** +- repo: https://github.com/charliermarsh/ruff-pre-commit + rev: v0.0.254 + hooks: + - id: ruff + args: [--fix, --exit-non-zero-on-fix, --no-cache] - repo: local hooks: - id: pylint-doc-string diff --git a/pyproject.toml b/pyproject.toml index d42ee7ab0ec540..67fbd65d117f42 100644 --- a/pyproject.toml +++ b/pyproject.toml @@ -17,3 +17,37 @@ extend_skip_glob = [ "python/paddle/fluid/tests/unittests/npu/**", "python/paddle/fluid/tests/unittests/mlu/**", ] + +[tool.ruff] +exclude = [ + "./build", + "./python/paddle/fluid/[!t]**", + "./python/paddle/fluid/tra**", + "./python/paddle/utils/gast/**", + "./python/paddle/fluid/tests/unittests/npu/**", + "./python/paddle/fluid/tests/unittests/mlu/**", +] +target-version = "py37" +select = [ + "UP001", + "UP003", + "UP007", + "UP011", + "UP013", + "UP014", + "UP017", + "UP019", + "UP020", + "UP021", + "UP022", + "UP023", + "UP025", + "UP026", + "UP029", + "UP033", + "UP035", + "UP036", +] + +[tool.ruff.per-file-ignores] +"setup.py" = ["UP036"] From 0fc2209ac80b5a5e9589b6dd396faf3980294c39 Mon Sep 17 00:00:00 2001 From: SigureMo Date: Sun, 5 Mar 2023 01:42:34 +0800 Subject: [PATCH 2/5] update F401 config --- pyproject.toml | 1 + 1 file changed, 1 insertion(+) diff --git a/pyproject.toml b/pyproject.toml index 67fbd65d117f42..fc0b68bc2f05e4 100644 --- a/pyproject.toml +++ b/pyproject.toml @@ -50,4 +50,5 @@ select = [ ] [tool.ruff.per-file-ignores] +"__init__.py" = ["F401"] "setup.py" = ["UP036"] From 01afc10d6c7961027f7219d2039eed46a706ed00 Mon Sep 17 00:00:00 2001 From: SigureMo Date: Sun, 12 Mar 2023 16:36:54 +0800 Subject: [PATCH 3/5] [CodeStyle][F401] replace autoflake with ruff --- .pre-commit-config.yaml | 10 ---------- pyproject.toml | 4 ++++ 2 files changed, 4 insertions(+), 10 deletions(-) diff --git a/.pre-commit-config.yaml b/.pre-commit-config.yaml index 1245f1b4cb1d8e..ccf1db464d344d 100644 --- a/.pre-commit-config.yaml +++ b/.pre-commit-config.yaml @@ -68,16 +68,6 @@ repos: hooks: - id: flake8 args: ["--config=.flake8"] -- repo: https://github.com/PyCQA/autoflake - rev: v1.7.7 - hooks: - - id: autoflake - args: - - --in-place - - --remove-all-unused-imports - - --ignore-pass-after-docstring - - --ignore-init-module-imports - - --exclude=python/paddle/fluid/[!t]**,python/paddle/fluid/tra** - repo: https://github.com/charliermarsh/ruff-pre-commit rev: v0.0.254 hooks: diff --git a/pyproject.toml b/pyproject.toml index fc0b68bc2f05e4..da5091431897dc 100644 --- a/pyproject.toml +++ b/pyproject.toml @@ -29,6 +29,10 @@ exclude = [ ] target-version = "py37" select = [ + # Pyflakes + "F401", + + # Pyupgrade "UP001", "UP003", "UP007", From afed941004b9d2a38306e04f98fbec569fe5d9d0 Mon Sep 17 00:00:00 2001 From: SigureMo Date: Thu, 16 Mar 2023 12:52:57 +0800 Subject: [PATCH 4/5] empty commit; test=document_fix From 50bbf3d1b9afc2fa33fed9486ca206458e4d73d4 Mon Sep 17 00:00:00 2001 From: SigureMo Date: Thu, 16 Mar 2023 12:54:08 +0800 Subject: [PATCH 5/5] restore unfixable; test=document_fix --- pyproject.toml | 3 +++ 1 file changed, 3 insertions(+) diff --git a/pyproject.toml b/pyproject.toml index ffd71b0c072bca..f244f6c1d45e4d 100644 --- a/pyproject.toml +++ b/pyproject.toml @@ -55,6 +55,9 @@ select = [ # NumPy-specific rules "NPY001", ] +unfixable = [ + "NPY001" +] [tool.ruff.per-file-ignores] "__init__.py" = ["F401"]