Pre-commit hook: auto-recover broken venv before running checks #61

Closed
opened 2026-03-21 19:12:14 +00:00 by kert · 0 comments
Owner

Problem

When .venv is broken (symlink to /root, stale uv version, missing editable install), the pre-commit hook fails at the first uv run call with a cryptic permission error. The developer has to manually rm -rf .venv && uv sync — a friction point.

Fix

Add a venv health check at the top of .git/hooks/pre-commit:

# Ensure venv is healthy before running checks
if ! uv run python -c 'import sys' 2>/dev/null; then
  echo "==> pre-commit: venv broken, running uv sync --dev"
  uv sync --dev
fi

This auto-recovers the venv if it's broken, before any lint/test/notebook checks run.

Files

  • .git/hooks/pre-commit
## Problem When `.venv` is broken (symlink to /root, stale uv version, missing editable install), the pre-commit hook fails at the first `uv run` call with a cryptic permission error. The developer has to manually `rm -rf .venv && uv sync` — a friction point. ## Fix Add a venv health check at the top of `.git/hooks/pre-commit`: ```bash # Ensure venv is healthy before running checks if ! uv run python -c 'import sys' 2>/dev/null; then echo "==> pre-commit: venv broken, running uv sync --dev" uv sync --dev fi ``` This auto-recovers the venv if it's broken, before any lint/test/notebook checks run. ## Files - `.git/hooks/pre-commit`
kert added this to the P12: uv Hygiene — fix venv, build system, python resolution milestone 2026-03-21 19:12:14 +00:00
kert added the config label 2026-03-21 19:12:14 +00:00
kert closed this issue 2026-03-21 19:34:02 +00:00
Sign in to join this conversation.
1 Participants
Notifications
Due Date
No due date set.
Dependencies

No dependencies set.

Reference: homelab/stack#61