-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy path.pre-commit-config.yaml
More file actions
156 lines (142 loc) · 4.04 KB
/
Copy path.pre-commit-config.yaml
File metadata and controls
156 lines (142 loc) · 4.04 KB
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
# Pre-commit hooks for code quality and consistency
# Install: uv run pre-commit install
# Run manually: uv run pre-commit run --all-files
# Update hooks: uv run pre-commit autoupdate
repos:
# General file checks
- repo: https://github.com/pre-commit/pre-commit-hooks
rev: v4.6.0
hooks:
- id: trailing-whitespace
exclude: '^.*\.(md|rst)$'
- id: end-of-file-fixer
exclude: '^.*\.(jpg|png|gif|ico|svg)$'
- id: check-yaml
args: ['--unsafe']
- id: check-json
- id: check-toml
- id: check-added-large-files
args: ['--maxkb=1000']
- id: check-merge-conflict
- id: check-case-conflict
- id: debug-statements
- id: detect-private-key
- id: mixed-line-ending
args: ['--fix=lf']
- id: check-docstring-first
- id: check-executables-have-shebangs
- id: check-shebang-scripts-are-executable
# Python code formatting
- repo: https://github.com/psf/black
rev: 24.8.0
hooks:
- id: black
language_version: python3.12
args: ['--line-length=88']
# Import sorting
- repo: https://github.com/pycqa/isort
rev: 5.13.2
hooks:
- id: isort
args: ['--profile', 'black', '--line-length', '88']
# Python linting
- repo: https://github.com/pycqa/flake8
rev: 7.1.1
hooks:
- id: flake8
args: ['--max-line-length=88', '--extend-ignore=E203,W503,E501']
additional_dependencies:
- flake8-django
- flake8-bugbear
- flake8-comprehensions
- flake8-simplify
exclude: '^(migrations|.*_cache|build|dist)/.*\.py$'
# Security checks
- repo: https://github.com/PyCQA/bandit
rev: 1.7.10
hooks:
- id: bandit
args: ['-ll', '--skip', 'B101,B601,B602,B607']
exclude: '^(tests?/|test_.*\.py$|migrations/)'
# Django specific checks
- repo: https://github.com/adamchainz/django-upgrade
rev: 1.22.1
hooks:
- id: django-upgrade
args: ['--target-version', '5.1']
# Python upgrade syntax
- repo: https://github.com/asottile/pyupgrade
rev: v3.17.0
hooks:
- id: pyupgrade
args: ['--py312-plus']
exclude: '^(migrations)/.*\.py$'
# Type checking (optional - uncomment to enable)
# Note: This can be slow, so it's disabled by default
# - repo: https://github.com/pre-commit/mirrors-mypy
# rev: v1.11.2
# hooks:
# - id: mypy
# args: ['--config-file=pyproject.toml', '--ignore-missing-imports']
# additional_dependencies:
# - django-stubs
# - types-python-dateutil
# - types-requests
# - types-PyYAML
# exclude: '^(migrations|tests?|conftest\.py)/.*\.py$'
# Local Django checks
- repo: local
hooks:
- id: django-check
name: Django check
entry: uv run python manage.py check --fail-level WARNING
language: system
types: [python]
pass_filenames: false
always_run: true
stages: [pre-commit]
- id: django-makemigrations-check
name: Check for missing migrations
entry: uv run python manage.py makemigrations --check --dry-run
language: system
types: [python]
pass_filenames: false
files: 'models\.py$'
stages: [pre-commit]
- id: django-test-critical
name: Run critical tests
entry: bash -c 'DJANGO_SETTINGS_MODULE=settings uv run pytest apps/common/tests/test_behaviors.py -q --tb=no'
language: system
types: [python]
pass_filenames: false
stages: [pre-push]
# Configuration
default_language_version:
python: python3.12
exclude: |
(?x)^(
.*\.egg-info/.*|
\.git/.*|
\.venv/.*|
venv/.*|
build/.*|
dist/.*|
staticfiles/.*|
media/.*|
node_modules/.*|
htmlcov/.*|
\.coverage|
\.pytest_cache/.*|
__pycache__/.*|
.*\.pyc|
.*\.pyo|
.*\.mo|
.*\.pot|
.*\.log|
.*\.sqlite3|
.*\.db|
\.env.*|
\.DS_Store
)$
fail_fast: false
default_stages: [pre-commit, pre-push]