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()
|
||||
|
||||
Reference in new issue
Block a user