.pre-commit-config.yaml 4.02 KB
Newer Older
1
2
3
4
5
6
7
8
9
10
11
12
13
14
# To use:
#
#     pre-commit run -a
#
# Or:
#
#     pre-commit install  # (runs every time you commit in git)
#
# To update this file:
#
#     pre-commit autoupdate
#
# See https://github.com/pre-commit/pre-commit

15
repos:
16
# Standard hooks
17
- repo: https://github.com/pre-commit/pre-commit-hooks
18
  rev: "v4.1.0"
19
20
21
  hooks:
  - id: check-added-large-files
  - id: check-case-conflict
22
  - id: check-docstring-first
23
24
  - id: check-merge-conflict
  - id: check-symlinks
25
  - id: check-toml
26
27
28
29
30
31
32
  - id: check-yaml
  - id: debug-statements
  - id: end-of-file-fixer
  - id: mixed-line-ending
  - id: requirements-txt-fixer
  - id: trailing-whitespace

33
# Upgrade old Python syntax
34
- repo: https://github.com/asottile/pyupgrade
35
  rev: "v2.31.1"
36
37
  hooks:
  - id: pyupgrade
38
    args: [--py36-plus]
39

40
# Nicely sort includes
41
- repo: https://github.com/PyCQA/isort
42
  rev: "5.10.1"
43
44
45
  hooks:
  - id: isort

46
47
# Black, the code formatter, natively supports pre-commit
- repo: https://github.com/psf/black
Henry Schreiner's avatar
Henry Schreiner committed
48
  rev: "22.3.0" # Keep in sync with blacken-docs
49
50
  hooks:
  - id: black
51

52
# Also code format the docs
53
- repo: https://github.com/asottile/blacken-docs
54
  rev: "v1.12.1"
55
56
57
  hooks:
  - id: blacken-docs
    additional_dependencies:
Henry Schreiner's avatar
Henry Schreiner committed
58
    - black==22.3.0 # keep in sync with black hook
59
60

# Changes tabs to spaces
61
- repo: https://github.com/Lucas-C/pre-commit-hooks
62
  rev: "v1.1.13"
63
64
65
  hooks:
  - id: remove-tabs

66
- repo: https://github.com/sirosen/texthooks
67
  rev: "0.3.1"
68
69
70
71
  hooks:
  - id: fix-ligatures
  - id: fix-smartquotes

72
73
# Autoremoves unused imports
- repo: https://github.com/hadialqattan/pycln
74
  rev: "v1.2.5"
75
76
  hooks:
  - id: pycln
Henry Schreiner's avatar
Henry Schreiner committed
77
78
    additional_dependencies: [click<8.1]  # Unpin when typer updates
    stages: [manual]
79

80
# Checking for common mistakes
81
- repo: https://github.com/pre-commit/pygrep-hooks
82
  rev: "v1.9.0"
83
84
85
86
  hooks:
  - id: python-check-blanket-noqa
  - id: python-check-blanket-type-ignore
  - id: python-no-log-warn
87
  - id: python-use-type-annotations
88
89
90
91
  - id: rst-backticks
  - id: rst-directive-colons
  - id: rst-inline-touching-normal

Henry Schreiner's avatar
Henry Schreiner committed
92
93
94
95
96
97
98
99
100
# Automatically remove noqa that are not used
- repo: https://github.com/asottile/yesqa
  rev: "v1.3.0"
  hooks:
  - id: yesqa
    additional_dependencies: &flake8_dependencies
      - flake8-bugbear
      - pep8-naming

101
# Flake8 also supports pre-commit natively (same author)
102
- repo: https://github.com/PyCQA/flake8
103
  rev: "4.0.1"
104
105
106
  hooks:
  - id: flake8
    exclude: ^(docs/.*|tools/.*)$
Henry Schreiner's avatar
Henry Schreiner committed
107
    additional_dependencies: *flake8_dependencies
108

Henry Schreiner's avatar
Henry Schreiner committed
109
110
# PyLint has native support - not always usable, but works for us
- repo: https://github.com/PyCQA/pylint
Henry Schreiner's avatar
Henry Schreiner committed
111
  rev: "v2.13.2"
112
  hooks:
Henry Schreiner's avatar
Henry Schreiner committed
113
114
  - id: pylint
    files: ^pybind11
115

116
# CMake formatting
117
- repo: https://github.com/cheshirekow/cmake-format-precommit
118
  rev: "v0.6.13"
119
120
121
  hooks:
  - id: cmake-format
    additional_dependencies: [pyyaml]
Henry Schreiner's avatar
Henry Schreiner committed
122
123
    types: [file]
    files: (\.cmake|CMakeLists.txt)(.in)?$
124

125
126
# Check static types with mypy
- repo: https://github.com/pre-commit/mirrors-mypy
Henry Schreiner's avatar
Henry Schreiner committed
127
  rev: "v0.942"
128
129
  hooks:
  - id: mypy
130
131
132
    args: [--show-error-codes]
    exclude: ^(tests|docs)/
    additional_dependencies: [nox, rich]
133

134
135
# Checks the manifest for missing files (native support)
- repo: https://github.com/mgedmin/check-manifest
136
  rev: "0.48"
137
138
139
140
141
142
  hooks:
  - id: check-manifest
    # This is a slow hook, so only run this if --hook-stage manual is passed
    stages: [manual]
    additional_dependencies: [cmake, ninja]

143
# Check for spelling
144
- repo: https://github.com/codespell-project/codespell
145
  rev: "v2.1.0"
146
147
  hooks:
  - id: codespell
148
149
    exclude: ".supp$"
    args: ["-L", "nd,ot,thist"]
150

151
# Check for common shell mistakes
152
- repo: https://github.com/shellcheck-py/shellcheck-py
153
  rev: "v0.8.0.4"
154
155
  hooks:
  - id: shellcheck
156

157
# Disallow some common capitalization mistakes
158
159
160
161
162
- repo: local
  hooks:
  - id: disallow-caps
    name: Disallow improper capitalization
    language: pygrep
163
    entry: PyBind|Numpy|Cmake|CCache|PyTest
164
    exclude: ^\.pre-commit-config.yaml$
165

166
# Clang format the codebase automatically
167
- repo: https://github.com/pre-commit/mirrors-clang-format
168
  rev: "v13.0.1"
169
  hooks:
170
  - id: clang-format
171
    types_or: [c++, c, cuda]