#!/usr/bin/env bash # 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 # # 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 # runs the hook. `pre-commit install` does not arrange that, so this script puts the # virtualenv first on PATH inside the installed hook scripts. It is idempotent; run it # again after changing requirements-dev.txt or the hook types. set -euo pipefail root="$(git rev-parse --show-toplevel)" cd "$root" python3 -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" for hook in pre-commit commit-msg; do file="$(git rev-parse --git-path "hooks/$hook")" if ! grep -qxF "$marker" "$file"; then tmp="$(mktemp)" { head -n 1 "$file" printf '%s\n' "$marker" "export PATH=\"$root/.venv/bin:\$PATH\"" tail -n +2 "$file" } > "$tmp" cat "$tmp" > "$file" # keeps the file mode of the hook rm -f "$tmp" fi done echo "Done: git commit now runs the hooks with the tools in $root/.venv/bin."