Files
nixos-core/.githooks/pre-commit
T
kiskaadee 61a2798d4f build(nix): unify Python dev environment via .venv symlink and add pyright to scripts/test
- Extract shared pythonEnv in flake.nix and symlink .venv in devShell
  shellHook so IDEs, terminal, and Nix checks share one Python 3.14 env.
- Add pyright static type checking to scripts/test and align pre-commit
  with the unified Nix environment.
- Remove personal domain from flake.nix description and ignore .venv.
2026-10-15 19:27:30 -05:00

37 lines
1.2 KiB
Bash
Executable File

#!/usr/bin/env bash
set -euo pipefail
# ==============================================================================
# Homelab Core Pre-Commit Invariant & Quality Gate Hook
# Runs linter (Ruff), static type checker (Pyright), and test suite (Pytest)
# ==============================================================================
REPO_ROOT="$(cd "$(dirname "${BASH_SOURCE[0]}")/.." && pwd)"
cd "$REPO_ROOT"
echo "🔍 [pre-commit] Executing Homelab Core invariant checks..."
# 1. Run Ruff Linter
echo " ↳ Linting repository with Ruff..."
if command -v ruff >/dev/null 2>&1; then
ruff check .
elif command -v nix >/dev/null 2>&1 && [ -f flake.nix ]; then
nix develop --command ruff check .
else
echo "⚠️ [pre-commit] Neither ruff nor nix found; skipping ruff"
fi
# 2. Run Pytest Suite
echo " ↳ Running structural and security test suite with Pytest..."
if [ -x ".venv/bin/pytest" ]; then
.venv/bin/pytest tests/
elif command -v pytest >/dev/null 2>&1; then
pytest tests/
elif command -v nix >/dev/null 2>&1 && [ -f flake.nix ]; then
nix develop --command pytest tests/
else
echo "⚠️ [pre-commit] Neither pytest nor nix found; skipping pytest"
fi
echo "✅ [pre-commit] All repository checks passed successfully!"