-
Notifications
You must be signed in to change notification settings - Fork 27
/
.pre-commit-config.yaml
161 lines (148 loc) · 5.3 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
default_install_hook_types: [ pre-commit, pre-push ]
default_language_version:
python: python3.11
repos:
# Update Poetry to the latest version.
- repo: local
hooks:
- id: poetry-self-update
name: Update Poetry to the latest version
entry: poetry self update
language: system
types: [ python ]
pass_filenames: false
always_run: true
# Check if Poetry is configured correctly, and if the lock file is up to date, and if the requirements.txt file is up to date.
- repo: https://github.com/python-poetry/poetry
rev: "1.5.0"
hooks:
- id: poetry-check
name: Check if Poetry is configured correctly by running `poetry check`
- id: poetry-lock
name: Check if the poetry.lock file is up to date
- id: poetry-export
name: Check if the requirements.txt file is up to date
args:
[
"-f",
"requirements.txt",
"-o",
"requirements.txt",
]
- repo: https://github.com/tox-dev/pyproject-fmt
rev: "0.13.0"
hooks:
- id: pyproject-fmt
name: Format pyproject.toml with pyproject-fmt
# Add a trailing comma to Python stuff.
- repo: https://github.com/asottile/add-trailing-comma
rev: v3.0.0
hooks:
- id: add-trailing-comma
args: [ --py36-plus ]
- repo: https://github.com/pre-commit/pre-commit-hooks
rev: v4.4.0
hooks:
- id: check-added-large-files
name: Prevent adding large files to the repository (500 Kb)
- id: check-ast
name: Check for syntax errors
- id: check-builtin-literals
name: Require literal syntax when initializing empty or zero Python builtin types.
- id: check-case-conflict
name: Check for files that would conflict in case-insensitive filesystems.
- id: check-docstring-first
name: Check that the docstring is the first statement in a module, function, class, or method definition.
- id: check-executables-have-shebangs
name: Check that executables have shebangs.
- id: check-json
name: Check JSON files for syntax errors.
- id: check-merge-conflict
name: Check for files that contain merge conflict strings.
- id: check-symlinks
name: Check for broken symlinks.
- id: check-toml
name: Check TOML files for syntax errors.
- id: check-vcs-permalinks
name: Check for VCS permalinks.
- id: check-xml
name: Check XML files for syntax errors.
- id: check-yaml
name: Check YAML files for syntax errors.
- id: debug-statements
name: Check for debugger imports and py37+ `breakpoint()` calls in Python code.
- id: destroyed-symlinks
name: Check for destroyed symlinks.
- id: detect-private-key
name: Check for private keys.
- id: end-of-file-fixer
name: Ensure that a file is either empty, or ends with one newline.
- id: fix-byte-order-marker
name: Remove the byte-order marker (BOM) from files.
- id: fix-encoding-pragma
name: Remove the encoding pragma from Python files.
args: [ --remove ]
- id: mixed-line-ending
name: Check for files with mixed line endings and replace them with the most common line ending.
- id: name-tests-test
name: Check that test functions are named test_*.
args: [ --pytest-test-first ]
- id: trailing-whitespace
name: Check for trailing whitespace.
args: [ --markdown-linebreak-ext=md ]
exclude_types:
- "html"
# Not used:
# - id: detect-aws-credentials
# - id: double-quote-string-fixer
# - id: file-contents-sorter
# - id: forbid-new-submodules
# - id: forbid-submodules
# - id: no-commit-to-branch
# - id: pretty-format-json
# - id: requirements-txt-fixer
# Run Ruff on all Python files. We do this before Black so that Black can
# format the code that Ruff changes.
- repo: https://github.com/charliermarsh/ruff-pre-commit
rev: "v0.0.280"
hooks:
- id: ruff
name: Lint Python code with Ruff
args: [ "--fix", "--exit-non-zero-on-fix" ]
# Run Black on all Python files. This will format the code.
- repo: https://github.com/psf/black
rev: 23.7.0
hooks:
- id: black
name: Format Python code with Black
# Sort Python imports using isort.
- repo: https://github.com/pycqa/isort
rev: 5.12.0
hooks:
- id: isort
name: Sort Python imports with isort
args: [ "--profile", "black", "--filter-files" ]
# Run Pyupgrade on all Python files. This will upgrade the code to Python 3.11.
- repo: https://github.com/asottile/pyupgrade
rev: v3.9.0
hooks:
- id: pyupgrade
name: Upgrade Python syntax to Python 3.11 with pyupgrade
args: [ "--py311-plus" ]
# Run Flake8 on all Python files.
- repo: https://github.com/pycqa/flake8
rev: 6.0.0
hooks:
- id: flake8
name: Lint Python code with Flake8
args: [ "--max-line-length", "120" ]
# Run Pytest before committing.
- repo: local
hooks:
- id: tests
name: Test Python code with Pytest
entry: poetry run pytest
language: system
types: [ python ]
pass_filenames: false
always_run: true