.pre-commit-config.yaml 4.1 KB
Newer Older
1
# Exclude all third-party libraries and auto-generated files globally
2 3
exclude: |
    (?x)^(
4 5
        patches/.+|
        paddle/fluid/framework/fleet/heter_ps/cudf/.+|
6
        paddle/fluid/distributed/ps/thirdparty/round_robin.h|
7 8
        python/paddle/utils/gast/.+|
        third_party/.+
9
    )$
Y
Yi Wang 已提交
10
repos:
11 12
# Common hooks
-   repo: https://github.com/pre-commit/pre-commit-hooks
13
    rev: v4.4.0
14 15 16 17 18 19 20 21 22 23
    hooks:
    -   id: check-added-large-files
    -   id: check-merge-conflict
    -   id: check-symlinks
    -   id: detect-private-key
    -   id: end-of-file-fixer
    -   id: sort-simple-yaml
        files: (ops|backward|op_[a-z_]+)\.yaml$
    -   id: trailing-whitespace
        files: (.*\.(py|bzl|md|rst|c|cc|cxx|cpp|cu|h|hpp|hxx|xpu|kps|cmake|yaml|yml|hook)|BUILD|.*\.BUILD|WORKSPACE|CMakeLists\.txt)$
Y
Yu Yang 已提交
24
-   repo: https://github.com/Lucas-C/pre-commit-hooks.git
25
    rev: v1.5.1
Y
Yu Yang 已提交
26 27
    hooks:
    -   id: remove-crlf
28
    -   id: remove-tabs
29
        name: Tabs remover (C++)
30 31
        files: \.(c|cc|cxx|cpp|cu|h|hpp|hxx|xpu|kps)$
        args: [--whitespaces-count, '2']
32
    -   id: remove-tabs
33
        name: Tabs remover (Python)
34 35
        files: (.*\.(py|bzl)|BUILD|.*\.BUILD|WORKSPACE)$
        args: [--whitespaces-count, '4']
36
        # Exclude some unit test files that require tabs.
37 38
        exclude: |
            (?x)^(
39
                test/dygraph_to_static/test_error.py
40
            )$
41 42 43 44 45 46 47 48 49
-   repo: local
    hooks:
    -   id: copyright_checker
        name: copyright_checker
        entry: python ./tools/codestyle/copyright.hook
        language: system
        files: \.(c|cc|cxx|cpp|cu|h|hpp|hxx|proto|xpu|kps|py|sh)$
        exclude: |
            (?x)^(
50 51
                paddle/utils/.*|
                paddle/cinn/utils/registry.h
52 53
            )$
# For Python files
54
-   repo: https://github.com/psf/black.git
55
    rev: 23.3.0
Y
Yu Yang 已提交
56
    hooks:
57 58
    -   id: black
        files: (.*\.(py|pyi|bzl)|BUILD|.*\.BUILD|WORKSPACE)$
59
-   repo: https://github.com/pycqa/isort
MarDino's avatar
MarDino 已提交
60
    rev: 5.11.5
61 62
    hooks:
    -   id: isort
63
-   repo: https://github.com/PyCQA/flake8
64
    rev: 5.0.4
65 66
    hooks:
    -   id: flake8
67
        args: ["--config=.flake8"]
68 69
-   repo: https://github.com/astral-sh/ruff-pre-commit
    rev: v0.0.272
70 71 72
    hooks:
    -   id: ruff
        args: [--fix, --exit-non-zero-on-fix, --no-cache]
73 74 75 76 77 78 79 80 81
-   repo: local
    hooks:
    -   id: pylint-doc-string
        name: pylint
        description: Check python docstring style using docstring_checker.
        entry: bash ./tools/codestyle/pylint_pre_commit.hook
        language: system
        files: \.(py)$
# For C++ files
L
test  
liaogang 已提交
82
-   repo: local
Y
Yu Yang 已提交
83
    hooks:
84
    -   id: clang-format
L
test  
liaogang 已提交
85 86
        name: clang-format
        description: Format files with ClangFormat.
87
        entry: bash ./tools/codestyle/clang_format.hook -i
L
test  
liaogang 已提交
88
        language: system
89
        files: \.(c|cc|cxx|cpp|cu|h|hpp|hxx|xpu|kps)$
Y
Yi Wang 已提交
90 91 92 93 94 95 96 97
-   repo: local
    hooks:
    -   id: cpplint-cpp-source
        name: cpplint
        description: Check C++ code style using cpplint.py.
        entry: bash ./tools/codestyle/cpplint_pre_commit.hook
        language: system
        files: \.(c|cc|cxx|cpp|cu|h|hpp|hxx)$
98 99 100 101
        args:
            - --extensions=c,cc,cxx,cpp,cu,cuh,h,hpp,hxx,kps
            - --filter=-readability/fn_size,-build/include_what_you_use,-build/c++11,-whitespace/parens
            - --quiet
102
        # Exclude third-party libraries
103 104
        exclude:  |
            (?x)^(
105
                paddle/utils/flat_hash_map\.h
106
            )$
107
# For CMake files
R
Roc 已提交
108 109 110 111 112 113 114
-   repo: local
    hooks:
    -   id: auto-generate-cmakelists
        name: auto-generate-cmakelists
        entry: bash ./tools/gen_ut_cmakelists.hook
        language: system
        files: testslist.csv$
115 116 117 118 119 120 121 122 123 124
-   repo: https://github.com/cheshirekow/cmake-format-precommit
    rev: v0.6.13
    hooks:
    -   id: cmake-format
        # exclude paddle/fluid/operators/CMakeLists.txt, see the comment
        # https://github.com/PaddlePaddle/Paddle/pull/43057#pullrequestreview-993471860
        exclude: |
            (?x)^(
                paddle/fluid/operators/CMakeLists.txt
            )$
125 126 127 128 129
-   repo: https://github.com/cmake-lint/cmake-lint
    rev: 1.4.2
    hooks:
    -   id: cmakelint
        args: [--config=./tools/codestyle/.cmakelintrc]