ci(lint): accept an apm-cli bump in the bot-diff check
A Renovate pull request may now change pyproject.toml and uv.lock, but only together, so the pep621 manager can move the apm pin. In pyproject.toml only the version of a quoted name==version pin may change. uv.lock is parsed with tomllib in a module of its own, check_uv_lock.py, because uv installs whatever the lock names and a line-shape rule cannot tie a file to its package: a file of another package under apm-cli, an added package, a marker that drops a dependency and a downgrade all passed one. The parsed rule allows only apm-cli moving up to the pin in pyproject.toml, as plain releases compared as numbers, with the same kinds of file as before (an sdist if it had one, the same wheel tags), each on files.pythonhosted.org under /packages/ without dot segments or escapes, named for apm-cli at the pin, by sha256. Every other package, the root project beyond its apm-cli specifier and the top level beyond `revision` must stay as they are. Without the same file kinds, a lock could drop the wheels and make uv build apm-cli from its sdist with a build backend fetched at sync time. A bump that moves anything else is made by hand. Refs: #518 Assisted-by: Claude Code
This commit is contained in:
1 parent
535926b36e
commit
47641ae01d
7 files changed
+754
-10
No files matched your search
@@ -12,6 +12,10 @@ When <head-ref> starts with `renovate/`, the diff of <base-ref>...HEAD may only
|
||||
`name==version` entries, `--hash=sha256:<64 hex>` lines and plain `# via` or prose comments,
|
||||
nothing else; packages may be added or removed (a transitive dependency), but the
|
||||
`# pip-compile ...` command in the header, which Renovate runs again, must stay as it is;
|
||||
* pyproject.toml: the version of a quoted `"name==version"` pin (the names, spelled as they
|
||||
are, and every other line, stay), only together with uv.lock;
|
||||
* uv.lock: the apm-cli bump to the pin of the new pyproject.toml, and nothing else
|
||||
(check_uv_lock.py), only together with pyproject.toml;
|
||||
* requirements.yml and extensions/molecule/requirements.yml: `version:` lines (the collection
|
||||
names, and every other line, stay);
|
||||
* .pre-commit-config.yaml: `rev:` lines (a tag, or a commit SHA with its `# frozen: <tag>` comment);
|
||||
@@ -50,6 +54,7 @@ import re
|
||||
import sys
|
||||
|
||||
import check_image_versions as civ
|
||||
import check_uv_lock
|
||||
|
||||
PREFIX = "renovate/"
|
||||
TAG = r"[A-Za-z0-9._-]+"
|
||||
@@ -73,6 +78,7 @@ COLLECTION_PINS = {"requirements.yml", "extensions/molecule/requirements.yml"}
|
||||
# Lint's and the molecule-controller image's requirements, each with its pip-compile lock.
|
||||
REQUIREMENTS = {"requirements-dev.txt", "requirements-molecule.txt"}
|
||||
LOCKS = {"requirements-dev.lock", "requirements-molecule.lock"}
|
||||
UV_LOCK = "uv.lock"
|
||||
CONSUMERS = {
|
||||
".gitea/workflows/lint.yml",
|
||||
".gitea/workflows/build.yml",
|
||||
@@ -144,6 +150,16 @@ def lock_problem(removed, added):
|
||||
return None
|
||||
|
||||
|
||||
# A quoted `name==version` pin in a pyproject.toml dependency array.
|
||||
PYPROJECT_PIN = re.compile(r'"([A-Za-z0-9][A-Za-z0-9._-]*)==[0-9][0-9A-Za-z.+!_-]*"')
|
||||
|
||||
|
||||
def reduce_pyproject(line):
|
||||
if not PYPROJECT_PIN.search(line):
|
||||
return None
|
||||
return PYPROJECT_PIN.sub(lambda m: f'"{m[1]}==X"', line)
|
||||
|
||||
|
||||
def reduce_rev(line):
|
||||
return "rev" if REV_LINE.match(line) else None
|
||||
|
||||
@@ -178,6 +194,10 @@ def file_problem(path, removed, added):
|
||||
)
|
||||
if path in LOCKS:
|
||||
return lock_problem(removed, added)
|
||||
if path == "pyproject.toml":
|
||||
return same_shape(
|
||||
removed, added, reduce_pyproject, "a quoted `name==version` pin"
|
||||
)
|
||||
if path in COLLECTION_PINS:
|
||||
return same_shape(removed, added, reduce_version, "a `version:` line")
|
||||
if path == ".pre-commit-config.yaml":
|
||||
@@ -254,15 +274,22 @@ def moved_problem(removed, added):
|
||||
return None
|
||||
|
||||
|
||||
def check(entries, patch_of):
|
||||
"""One message per offending file; patch_of(path) returns that file's -U0 patch text."""
|
||||
def check(entries, patch_of, show=None):
|
||||
"""One message per offending file; patch_of(path) returns that file's -U0 patch text and
|
||||
show(side, path) its text on the "base" or "head" side (needed for uv.lock)."""
|
||||
problems = []
|
||||
# The pin and its lock move together, so neither can change what the other one locks.
|
||||
partners = {"pyproject.toml": UV_LOCK, UV_LOCK: "pyproject.toml"}
|
||||
paths = {path for unused, unused, unused, path in entries}
|
||||
for old_mode, new_mode, status, path in entries:
|
||||
if status != "M" or old_mode != new_mode or new_mode != "100644":
|
||||
problems.append(
|
||||
f"{path}: a bot pull request may not add, delete, rename or change the mode of a file"
|
||||
)
|
||||
continue
|
||||
if path in partners and partners[path] not in paths:
|
||||
problems.append(f"{path}: changes without {partners[path]}")
|
||||
continue
|
||||
patch = patch_of(path)
|
||||
if BINARY.search(patch):
|
||||
problems.append(
|
||||
@@ -276,9 +303,22 @@ def check(entries, patch_of):
|
||||
f"{len(removed)} removed and {len(added)} added (binary or empty change?)"
|
||||
)
|
||||
continue
|
||||
reason = file_problem(
|
||||
path, [line for unused, line in removed], [line for unused, line in added]
|
||||
)
|
||||
if path == UV_LOCK:
|
||||
reason = (
|
||||
check_uv_lock.lock_problem(
|
||||
show("base", path),
|
||||
show("head", path),
|
||||
show("head", "pyproject.toml"),
|
||||
)
|
||||
if show
|
||||
else "is not a file a bot pull request may change"
|
||||
)
|
||||
else:
|
||||
reason = file_problem(
|
||||
path,
|
||||
[line for unused, line in removed],
|
||||
[line for unused, line in added],
|
||||
)
|
||||
if not reason and path == civ.MATRIX_FILE:
|
||||
reason = moved_problem(removed, added)
|
||||
if reason:
|
||||
@@ -336,8 +376,14 @@ def run(argv):
|
||||
path,
|
||||
)
|
||||
|
||||
def show(side, path):
|
||||
rev = base if side == "base" else "HEAD"
|
||||
return civ.git("cat-file", "blob", f"{rev}:{path}")
|
||||
|
||||
entries = parse_raw(raw)
|
||||
return check(entries, patch_of), f"{len(entries)} file(s) within the bot allowance"
|
||||
return check(
|
||||
entries, patch_of, show
|
||||
), f"{len(entries)} file(s) within the bot allowance"
|
||||
|
||||
|
||||
def main(argv):
|
||||
|
||||
Reference in new issue
Block a user