ci: add weekly audit for uv override-dependencies#1887
ci: add weekly audit for uv override-dependencies#1887
Conversation
Signed-off-by: Dong Hyuk Chang <9426164+thomasdhc@users.noreply.github.com> Co-Authored-By: Claude Opus 4.6 (1M context) <noreply@anthropic.com>
Signed-off-by: Dong Hyuk Chang <9426164+thomasdhc@users.noreply.github.com> Co-Authored-By: Claude Opus 4.6 (1M context) <noreply@anthropic.com>
| def remove_override_line(pyproject: Path, spec: str) -> None: | ||
| """Strip the single line containing the given override spec.""" | ||
| text = pyproject.read_text() | ||
| pattern = re.compile( | ||
| r'^[ \t]*"' + re.escape(spec) + r'"[ \t]*,?[ \t]*(#.*)?\n', | ||
| re.MULTILINE, | ||
| ) | ||
| new_text, count = pattern.subn("", text, count=1) | ||
| if count != 1: | ||
| msg = f"Could not locate override line for {spec!r} in {pyproject}" | ||
| raise RuntimeError(msg) | ||
| pyproject.write_text(new_text) |
There was a problem hiding this comment.
remove_override_line silently misclassifies single-quoted specs
TOML allows both "double-quoted" and 'single-quoted' string literals. tomllib returns the same Python string either way, but the regex only anchors on ". Any spec written with single quotes in pyproject.toml (e.g. 'packaging>=21.0') will fail to match, raise a RuntimeError, get caught by the broad except Exception in main, and appear in the report as "error: audit failed: Could not locate override line …" rather than being correctly audited. Fix by matching either quote style:
pattern = re.compile(
r'^[ \t]*["\']' + re.escape(spec) + r'["\'][ \t]*,?[ \t]*(#.*)?\n',
re.MULTILINE,
)| def remove_override_line(pyproject: Path, spec: str) -> None: | ||
| """Strip the single line containing the given override spec.""" | ||
| text = pyproject.read_text() | ||
| pattern = re.compile( | ||
| r'^[ \t]*"' + re.escape(spec) + r'"[ \t]*,?[ \t]*(#.*)?\n', | ||
| re.MULTILINE, | ||
| ) | ||
| new_text, count = pattern.subn("", text, count=1) | ||
| if count != 1: | ||
| msg = f"Could not locate override line for {spec!r} in {pyproject}" | ||
| raise RuntimeError(msg) | ||
| pyproject.write_text(new_text) |
There was a problem hiding this comment.
Inline or compact TOML arrays will break the regex
If override-dependencies is written as a single-line inline array — override-dependencies = ["pkg>=1.0", "other==2.0"] — the ^ anchor never matches because the spec is not at the start of a line. The RuntimeError is again caught as an "error" result, meaning those overrides are silently mis-reported rather than audited. The function's docstring says "Strip the single line containing the given override spec", so this limitation should at least be documented, or validated up-front by asserting the array is written in multi-line form before entering the per-spec loop.
Signed-off-by: Dong Hyuk Chang <9426164+thomasdhc@users.noreply.github.com> Co-Authored-By: Claude Opus 4.6 (1M context) <noreply@anthropic.com>
Signed-off-by: Dong Hyuk Chang <9426164+thomasdhc@users.noreply.github.com> Co-Authored-By: Claude Opus 4.6 (1M context) <noreply@anthropic.com>
|
/ok to test c9da3bd |
| if ver is None: | ||
| return "stale", f"{req.name} is not in the lock without the override" |
There was a problem hiding this comment.
Misleading "stale" classification when
ver is None for a specifier override
_categorize falls through to return "stale", f"{req.name} is not in the lock without the override" for any version-constraining spec when the package is absent from the freshly generated lock. For a normal version override, the package should still be pulled in (overrides constrain versions, they don't add deps). The only realistic paths to ver is None here are:
- Package-name canonicalization failure (e.g., a dotted name — see the separate thread on
locked_version), which causes a false "stale" classification rather than a lookup error. - The package is only an optional extra and no extras were locked.
In case 1 the silent misclassification makes the audit trustworthy only for packages with no dots or extra-only specs. Consider distinguishing these cases — e.g., log a warning or return an intermediate category when ver is None but lock succeeded for a specifier override.
Description
[tool.uv] override-dependenciesfor staleness, by removing it frompyproject.tomland re-runninguv lock.Usage
Output
Checklist