.pre-commit-config.yaml 5.5 KB
Newer Older
“yuguo”'s avatar
2.5  
“yuguo” committed
1
2
3
4
5
6
7
8
9
# Exclude all third-party libraries and auto-generated files globally
exclude: |
    (?x)^(
        patches/.+|
        paddle/fluid/framework/fleet/heter_ps/cudf/.+|
        paddle/fluid/distributed/ps/thirdparty/round_robin.h|
        python/paddle/utils/gast/.+|
        third_party/.+
    )$
yuguo960516yuguo's avatar
yuguo960516yuguo committed
10
repos:
“yuguo”'s avatar
2.5  
“yuguo” committed
11
# Common hooks
yuguo960516yuguo's avatar
yuguo960516yuguo committed
12
-   repo: https://github.com/pre-commit/pre-commit-hooks
“yuguo”'s avatar
2.5  
“yuguo” committed
13
    rev: v4.4.0
yuguo960516yuguo's avatar
yuguo960516yuguo committed
14
15
16
17
18
19
20
    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
“yuguo”'s avatar
2.5  
“yuguo” committed
21
22
23
24
25
        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)$
-   repo: https://github.com/Lucas-C/pre-commit-hooks.git
    rev: v1.5.1
yuguo960516yuguo's avatar
yuguo960516yuguo committed
26
    hooks:
“yuguo”'s avatar
2.5  
“yuguo” committed
27
28
29
    -   id: remove-crlf
    -   id: remove-tabs
        name: Tabs remover (C++)
yuguo960516yuguo's avatar
yuguo960516yuguo committed
30
        files: \.(c|cc|cxx|cpp|cu|h|hpp|hxx|xpu|kps)$
“yuguo”'s avatar
2.5  
“yuguo” committed
31
32
33
34
35
36
        args: [--whitespaces-count, '2']
    -   id: remove-tabs
        name: Tabs remover (Python)
        files: (.*\.(py|bzl)|BUILD|.*\.BUILD|WORKSPACE)$
        args: [--whitespaces-count, '4']
        # Exclude some unit test files that require tabs.
yuguo960516yuguo's avatar
yuguo960516yuguo committed
37
38
        exclude: |
            (?x)^(
“yuguo”'s avatar
2.5  
“yuguo” committed
39
                test/dygraph_to_static/test_error.py
yuguo960516yuguo's avatar
yuguo960516yuguo committed
40
41
42
            )$
-   repo: local
    hooks:
“yuguo”'s avatar
2.5  
“yuguo” committed
43
44
45
    -   id: copyright_checker
        name: copyright_checker
        entry: python ./tools/codestyle/copyright.hook
yuguo960516yuguo's avatar
yuguo960516yuguo committed
46
        language: system
“yuguo”'s avatar
2.5  
“yuguo” committed
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
        files: \.(c|cc|cxx|cpp|cu|h|hpp|hxx|proto|xpu|kps|py|sh)$
        exclude: |
            (?x)^(
                paddle/utils/.*|
                paddle/cinn/utils/registry.h
            )$
# For Python files
-   repo: https://github.com/psf/black.git
    rev: 23.3.0
    hooks:
    -   id: black
        files: (.*\.(py|pyi|bzl)|BUILD|.*\.BUILD|WORKSPACE)$
-   repo: https://github.com/PyCQA/flake8
    rev: 5.0.4
    hooks:
    -   id: flake8
        args: ["--config=.flake8"]
-   repo: https://github.com/astral-sh/ruff-pre-commit
yuguo-Jack's avatar
yuguo-Jack committed
65
    rev: v0.1.5
“yuguo”'s avatar
2.5  
“yuguo” committed
66
67
68
69
    hooks:
    -   id: ruff
        args: [--fix, --exit-non-zero-on-fix, --no-cache]
# For C++ files
yuguo960516yuguo's avatar
yuguo960516yuguo committed
70
71
-   repo: local
    hooks:
“yuguo”'s avatar
2.5  
“yuguo” committed
72
73
74
75
    -   id: clang-format
        name: clang-format
        description: Format files with ClangFormat.
        entry: bash ./tools/codestyle/clang_format.hook -i
yuguo960516yuguo's avatar
yuguo960516yuguo committed
76
        language: system
“yuguo”'s avatar
2.5  
“yuguo” committed
77
78
79
80
81
82
83
84
        files: \.(c|cc|cxx|cpp|cu|h|hpp|hxx|xpu|kps)$
-   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
yuguo-Jack's avatar
yuguo-Jack committed
85
        files: \.(cc|cxx|cpp|cu|h|hpp|hxx)$
“yuguo”'s avatar
2.5  
“yuguo” committed
86
        args:
yuguo-Jack's avatar
yuguo-Jack committed
87
            - --extensions=cc,cxx,cpp,cu,cuh,h,hpp,hxx,kps
“yuguo”'s avatar
2.5  
“yuguo” committed
88
89
90
91
            - --filter=-readability/fn_size,-build/include_what_you_use,-build/c++11,-whitespace/parens
            - --quiet
        # Exclude third-party libraries
        exclude:  |
yuguo960516yuguo's avatar
yuguo960516yuguo committed
92
            (?x)^(
“yuguo”'s avatar
2.5  
“yuguo” committed
93
                paddle/utils/flat_hash_map\.h
yuguo960516yuguo's avatar
yuguo960516yuguo committed
94
            )$
“yuguo”'s avatar
2.5  
“yuguo” committed
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
-   repo: local
    hooks:
    -   id: clang-tidy
        name: clang-tidy
        description: Parallel clang-tidy runner.
        entry: python ./tools/codestyle/clang-tidy.py
        language: system
        files: \.(c|cc|cxx|cpp|h|hpp|hxx)$
        args:
            - -p=build/
            - -extra-arg=-Wno-unknown-warning-option
            - -extra-arg=-Wno-pessimizing-move
            - -extra-arg=-Wno-braced-scalar-init
            - -extra-arg=-Wno-dangling-gsl
            - -extra-arg=-Wno-deprecated-copy
            - -extra-arg=-Wno-final-dtor-non-final-class
            - -extra-arg=-Wno-implicit-int-float-conversion
            - -extra-arg=-Wno-inconsistent-missing-override
            - -extra-arg=-Wno-infinite-recursion
            - -extra-arg=-Wno-mismatched-tags
            - -extra-arg=-Wno-self-assign
            - -extra-arg=-Wno-sign-compare
            - -extra-arg=-Wno-sometimes-uninitialized
            - -extra-arg=-Wno-tautological-overlap-compare
            - -extra-arg=-Wno-unused-const-variable
            - -extra-arg=-Wno-unused-lambda-capture
            - -extra-arg=-Wno-unused-private-field
            - -extra-arg=-Wno-unused-value
            - -extra-arg=-Wno-unused-variable
            - -extra-arg=-Wno-overloaded-virtual
            - -extra-arg=-Wno-defaulted-function-deleted
            - -extra-arg=-Wno-delete-non-abstract-non-virtual-dtor
            - -extra-arg=-Wno-return-type-c-linkage
# For CMake files
yuguo960516yuguo's avatar
yuguo960516yuguo committed
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
-   repo: local
    hooks:
    -   id: auto-generate-cmakelists
        name: auto-generate-cmakelists
        entry: bash ./tools/gen_ut_cmakelists.hook
        language: system
        files: testslist.csv$
-   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
            )$
yuguo-Jack's avatar
yuguo-Jack committed
146
147
-   repo: https://github.com/PFCCLab/cmake-lint-paddle
    rev: v1.5.1
yuguo960516yuguo's avatar
yuguo960516yuguo committed
148
149
150
    hooks:
    -   id: cmakelint
        args: [--config=./tools/codestyle/.cmakelintrc]
yuguo-Jack's avatar
yuguo-Jack committed
151
152
153
154
155
156
157
158
159
160
# Others
-   repo: local
    hooks:
    -   id: sort-txt-file
        name: sort-txt-file
        description: Sorts each line string in a text file
        entry: python ./tools/codestyle/sort_txt_file.py
        language: python
        files: test/white_list/pir_op_test_white_list
        args: []