Something went wrong. Try again.
[READ-ONLY] Mirror of https://github.com/mojzis/python-template.
Something went wrong. Try again.
123456789101112131415161718192021222324252627282930313233343536373839#!/usr/bin/env bashset -euo pipefail
# Get staged Python filesSTAGED_PY_FILES=$(git diff --cached --name-only --diff-filter=ACM -- '*.py')
if [ -z "$STAGED_PY_FILES" ]; then exit 0fi
echo "Pre-commit: checking staged Python files..."
# Phase 1: Auto-fix (format + lint fix)echo "$STAGED_PY_FILES" | xargs uv run ruff format --quietecho "$STAGED_PY_FILES" | xargs uv run ruff check --fix --quiet 2>/dev/null || true
# Re-stage any auto-fixed filesecho "$STAGED_PY_FILES" | xargs git add
# Phase 2: Report-only checksFAILED=0
echo "$STAGED_PY_FILES" | xargs uv run ruff check --no-fix || FAILED=1
uv run ty check || FAILED=1
# Run bandit only on src files (skip tests)STAGED_SRC_FILES=$(echo "$STAGED_PY_FILES" | grep -v '^tests/' || true)if [ -n "$STAGED_SRC_FILES" ]; then echo "$STAGED_SRC_FILES" | xargs uv run bandit -q || FAILED=1fi
if [ "$FAILED" -ne 0 ]; then echo "" echo "Pre-commit checks failed. Fix the issues above or bypass with:" echo " git commit --no-verify" exit 1fi