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
This commit is contained in:
1 parent
3a777ac015
commit
b0607a39e2
12 files changed
+285
-43
No files matched your search
@@ -399,6 +399,53 @@ def check_pins(matrix, consumer_texts):
|
||||
return errors
|
||||
|
||||
|
||||
PYTHON_PIN_FILE = ".python-version"
|
||||
LOCK_FILE = "requirements-dev.lock"
|
||||
PYTHON_PIN_RE = re.compile(r"[0-9]+\.[0-9]+")
|
||||
LOCK_PYTHON_RE = re.compile(
|
||||
r"^# This file is autogenerated by pip-compile with Python ([0-9]+\.[0-9]+)\s*$",
|
||||
re.MULTILINE,
|
||||
)
|
||||
ARG_PYTHON_RE = re.compile(
|
||||
r"^[ \t]*ARG[ \t]+PYTHON_VERSION=[\"']?([^\s\"'#]+)[\"']?[ \t\r]*(?:#.*)?$",
|
||||
re.MULTILINE | re.IGNORECASE,
|
||||
)
|
||||
|
||||
|
||||
def check_python_pin(pin_text, lock_text, dockerfiles):
|
||||
"""Errors where the Python of .python-version, the header of requirements-dev.lock and the
|
||||
`ARG PYTHON_VERSION=` of an image Dockerfile (path -> text) are not one MAJOR.MINOR version. A
|
||||
clone's virtualenv (scripts/dev-setup.sh) and the ci image's /opt/venv use the first, the lock
|
||||
records the third as the interpreter it was resolved on; at least one Dockerfile must carry the ARG."""
|
||||
pin = pin_text.strip()
|
||||
if not PYTHON_PIN_RE.fullmatch(pin):
|
||||
return [f"{PYTHON_PIN_FILE} must hold one MAJOR.MINOR version, found {pin!r}"]
|
||||
errors = []
|
||||
header = LOCK_PYTHON_RE.search(lock_text)
|
||||
if not header:
|
||||
errors.append(
|
||||
f"{LOCK_FILE}: no 'autogenerated by pip-compile with Python X.Y' header"
|
||||
)
|
||||
elif header.group(1) != pin:
|
||||
errors.append(
|
||||
f"{LOCK_FILE}: header says Python {header.group(1)} but {PYTHON_PIN_FILE} is {pin}; "
|
||||
"regenerate it with scripts/lock-requirements.sh"
|
||||
)
|
||||
carriers = 0
|
||||
for path, text in dockerfiles.items():
|
||||
for arg in ARG_PYTHON_RE.findall(text):
|
||||
carriers += 1
|
||||
if arg != pin:
|
||||
errors.append(
|
||||
f"{path}: ARG PYTHON_VERSION={arg} but {PYTHON_PIN_FILE} is {pin}"
|
||||
)
|
||||
if not carriers:
|
||||
errors.append(
|
||||
f"no image Dockerfile has an ARG PYTHON_VERSION= line; the ci image must build /opt/venv on {pin}"
|
||||
)
|
||||
return errors
|
||||
|
||||
|
||||
JOB_IMAGE_RE = re.compile(r"ubuntu:(?P<release>[0-9]+\.[0-9]+)@sha256:[0-9a-f]{64}")
|
||||
CONTAINER_LINE_RE = re.compile(
|
||||
r"^\s*container:[ \t]*\n\s*image:\s*\$\{\{\s*matrix\.job_image\s*\}\}[ \t]*$",
|
||||
@@ -717,6 +764,23 @@ def run(argv):
|
||||
errors += check_image_metadata(
|
||||
matrix, lambda p: pathlib.Path(p).read_text(), file_size
|
||||
)
|
||||
dockerfiles = {}
|
||||
for entry in matrix.values():
|
||||
path = (
|
||||
str(pathlib.PurePosixPath(entry["subpath"]) / entry["dockerfile"])
|
||||
if entry["subpath"]
|
||||
else entry["dockerfile"]
|
||||
)
|
||||
if pathlib.Path(path).exists():
|
||||
dockerfiles[path] = pathlib.Path(path).read_text()
|
||||
try:
|
||||
errors += check_python_pin(
|
||||
pathlib.Path(PYTHON_PIN_FILE).read_text(),
|
||||
pathlib.Path(LOCK_FILE).read_text(),
|
||||
dockerfiles,
|
||||
)
|
||||
except OSError as exc:
|
||||
errors.append(f"cannot read the Python pin files: {exc}")
|
||||
workflows = (
|
||||
sorted(pathlib.Path(WORKFLOW_DIR).glob("*.y*ml"))
|
||||
if pathlib.Path(WORKFLOW_DIR).is_dir()
|
||||
|
||||
+21
-15
@@ -3,11 +3,11 @@
|
||||
# (requirements-dev.lock, the hashed lock of requirements-dev.txt: the versions CI runs), the pinned collections the roles call
|
||||
# (requirements.yml) and git hooks that find the tools.
|
||||
#
|
||||
# scripts/dev-setup.sh # KAMINO_PYTHON=python3.13 scripts/dev-setup.sh to pick one
|
||||
# scripts/dev-setup.sh # KAMINO_PYTHON=/path/to/python3.13 scripts/dev-setup.sh to pick one
|
||||
#
|
||||
# KAMINO_PYTHON (default python3) selects the interpreter that is checked and that creates
|
||||
# a new virtualenv. An existing virtualenv is kept when it already runs Python 3.13+, even
|
||||
# if it was built by another interpreter; only an older one is rebuilt.
|
||||
# The interpreter must be the Python of .python-version (python<MINOR> by default, KAMINO_PYTHON selects
|
||||
# another path); it creates a new virtualenv. An existing virtualenv is kept when it runs that Python,
|
||||
# even if another interpreter built it; one on a different Python is rebuilt.
|
||||
#
|
||||
# The repository is the one this script lives in, whatever the caller's working directory.
|
||||
#
|
||||
@@ -24,17 +24,6 @@
|
||||
# idempotent; run it again after changing requirements-dev.txt or its lock, requirements.yml or the hook types.
|
||||
set -euo pipefail
|
||||
|
||||
# ansible-core 2.22 (requirements-dev.txt) needs Python 3.13+. Renovate raises that pin, so
|
||||
# when a bump of it changes the minimum Python, raise py_ok and the message below in the
|
||||
# same pull request. The ci image has python3.13 next to the distribution's;
|
||||
# without a system 3.13, `uv python install 3.13` provides one.
|
||||
python="${KAMINO_PYTHON:-python3}"
|
||||
py_ok='import sys; sys.exit(0 if sys.version_info >= (3, 13) else 1)'
|
||||
if ! "$python" -c "$py_ok" 2>/dev/null; then
|
||||
echo "error: $python is missing or older than 3.13 (ansible-core 2.22 needs 3.13+); set KAMINO_PYTHON=/path/to/python3.13 (uv python install 3.13)" >&2
|
||||
exit 1
|
||||
fi
|
||||
|
||||
# The repository is derived from this script's own location (symlinks resolved), never
|
||||
# from the caller's working directory: running it from another repository must not
|
||||
# create or remove that repository's .venv.
|
||||
@@ -42,6 +31,23 @@ script="$(readlink -f "${BASH_SOURCE[0]}")"
|
||||
root="$(git -C "$(dirname "$script")/.." rev-parse --show-toplevel)"
|
||||
cd "$root"
|
||||
|
||||
# The Python of the virtualenv is the one in .python-version (a minor version, e.g. 3.13): the one the
|
||||
# lock was resolved on and the ci image's /opt/venv runs on (check_image_versions.py pins keeps the lock
|
||||
# header and the image's Dockerfile equal to it). ansible-core 2.22 needs 3.13+; when a Renovate bump
|
||||
# raises that minimum, .python-version, the ci image's PYTHON_VERSION and the lock move in one pull request.
|
||||
[ -f .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:]' < .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}"
|
||||
py_ok="import sys; sys.exit(0 if '%d.%d' % sys.version_info[:2] == '$pin' else 1)"
|
||||
if ! "$python" -c "$py_ok" 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
|
||||
|
||||
# `pre-commit install` refuses to run when core.hooksPath is set, and git would not run
|
||||
# .git/hooks anyway. A repo-local setting whose values all resolve to this repository's own
|
||||
# hooks directory (or are empty) is harmless: it is lifted for the install and restored
|
||||
|
||||
@@ -7,7 +7,8 @@
|
||||
# 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).
|
||||
# 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
|
||||
@@ -32,13 +33,19 @@ case "${1:-}" in
|
||||
*) 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
|
||||
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
|
||||
|
||||
root="$(cd "$(dirname "$(readlink -f "${BASH_SOURCE[0]}")")/.." && pwd)"
|
||||
tmp="$(mktemp -d)"
|
||||
trap 'rm -rf "$tmp"' EXIT
|
||||
|
||||
|
||||
Reference in new issue
Block a user