diff --git a/.pre-commit-config.yaml b/.pre-commit-config.yaml index f7639a1370aa6d049f30b5b022375c4e4eff0bae..1245f1b4cb1d8e4dedc2a1aceabed6c65d8f26d5 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 d42ee7ab0ec5408bd2c8a0014dd388f9f68fb657..cf4afca27c328033302569d9ccb35373f218016d 100644 --- a/pyproject.toml +++ b/pyproject.toml @@ -17,3 +17,45 @@ 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 = [ + # Pyupgrade + "UP001", + "UP003", + "UP007", + "UP011", + "UP013", + "UP014", + "UP017", + "UP019", + "UP020", + "UP021", + "UP022", + "UP023", + "UP025", + "UP026", + "UP029", + "UP033", + "UP035", + "UP036", + + # NumPy-specific rules + "NPY001", +] +unfixable = [ + "NPY001" +] + +[tool.ruff.per-file-ignores] +"__init__.py" = ["F401"] +"setup.py" = ["UP036"] diff --git a/python/paddle/fluid/tests/unittests/ir/inference/test_trt_convert_elementwise.py b/python/paddle/fluid/tests/unittests/ir/inference/test_trt_convert_elementwise.py index ff7cc6e2dd1a214f543e9ca637fa8c4065f42a99..417591c453694912c5134f45193700658338719f 100644 --- a/python/paddle/fluid/tests/unittests/ir/inference/test_trt_convert_elementwise.py +++ b/python/paddle/fluid/tests/unittests/ir/inference/test_trt_convert_elementwise.py @@ -953,7 +953,7 @@ class TrtConvertElementwiseTestTwoInputSkipCase(TrtLayerAutoScanTest): ) # Paddle mul support bool and TensorRT not if op_type == "elementwise_mul": - return np.random.random(shape).astype(np.bool) + return np.random.random(shape).astype(np.bool_) for shape in [[4], [4, 32], [2, 32, 16], [1, 8, 16, 32]]: for op_type in [ diff --git a/python/paddle/fluid/tests/unittests/op_test.py b/python/paddle/fluid/tests/unittests/op_test.py index 4d728eb98d652f1d870ebd3f8458f0080041016f..74e35abe5d29cc999fb241685d752afb9db47c48 100644 --- a/python/paddle/fluid/tests/unittests/op_test.py +++ b/python/paddle/fluid/tests/unittests/op_test.py @@ -2185,7 +2185,7 @@ class OpTest(unittest.TestCase): else: abs_a = 1 if abs_a < 1e-3 else abs_a - if self.dtype == np.bool: + if self.dtype == np.bool_: diff_mat = np.abs(a ^ b) / abs_a else: diff_mat = np.abs(a - b) / abs_a