Repository navigation
Expand file tree
/
Copy path.pre-commit-config.yaml
More file actions
75 lines (69 loc) · 2.95 KB
/
Copy path.pre-commit-config.yaml
File metadata and controls
75 lines (69 loc) · 2.95 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
# Code-quality checks run by pre-commit (https://pre-commit.com).
#
# uv run pre-commit run --all-files # check and auto-fix the whole repository
# uv run pre-commit install # run the checks automatically before every `git commit`
#
# Python and notebook rules (lint, formatting, import order, docstrings, type hints) are configured
# in pyproject.toml under [tool.ruff].
# ---------------------------------------------------------------------------
# File hygiene
# ---------------------------------------------------------------------------
repos:
- repo: https://github.com/pre-commit/pre-commit-hooks
rev: v5.0.0
hooks:
- id: trailing-whitespace
- id: end-of-file-fixer
- id: mixed-line-ending
args: ["--fix=lf"]
- id: check-merge-conflict
- id: check-case-conflict
- id: detect-private-key
- id: check-yaml
- id: check-toml
# Also validates notebooks, which are JSON files
- id: check-json
# Notebooks keep their figures (the largest is ~5 MB); anything bigger is probably data
- id: check-added-large-files
args: ["--maxkb=6000"]
# ---------------------------------------------------------------------------
# Python and Jupyter notebooks: lint + format with ruff
# ---------------------------------------------------------------------------
- repo: https://github.com/astral-sh/ruff-pre-commit
rev: v0.16.9
hooks:
- id: ruff-check
args: ["--fix"]
types_or: ["python", "pyi", "jupyter"]
- id: ruff-format
types_or: ["python", "pyi", "jupyter"]
# ---------------------------------------------------------------------------
# Notebooks: valid nbformat schema (GitHub refuses to render invalid notebooks)
# ---------------------------------------------------------------------------
- repo: local
hooks:
- id: validate-notebooks
name: validate notebooks (nbformat)
language: python
types: [jupyter]
additional_dependencies: ["nbformat>=5.9"]
entry: python -c "import sys, nbformat; [nbformat.validate(nbformat.read(path, as_version=4)) for path in sys.argv[1:]]"
# ---------------------------------------------------------------------------
# Project metadata and dependencies
# ---------------------------------------------------------------------------
- repo: https://github.com/abravalheri/validate-pyproject
rev: v0.25
hooks:
- id: validate-pyproject
- repo: https://github.com/astral-sh/uv-pre-commit
rev: "0.12.19"
hooks:
- id: uv-lock
# ---------------------------------------------------------------------------
# Spelling in code, docstrings and documentation (settings in pyproject.toml [tool.codespell])
# ---------------------------------------------------------------------------
- repo: https://github.com/codespell-project/codespell
rev: v2.4.3
hooks:
- id: codespell
additional_dependencies: ["tomli>=2"]