Files
Kamino/scripts/lock-requirements.sh
T
Dragonish 4058978353
Build / build (pull_request) Successful in 10s
Lint / lint (pull_request) Successful in 1m42s
Molecule / molecule (pull_request) Successful in 5m23s
ci(deps): pin hook revisions by SHA and install dev tools from a hashed lock
Refs #113.

- .pre-commit-config.yaml: every hook repo is pinned by commit SHA with the release in a
  `# frozen:` comment, so a moved tag cannot change the code a hook environment is built from.
- requirements-dev.lock: hashed lock of requirements-dev.txt. Installs use
  `pip install --require-hashes -r requirements-dev.lock -r requirements-dev.txt` (dev-setup.sh,
  the ci image, the fallback install of Lint and Build): pip refuses an unhashed package and any
  disagreement between the two files.
- scripts/lock-requirements.sh regenerates the lock (pinned pip and pip-tools, --upgrade mode).
- renovate.json: the pip-compile manager replaces pip_requirements for the lock, plus a weekly,
  never automerged lock-file maintenance PR for transitive packages. Not yet dry-run on Renovate.
- check_bot_pr_diff.py accepts `rev: <sha>  # frozen: <tag>` and lock entries, hashes and plain
  comments, but not a changed pip-compile header command.
- ci image 0.2.18 -> 0.2.19 (image inputs changed).
2026-11-14 16:52:38 +00:00

50 lines
2.4 KiB
Bash
Executable File

#!/usr/bin/env bash
# SPDX-FileCopyrightText: Defame1297 and contributors
# SPDX-License-Identifier: GPL-3.0-or-later
#
# Regenerate requirements-dev.lock, the hashed lock of requirements-dev.txt (#113).
#
# scripts/lock-requirements.sh re-resolve, keeping every locked version that still fits
# scripts/lock-requirements.sh --upgrade move every package, transitive ones included, to its newest release
#
# Needs the network (PyPI) and Python 3.13+ (ansible-core 2.22; KAMINO_PYTHON overrides python3).
# pip and pip-tools are installed, at the pinned versions below, into a throwaway virtualenv, never
# into the project's .venv. pip is pinned too: pip-tools breaks on newer pip releases (7.5.2 on pip 26). Commit
# the lock with requirements-dev.txt; pip refuses an install of the two when they disagree
# (`pip install --require-hashes -r requirements-dev.lock -r requirements-dev.txt`). An image input
# changed, so the image version needs its bump as usual (python3 scripts/bump_image_versions.py).
# The pins are not hash-checked themselves: they come from PyPI over TLS, like the pip that
# created the throwaway venv.
#
# Renovate runs the same command from the header of the lock (pip-compile manager, renovate.json),
# so keep the header: do not add --no-header, and keep the flags below in step with renovate.json.
set -euo pipefail
pip_version="25.2"
pip_tools_version="7.6.2"
upgrade=()
case "${1:-}" in
"") ;;
--upgrade) upgrade=(--upgrade) ;;
*) echo "usage: lock-requirements.sh [--upgrade]" >&2; exit 2 ;;
esac
python="${KAMINO_PYTHON:-python3}"
if ! "$python" -c 'import sys; sys.exit(0 if sys.version_info >= (3, 13) else 1)' 2>/dev/null; then
echo "error: $python is missing or older than 3.13; set KAMINO_PYTHON=/path/to/python3.13" >&2
exit 1
fi
root="$(cd "$(dirname "$(readlink -f "${BASH_SOURCE[0]}")")/.." && pwd)"
tmp="$(mktemp -d)"
trap 'rm -rf "$tmp"' EXIT
"$python" -m venv "$tmp/venv"
"$tmp/venv/bin/pip" install --quiet --disable-pip-version-check "pip==${pip_version}" "pip-tools==${pip_tools_version}"
cd "$root"
# --allow-unsafe: setuptools is a dependency of a tool here, and pip refuses an unpinned
# requirement in a file that carries hashes.
"$tmp/venv/bin/pip-compile" --quiet --generate-hashes --strip-extras --allow-unsafe --newline lf \
"${upgrade[@]}" --output-file requirements-dev.lock requirements-dev.txt
echo "requirements-dev.lock regenerated; commit it with requirements-dev.txt."