-
Notifications
You must be signed in to change notification settings - Fork 11
/
.pre-commit-config.yaml
216 lines (192 loc) · 7.42 KB
/
.pre-commit-config.yaml
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
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
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
#
# This is the configuration file of the pre-commit framework for this repository:
# https://pypi.org/project/pre-commit
#
# pre-commit runs in the GitHub Workflow of this project on each push and PR.
# Additionally, you can run it locally for faster fixing of issues using
# $ pip3 install pre-commit -r requirements-dev.txt
#
# On the initial run, pre-commit downloads its checkers, subsequent runs are fast:
#
# $ pre-commit run # automatically checks which checks are needed.
# $ pre-commit run -a # runs all fixes and checks, even when not needed
#
# When this works, you can enable it as the pre-commit hook for this git clone:
# $ pre-commit install
# $ pre-commit install --hook-type pre-push
#
# You can skip checks if you commit very often you don't want them to run, e.g:
# export SKIP=mypy,pylint;git commit -m "quick save" (or for --amend)
#
# For more customizations, see https://pre-commit.com/#temporarily-disabling-hooks
# and https://pre-commit.com/#confining-hooks-to-run-at-certain-stages (e.g push)
#
# After this, the pre-commit fixes and checks run when you commit an update.
#
# You can also automatically set pre-commit as pre-commit hook for new git clones:
# $ git config --global init.templateDir ~/.git-template
# $ pre-commit init-templatedir ~/.git-template
#
# Further information:
# https://pre-commit.com/#automatically-enabling-pre-commit-on-repositories
# All hooks: https://pre-commit.com/hooks.html
fail_fast: false
default_stages: [commit, push]
repos:
- repo: https://github.com/pre-commit/pre-commit-hooks
rev: v4.5.0
# https://github.com/pre-commit/pre-commit-hooks/blob/main/README.md:
hooks:
- id: no-commit-to-branch
name: "ensure that you don't commit to the local master branch"
args: [--branch, master]
always_run: true
- id: trailing-whitespace
name: 'check and fix files to have no trailing whitespace'
- id: end-of-file-fixer
name: 'check and fix that files have a trailing newline'
exclude: tests/integration/dom0-template
- id: mixed-line-ending
args: ['--fix=lf']
name: 'check and fix that line endings are line feeds'
- id: check-added-large-files
args: ['--maxkb=12']
name: 'check that no large files are added'
- id: check-executables-have-shebangs
- id: debug-statements
name: 'check for debugger imports and breakpoint calls'
- id: check-shebang-scripts-are-executable
- id: check-merge-conflict
- id: check-yaml
name: 'check the syntax of yaml files'
# The fast checks are first, to fix them first,
# pytest with code coverage at the end.
- repo: https://github.com/PyCQA/autoflake
rev: v2.2.1
hooks:
- id: autoflake
name: Run autoflake to automatically remove unused variables and imports
args: ["--in-place", "--remove-unused-variables", "--remove-all-unused-imports"]
language: python
files: \.py$
- repo: https://github.com/psf/black
rev: 23.11.0
hooks:
- id: black
name: Ensure that all files (excluding xen-bugtool itself) are black-formatted
args: [--safe, --quiet]
exclude: xen-bugtool
- repo: https://github.com/akaihola/darker
rev: 1.7.2
hooks:
- id: darker
name: Ensure that changes staged for updating xen-bugtool are black-formatted
files: xen-bugtool
# If needed, hooks can be disabled temporarily by removing commit and push:
stages: [commit, push, manual]
entry: make
pass_filenames: false
args: [darker-xen-bugtool]
additional_dependencies:
- isort
- repo: https://github.com/pre-commit/mirrors-mypy
rev: v1.8.0
hooks:
- id: mypy
name: Run mypy to check e.g. that all expected arguments are passed to functions etc
additional_dependencies:
- defusedxml
- pytest
- types-lxml
- types-mock
- types-requests
- repo: https://github.com/pylint-dev/pylint
rev: v3.0.4
hooks:
- id: pylint
additional_dependencies: ['pylint[spelling]', pytest]
args: [--spelling-dict=en_US] # See the comment in .pylintrc
files: '(^xen-bugtool|\.py)$'
# --------------------
# Hint about this hook
# --------------------
#
# If you want to skip this hook (in case the branch shall not be rebased), use:
# export SKIP=check-branch-needs-rebase or (for example):
# SKIP=check-branch-needs-rebase pre-commit run --hook-stage push --all-files -v
# SKIP=check-branch-needs-rebase git commit -s -m "your message"
#
- repo: local
hooks:
- id: check-branch-needs-rebase
name: Check if the current branch needs a rebase
entry: .github/workflows/check_branch-needs-rebase.py
language: python
always_run: true
pass_filenames: false
additional_dependencies: [requests]
- id: git-diff # Ref: https://github.com/pre-commit/pre-commit/issues/1712
name: Show not staged changes (fixups may make them too)
entry: sh -c '.vscode/ltex-sort-dictionary.sh && git diff --exit-code'
language: system
pass_filenames: false
always_run: true
# Run "python3 -m pip install -r requirements-dev.txt" to run pytest or use "git commit --no-verify":
- repo: local
hooks:
- id: pytest
name: check that the Xen-Bugtool Test Environment passes
entry: env PYTHONDEVMODE=yes sh -c
"coverage run && coverage xml && coverage html"
require_serial: true
pass_filenames: false
language: python
types: [python]
additional_dependencies:
- coverage
- defusedxml
- lxml
- mock
- pyfakefs
- pytest-coverage
- pytest-mock
- XenAPI
- id: diff-cover
name: check that that the changed lines are covered by tests
entry: diff-cover --ignore-whitespace --compare-branch=origin/master
--show-uncovered --html-report .git/coverage-diff.html
--fail-under 100 .git/coverage.xml
require_serial: true
pass_filenames: false
language: python
types: [python]
additional_dependencies: [diff-cover]
- id: coverage-report
name: check coverage report for minimum overall coverage
entry: coverage report --fail-under 55 #| tee .git/coverage.txt
require_serial: true
pass_filenames: false
language: python
types: [python]
additional_dependencies: [coverage]
- repo: https://github.com/RobertCraigie/pyright-python
rev: v1.1.351
hooks:
- id: pyright
name: Run pyright to check the unit tests for any typing warnings (use for bugtool later)
exclude: xen-bugtool
additional_dependencies: [defusedxml, pytest, lxml, mock, XenAPI]
- repo: https://github.com/mattseymour/pre-commit-pytype
rev: '2023.5.8'
hooks:
- id: pytype
# Note: Pytype does not support Python 3.12 yet:
# https://google.github.io/pytype/support.html
#
# If your pre-commit has been installed in a Python3.12 environment,
# you need to uncomment the next line to run pytype in a Python3.10 environment:
# that also the GitHub Action currently uses:
# language_version: "3.10"
name: Run pytype to check the unit tests for any typing warnings (does not work on bugtool yet)
exclude: xen-bugtool
additional_dependencies: [pytest]