Files
Kamino/scripts/lock-requirements.sh
T
Defame1297andClaude Sonnet 5.5 b0607a39e2
Build / build (pull_request) Successful in 14s
Molecule / molecule (pull_request) Canceled after 0s
Lint / lint (pull_request) Canceled after 56s
ci(python): one Python (3.14) for the lock, a clone and the ci image
.python-version (3.14) is the source. dev-setup.sh and lock-requirements.sh
require exactly that minor; the ci image builds /opt/venv from its baked
python-build-standalone of that version (ARG PYTHON_VERSION) instead of the
distribution's python3, and derives the python<MINOR> links for
ansible-test from it; `check_image_versions.py pins` fails when
.python-version, the lock header or an `ARG PYTHON_VERSION` differs.
The lock already carries the 3.14 header (Renovate's -full container runs
pip-compile on its own python 3.14.8); renovate.yml now says that python's
minor version must equal .python-version. ci image 0.2.25 -> 0.2.26.

Co-Authored-By: Claude Sonnet 5.5 <[email protected]>
Claude-Session: https://claude.ai/code/session_014uGZTNmHMc85bomfevwUDG
2026-11-16 07:42:45 +00:00

60 lines
3.2 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 the Python of .python-version (python<MINOR>; KAMINO_PYTHON overrides it): the
# header of the lock records it, and check_image_versions.py pins fails when it differs.
# 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.
# Renovate's pip-compile manager refuses a header with an option it does not know ("Option
# --newline=LF not supported (yet)", dry run 3880): it then extracts nothing and proposes no bump.
# So no --newline here: pip-compile keeps the lock's own line endings (LF on Linux) by default.
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
root="$(cd "$(dirname "$(readlink -f "${BASH_SOURCE[0]}")")/.." && pwd)"
[ -f "$root/.python-version" ] || { echo "error: .python-version is missing (the Python of the lock, a clone and the ci image)" >&2; exit 1; }
pin="$(tr -d '[:space:]' < "$root/.python-version")"
case "$pin" in
[0-9].[0-9]|[0-9].[0-9][0-9]) ;;
*) echo "error: .python-version must hold one MAJOR.MINOR version, found '$pin'" >&2; exit 1 ;;
esac
python="${KAMINO_PYTHON:-python$pin}"
if ! "$python" -c "import sys; sys.exit(0 if '%d.%d' % sys.version_info[:2] == '$pin' else 1)" 2>/dev/null; then
echo "error: $python is missing or is not Python $pin (.python-version); set KAMINO_PYTHON=/path/to/python$pin (uv python install $pin)" >&2
exit 1
fi
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 \
"${upgrade[@]}" --output-file requirements-dev.lock requirements-dev.txt
echo "requirements-dev.lock regenerated; commit it with requirements-dev.txt."