refactor: move the review's glue to devtools

This commit is contained in:
Abdessamad Derraz committed 2026-11-22 00:58:05 +01:00
1 parent 19bcc76c8f
commit e146a8f349
9 files changed
+40 -29

No files matched your search

+1 -1
View File
@@ -1 +1 @@
"""The repository's own tooling: commit rules, pull request checks, the test runner, disk cleanup, the bios/ migration."""
"""The repository's own tooling: commit rules, pull request checks, the BIOS review's files and report, the test runner, disk cleanup, the bios/ migration."""
@@ -11,8 +11,6 @@ from typing import TYPE_CHECKING
from core.gitclone import compare_base, git_lines
if TYPE_CHECKING:
import argparse
from resolve.review import ValidationResult
@@ -67,24 +65,28 @@ def expand_folders(paths: list[str]) -> list[str]:
return out
def files_to_validate(args: argparse.Namespace, parser: argparse.ArgumentParser) -> list[str]:
class SelectionError(ValueError):
"""The files named and --changed do not select a set to review."""
class ChangedFilesUnreadable(Exception):
"""git could not say which files this checkout changes."""
def files_to_validate(files: list[str], changed: bool) -> list[str]:
"""The files named on the command line, or the changed ones."""
if args.changed and args.files:
if changed and files:
# Named files were dropped for the git diff, and the run reported
# "No changed BIOS files detected" about files it never looked at.
parser.error("--changed reads the git diff: name files or pass --changed, not both")
if not args.changed:
if not args.files:
parser.error("No files specified. Use --changed or provide file paths.")
return expand_folders(args.files)
raise SelectionError("--changed reads the git diff: name files or pass --changed, not both")
if not changed:
if not files:
raise SelectionError("No files specified. Use --changed or provide file paths.")
return expand_folders(files)
try:
files = get_changed_files()
return get_changed_files()
except (RuntimeError, OSError) as exc:
print(f"Error: {exc}", file=sys.stderr)
sys.exit(2)
if not files and not args.json:
print("No changed BIOS files detected")
return files
raise ChangedFilesUnreadable(str(exc)) from exc
def place(results: list[ValidationResult]) -> list[str]:
File renamed without changes.
+11 -3
View File
@@ -27,8 +27,8 @@ sys.path.insert(0, os.path.dirname(__file__))
from model.database import load_optional_database
from core.cli import add_repo_inputs, require_directory
from resolve.review import load_platform_hashes, load_profile_hashes, validate_file
from resolve.reviewfiles import files_to_validate, place
from resolve.reviewreport import json_rows, markdown_report, text_lines
from devtools.reviewfiles import ChangedFilesUnreadable, SelectionError, files_to_validate, place
from devtools.reviewreport import json_rows, markdown_report, text_lines
def main() -> None:
@@ -63,8 +63,16 @@ def main() -> None:
args.files = [os.path.abspath(f) for f in args.files]
work_from_repo_root(args, parser, ["db", "platforms_dir", "emulators_dir"])
files = files_to_validate(args, parser)
try:
files = files_to_validate(args.files, args.changed)
except SelectionError as exc:
parser.error(str(exc))
except ChangedFilesUnreadable as exc:
print(f"Error: {exc}", file=sys.stderr)
sys.exit(2)
if not files:
if args.changed and not args.json:
print("No changed BIOS files detected")
if args.json:
print("[]")
return