fix(scripts): make dev-setup.sh check Python, core.hooksPath and the installed hooks
Build / build (pull_request) Successful in 8s
Lint / lint (pull_request) Successful in 5s

Require Python 3.11+ (PYTHON selects the interpreter), rebuild a virtualenv made
by an older Python, exit early when core.hooksPath is set, fail clearly when a
hook was not installed, and resolve the hook path with --path-format=absolute.

Co-Authored-By: Claude Sonnet 5.5 <[email protected]>
Claude-Session: https://claude.ai/code/session_01MmzvM9skAvYcph2c9EiPcm
This commit is contained in:
Defame1297andClaude Sonnet 5.5 committed 2026-10-25 18:20:47 +00:00
1 parent 32018e27f0
commit 4ed03b508a
2 files changed
+35 -3

No files matched your search

+31 -3
View File
@@ -2,7 +2,7 @@
# Sets up a local checkout for development: a virtualenv with the pinned tools
# (requirements-dev.txt, the versions CI runs) and git hooks that find them.
#
# scripts/dev-setup.sh
# scripts/dev-setup.sh # PYTHON=python3.12 scripts/dev-setup.sh to pick one
#
# Some hooks of .pre-commit-config.yaml are `language: system` (REUSE, changelog lint,
# ansible-lint): they run their tools by name, so the tools must be on PATH when git
@@ -11,16 +11,44 @@
# again after changing requirements-dev.txt or the hook types.
set -euo pipefail
# ansible-core 2.19 (requirements-dev.txt) needs Python 3.11+. The ci image uses the
# distribution's 3.12; any 3.11+ gives the same pins.
python="${PYTHON:-python3}"
py_ok='import sys; sys.exit(0 if sys.version_info >= (3, 11) else 1)'
if ! "$python" -c "$py_ok" 2>/dev/null; then
echo "error: $python is missing or older than 3.11 (ansible-core 2.19 needs 3.11+); set PYTHON=/path/to/python3.12" >&2
exit 1
fi
root="$(git rev-parse --show-toplevel)"
cd "$root"
python3 -m venv .venv
# `pre-commit install` refuses to run when core.hooksPath is set, and git would not run
# .git/hooks anyway. Say so up front instead of failing half way.
hooks_path="$(git config --get core.hooksPath || true)"
if [ -n "$hooks_path" ]; then
echo "error: core.hooksPath is set to '$hooks_path', so git does not run the hooks pre-commit installs." >&2
echo " Unset it for this clone (git config --unset core.hooksPath; add --global if it is set there)" >&2
echo " or manage the hooks in that directory yourself, then re-run this script." >&2
exit 1
fi
# A virtualenv made by an older Python is rebuilt rather than reused.
if [ -x .venv/bin/python ] && ! .venv/bin/python -c "$py_ok" 2>/dev/null; then
rm -rf "$root/.venv"
fi
[ -x .venv/bin/python ] || "$python" -m venv .venv
.venv/bin/pip install --quiet --disable-pip-version-check -r requirements-dev.txt
.venv/bin/pre-commit install --install-hooks
marker="# kamino-dev-setup: virtualenv first on PATH"
# default_install_hook_types in .pre-commit-config.yaml names these; keep in step.
for hook in pre-commit commit-msg; do
file="$(git rev-parse --git-path "hooks/$hook")"
file="$(git rev-parse --path-format=absolute --git-path "hooks/$hook")"
if [ ! -f "$file" ]; then
echo "error: $file was not installed by 'pre-commit install'; check default_install_hook_types in .pre-commit-config.yaml." >&2
exit 1
fi
if ! grep -qxF "$marker" "$file"; then
tmp="$(mktemp)"
{