Files
kevinveenbirkenbachandClaude Opus 5.5 326f063bd3 fix(codescan): clear the mechanical CodeQL notes and lint them away (WIP)
Work-in-progress commit on the collective code-scanning sidetree, so main
can be merged in; the single quality-high gate runs on the integration
branch before the pull request.

Fixes the CodeQL notes py/import-and-import-from, py/unused-import,
py/unused-global-variable, py/empty-except, py/mixed-tuple-returns and
py/unused-local-variable across 194 files, and adds one lint per rule under
tests/lint/repository/python/ so none of them can come back:
test_import_and_import_from, test_unused_imports_hidden_from_ruff,
test_unused_global_variables, test_empty_except, test_mixed_tuple_returns,
test_unused_local_variables, plus test_modules_import.

Accepted security finding: MEDUSA-MP-SCAN-2056 (low) on
utils/i18n/client.py:21, an import line matched by a keyword heuristic;
operator-confirmed false positive.

🎯 Fix: 85 %
💥 Break: 8 %
💸 Cost: –
⏱️ Time: –
🛡️ Security: 100 %
🏆 Score: 78
🚦 Gate: ⛔ fix 85 % < 90, break 8 % > 5

Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
2026-11-13 18:44:29 +00:00

88 lines
2.8 KiB
Python

from __future__ import annotations
import os
import subprocess
from typing import TYPE_CHECKING
from utils.cache import PROJECT_ROOT
from .env import resolve_distro
if TYPE_CHECKING:
import argparse
def add_parser(sub: argparse._SubParsersAction) -> None:
p = sub.add_parser(
"build", help="Build infinito image using scripts/image/build.sh (SPOT)."
)
p.add_argument("--missing", action="store_true", help="Build only if missing.")
p.add_argument("--no-cache", action="store_true", help="Build with --no-cache.")
p.add_argument("--target", help="Dockerfile target (e.g. virgin).", default="")
p.add_argument("--tag", help="Override output tag.", default="")
p.add_argument("--push", action="store_true", help="Push image (buildx).")
p.add_argument(
"--publish", action="store_true", help="Publish semantic tags (implies --push)."
)
p.add_argument("--registry", default="", help="Registry (e.g. ghcr.io).")
p.add_argument("--owner", default="", help="Owner/namespace (e.g. org/user).")
p.add_argument(
"--repo-prefix",
default="",
help="Repo prefix (default: current repository name).",
)
p.add_argument("--version", default="", help="Version (required for --publish).")
p.add_argument(
"--stable", choices=["true", "false"], default="", help="Publish stable tags."
)
p.set_defaults(_handler=handler)
def handler(args: argparse.Namespace) -> int:
repo_root = PROJECT_ROOT
script = repo_root / "scripts" / "image" / "build.sh"
repository_name_script = (
repo_root / "scripts" / "meta" / "resolve" / "repository" / "name.sh"
)
env = dict(os.environ)
env["INFINITO_DISTRO"] = resolve_distro()
if not args.repo_prefix and not env.get("INFINITO_IMAGE_REPOSITORY"):
resolved_repo = subprocess.run(
[str(repository_name_script)],
cwd=repo_root,
env=env,
check=True,
capture_output=True,
text=True,
).stdout.strip()
env["INFINITO_IMAGE_REPOSITORY"] = resolved_repo
cmd: list[str] = [str(script)]
if args.missing:
cmd.append("--missing")
if args.no_cache:
cmd.append("--no-cache")
if args.target:
cmd += ["--target", args.target]
if args.tag:
cmd += ["--tag", args.tag]
if args.push:
cmd.append("--push")
if args.publish:
cmd.append("--publish")
if args.registry:
cmd += ["--registry", args.registry]
if args.owner:
cmd += ["--owner", args.owner]
if args.repo_prefix:
cmd += ["--repo-prefix", args.repo_prefix]
if args.version:
cmd += ["--version", args.version]
if args.stable:
cmd += ["--stable", args.stable]
r = subprocess.run(cmd, cwd=repo_root, env=env, check=False)
return int(r.returncode)