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
+1 -1
View File
@@ -38,7 +38,7 @@ COMMANDS = {
),
"slots.py": ("packs/slots.py", "resolve/collisions.py", "packs/slotscan.py", "packs/slotreport.py"),
"validate_pr.py": (
"resolve/review.py", "resolve/reviewfiles.py", "resolve/reviewreport.py",
"resolve/review.py", "devtools/reviewfiles.py", "devtools/reviewreport.py",
"core/gitclone.py",
),
"refresh_data_dirs.py": ("packs/datadirs.py", "packs/datadirextract.py"),
+5 -5
View File
@@ -58,7 +58,7 @@ class GitThatCannotAnswer(unittest.TestCase):
proc = subprocess.run(
[sys.executable, "-c", (
f"import sys; sys.path.insert(0, {str(REPO_ROOT / 'scripts')!r}); "
"from resolve import reviewfiles; print(reviewfiles.get_changed_files())"
"from devtools import reviewfiles; print(reviewfiles.get_changed_files())"
)],
cwd=tmp, capture_output=True, text=True, timeout=60, check=False,
)
@@ -88,14 +88,14 @@ class AProjectMainThatCannotBeFetched(unittest.TestCase):
cli.run_cli(worktree.project_base)
self.assertEqual(ended.exception.code, 1)
self.assertEqual(err.getvalue(), "ERROR: no main\n")
from resolve import reviewfiles
from devtools import reviewfiles
with self.assertRaises(RuntimeError):
reviewfiles.get_changed_files()
def test_both_tools_compare_against_the_same_line(self):
from core import gitclone
from profiling import worktree
from resolve import reviewfiles
from devtools import reviewfiles
diffs: list[tuple[str, ...]] = []
@@ -130,7 +130,7 @@ class ChangesNotYetCommittedAreRead(unittest.TestCase):
proc = subprocess.run(
[sys.executable, "-c", (
f"import sys; sys.path.insert(0, {str(REPO_ROOT / 'scripts')!r}); "
"from resolve import reviewfiles; print(reviewfiles.get_changed_files())"
"from devtools import reviewfiles; print(reviewfiles.get_changed_files())"
)],
cwd=tmp, capture_output=True, text=True, timeout=60, check=False,
)
@@ -153,7 +153,7 @@ class AForkPushedToItsOwnMain(unittest.TestCase):
return subprocess.run(
[sys.executable, "-c", (
f"import sys; sys.path.insert(0, {str(REPO_ROOT / 'scripts')!r}); "
"from resolve import reviewfiles; from core import gitclone; "
"from devtools import reviewfiles; from core import gitclone; "
f"gitclone.PROJECT_URLS = ({project!r},); "
"print(reviewfiles.get_changed_files())"
)],
+1 -1
View File
@@ -16,7 +16,7 @@ import tempfile
import unittest
from pathlib import Path
from resolve import reviewfiles
from devtools import reviewfiles
from resolve import review
REPO_ROOT = Path(__file__).resolve().parent.parent
+1 -1
View File
@@ -20,7 +20,7 @@ from pathlib import Path
import yaml
from resolve import reviewfiles
from devtools import reviewfiles
from core import gitclone
from resolve import review
+3 -2
View File
@@ -54,8 +54,9 @@ scripts/ all tooling (Python and pyyaml, jsonschema for schema c
release/ the release record, its notes, the checks of its assets and the pack downloader
installer_build/ install.py from installer/, its pins, launchers and PyPI package
schemas/ the data contracts behind validate_schemas.py: schemas and semantic invariants
devtools/ the commit message rules, the checks of a pull request, the test
runner, the disk cleanup and the bios/ migration
devtools/ the commit message rules, the checks of a pull request, the BIOS
review's files and report (validate_pr.py), the test runner,
the disk cleanup and the bios/ migration
unattended/ the job registry, worktree, CI breaker and units behind autorun.py
freshness/ each transcribed layer against its upstream (check_freshness.py) and the
refresh of each stale row (refresh_stale.py)