This project now uses pre-commit hooks to automatically check code quality before commits.
# 1. Install pre-commit (if not already installed)
brew install pre-commit
# or: pip install pre-commit
# 2. Install the git hooks
pre-commit install
# 3. (Optional) Run on all files to test
pre-commit run --all-filesThe pre-commit hooks will automatically run on every git commit:
-
Ruff Linting - Fast Python linter checking for:
- Code style issues (PEP 8)
- Common bugs and anti-patterns
- Unused imports and variables
- Modern Python idioms (pyupgrade)
-
Ruff Formatting - Automatic code formatting (Black-compatible)
-
Security Checks - Bandit scans for common security issues
-
File Quality:
- Remove trailing whitespace
- Ensure files end with newline
- Check YAML/TOML syntax
- Detect merge conflicts
- Check for large files (>1MB)
Once installed, hooks run automatically on git commit. If any hook fails:
- The commit is blocked
- Files are auto-fixed when possible (formatting, whitespace)
- Review the changes with
git diff - Stage fixes with
git add - Commit again
# Run on staged files
pre-commit run
# Run on all files
pre-commit run --all-files
# Run specific hook
pre-commit run ruff --all-files
# Update hooks to latest versions
pre-commit autoupdate# Skip all hooks for a commit (not recommended)
git commit --no-verify
# Skip specific hook
SKIP=bandit git commitThe root Makefile provides shortcuts:
make pre-commit # Install hooks and run on all files
make lint # Run ruff manually
make format # Auto-format code
make security # Run safety + bandit- Pre-commit config:
.pre-commit-config.yaml - Ruff config:
pyproject.toml(see[tool.ruff]section) - Bandit config:
pyproject.toml(see[tool.bandit]section)
Test files are excluded from bandit security checks. If you're getting false positives, add exclusions to pyproject.toml.
Review the changes with git diff. Ruff follows Black formatting style. If needed, adjust settings in pyproject.toml.
Pre-commit caches hook environments in ~/.cache/pre-commit/. Clear with:
pre-commit clean
pre-commit gcpre-commit autoupdatePre-commit hooks complement (but don't replace) CI checks:
- Local: Fast feedback on common issues before push
- CI: Comprehensive testing across Python versions, security scans, coverage
Both use the same tools (ruff, bandit) for consistency.