-
Notifications
You must be signed in to change notification settings - Fork 0
/
pre-commit
33 lines (26 loc) · 818 Bytes
/
pre-commit
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
#!/usr/bin/env bash
# If any command fails, exit immediately with that command's exit status
set -eo pipefail
# Find all changed files for this commit
# Compute the diff only once to save a small amount of time.
CHANGED_FILES=$(git diff --cached --name-only --diff-filter=ACMRTUXB)
# Get only changed files that match our file suffix pattern
get_pattern_files() {
pattern=$(echo "$*" | sed "s/ /\$\\\|/g")
echo "$CHANGED_FILES" | { grep "$pattern$" || true; }
}
# Get all changed Python files
PY_FILES=$(get_pattern_files .py)
if [[ -n "$PY_FILES" ]]
then
pytest -vv
echo "tests passed."
black --check $PY_FILES
echo "black passed."
ruff check $PY_FILES
echo "ruff passed."
svst --check $PY_FILES
echo "svst passed."
mypy --check $PY_FILES
echo "mypy passed."
fi