fix(scripts): resolve the ruff findings in the scripts and tests
Fix what ruff 0.17.5's default rule set and the complexity rules report (#112): removeprefix/removesuffix instead of slicing, `_unused` for discarded tuple members, obsolete `noqa: E402` removed, a parenthesised string pair and an immutable class constant in the tests. Three functions stay over a complexity threshold and carry an inline `# noqa` with the rule code and a reason: matrix_of and copy_sources of check_image_versions.py (#96 may replace them) and path_problems of check_tarball.py. No rule is ignored globally and no threshold is tuned. ruff writes .ruff_cache/ into the checkout, which test_real_build_passes caught in the Collection archive: add it to galaxy.yml build_ignore. ruff.toml joins the molecule selector's IGNORED paths, since no scenario reads it. Co-Authored-By: Claude Sonnet 5.5 <[email protected]> Claude-Session: https://claude.ai/code/session_014uGZTNmHMc85bomfevwUDG
This commit is contained in:
1 parent
db1c1e176f
commit
697e4b6092
9 files changed
+30
-26
No files matched your search
@@ -145,7 +145,7 @@ def _scalar(raw, where):
|
||||
return value
|
||||
|
||||
|
||||
def matrix_of(text):
|
||||
def matrix_of(text): # noqa: C901, PLR0912, PLR0915 hand-written block-YAML reader; #96 may replace it
|
||||
"""Return {name: {version, subpath, dockerfile[, job_image]}} from the text of image.yml.
|
||||
|
||||
A purpose-built block-style reader, not a YAML parser: the Renovate image has no PyYAML
|
||||
@@ -294,7 +294,7 @@ def _mount_reads_context(line):
|
||||
return False
|
||||
|
||||
|
||||
def copy_sources(dockerfile_text, name="Dockerfile"):
|
||||
def copy_sources(dockerfile_text, name="Dockerfile"): # noqa: C901 one branch per unsupported COPY form; #96 may replace it
|
||||
"""Context paths a Dockerfile COPY/ADD reads (not --from=, not URLs).
|
||||
|
||||
Fails closed (CheckError naming the file and line) on anything whose real path cannot
|
||||
@@ -353,7 +353,7 @@ def _under(path, entry):
|
||||
entry = entry.strip()
|
||||
if entry in ("", ".", "./", "/"):
|
||||
return True
|
||||
entry = entry[2:] if entry.startswith("./") else entry
|
||||
entry = entry.removeprefix("./")
|
||||
return (
|
||||
path == entry.rstrip("/")
|
||||
or path.startswith(entry.rstrip("/") + "/")
|
||||
@@ -432,7 +432,7 @@ def dockerfile_releases(dockerfile_text):
|
||||
f"line {lineno}: FROM {ref} holds a variable, so its release cannot be read"
|
||||
)
|
||||
else:
|
||||
name, unused, tag = ref.split("@")[0].partition(":")
|
||||
name, _unused, tag = ref.split("@")[0].partition(":")
|
||||
if name in UBUNTU_NAMES:
|
||||
releases.append(tag)
|
||||
else:
|
||||
@@ -570,7 +570,7 @@ def check_image_metadata(matrix, read_file, size_of):
|
||||
f"image '{name}': the title label is '{title}', expected the image name"
|
||||
)
|
||||
base = labels.get("org.opencontainers.image.base.name", "").strip()
|
||||
releases, unused = dockerfile_releases(text)
|
||||
releases, _unused = dockerfile_releases(text)
|
||||
if (
|
||||
base
|
||||
and sorted(set(releases))
|
||||
|
||||
@@ -104,8 +104,8 @@ MAX_COMPONENT_BYTES = 255
|
||||
|
||||
def normalize(name):
|
||||
"""The member name without one leading './' and one trailing '/' (so 'a//' stays odd and is rejected)."""
|
||||
path = name[:-1] if name.endswith("/") else name
|
||||
return path[2:] if path.startswith("./") else path
|
||||
path = name.removesuffix("/")
|
||||
return path.removeprefix("./")
|
||||
|
||||
|
||||
def fold(text):
|
||||
@@ -130,7 +130,7 @@ def component_problems(path, part):
|
||||
return []
|
||||
|
||||
|
||||
def path_problems(name):
|
||||
def path_problems(name): # noqa: C901 one check per rule of the archive allowlist
|
||||
"""Problems of one member path, as a list of messages (empty when the path is fine)."""
|
||||
if name.startswith("/"):
|
||||
return [f"{name!r}: absolute path"]
|
||||
|
||||
@@ -66,6 +66,7 @@ IGNORED = (
|
||||
".ansible-lint",
|
||||
".pre-commit-config.yaml",
|
||||
"requirements-dev.txt",
|
||||
"ruff.toml",
|
||||
"apm.yml",
|
||||
"apm.lock.yaml",
|
||||
"tests/sanity/*",
|
||||
|
||||
Reference in new issue
Block a user