mirror of
https://github.com/kevinveenbirkenbach/computer-playbook.git
synced 2026-11-08 11:46:35 +00:00
Adds ``[tool.ruff.lint]`` with ``select = ["E", "F", "I", "B", "UP"]``
and ``target-version = "py311"``. ``E501`` is ignored because
``ruff format`` already reflows what it can; the remaining long lines
are unsplittable string literals / URLs.
Auto-fixed (2753 issues, behavior-preserving):
- UP006/UP035: ``List[X]`` → ``list[X]``, ``Dict[X]`` → ``dict[X]``,
``from typing import …`` redirected where superseded by builtins.
- UP045: ``Optional[X]`` → ``X | None``.
- UP010/UP009/UP015: dropped Python-2-era pragmas (``from __future__
import absolute_import, division, print_function``,
``# -*- coding: utf-8 -*-``), redundant ``open(..., "r")`` mode.
- UP004: dropped implicit ``class X(object):``.
- UP022/UP008/UP032: stdlib idiom modernization (``capture_output``,
super-call simplification, etc.).
- B905: ``zip(...)`` → ``zip(..., strict=False)`` (preserves prior
behavior; switching to ``strict=True`` is a separate semantic
choice not made here).
- I001: import-block ordering.
Hand-fixed (66 issues):
- B904 × 54: appended ``from <bound>`` (when the enclosing ``except``
binds a name) or ``from None`` (when it doesn't) so chained
exceptions stay distinguishable from errors-during-exception-
handling. Applied via a small AST-aware script that walked back to
the enclosing ``except`` clause and matched the binding.
- B017 × 4: narrowed broad ``assertRaises(Exception)`` to the actual
``AnsibleError`` / ``AnsibleFilterError`` raised by the code under
test.
- B023 × 2: bound captured loop variables via default args
(``def _record(name, *, _path_real=path_real, ...)``) so each
closure gets its own snapshot.
- B007 × 2: unused loop control variables renamed to ``_`` /
rewritten to ``.values()``.
- UP007 × 2: ``Union[X, Y]`` → ``X | Y`` (plus dropping the now-unused
``from typing import Union``).
- B018 × 1: Odoo addon manifests are bare dict expressions at module
level by design — suppressed with an inline ``# noqa: B018`` and
rationale comment.
- UP031 × 1: printf-style format → f-string.
The 65 ``# noqa: …`` markers introduced by the auto-fixer all carry
real ruff codes (``B018``, ``E402``, ``F401``, etc.), so
``test_noqa_only_ruff_codes`` stays green.
Verification
============
- ``ruff check .`` → All checks passed
- ``ruff format --check .`` → 894 files already formatted
- ``tests.lint.repository.{test_project_root_import,
test_no_direct_yaml_calls, test_noqa_only_ruff_codes}`` and
``tests.unit.utils.annotations.test_suppress`` → 20 tests OK
- 1621 unit tests → all pass
- Integration suite: 44 failures (pre-existing baseline, none from
this change), 1 skipped.
Going forward, the new rules block regressions on E (style), F
(pyflakes), I (import order), B (likely-bug patterns), and UP
(modernization to py311) for any new code.
Co-Authored-By: Claude Opus 4.7 (1M context) <noreply@anthropic.com>
84 lines
2.8 KiB
Python
84 lines
2.8 KiB
Python
from __future__ import annotations
|
|
|
|
import argparse
|
|
import os
|
|
import subprocess
|
|
|
|
from . import PROJECT_ROOT
|
|
from .common import resolve_distro
|
|
|
|
|
|
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)
|