diff --git a/scripts/devtools/__init__.py b/scripts/devtools/__init__.py index 337ce697e..5abea53a0 100644 --- a/scripts/devtools/__init__.py +++ b/scripts/devtools/__init__.py @@ -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.""" diff --git a/scripts/resolve/reviewfiles.py b/scripts/devtools/reviewfiles.py similarity index 84% rename from scripts/resolve/reviewfiles.py rename to scripts/devtools/reviewfiles.py index e5099f68a..e035c0143 100644 --- a/scripts/resolve/reviewfiles.py +++ b/scripts/devtools/reviewfiles.py @@ -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]: diff --git a/scripts/resolve/reviewreport.py b/scripts/devtools/reviewreport.py similarity index 100% rename from scripts/resolve/reviewreport.py rename to scripts/devtools/reviewreport.py diff --git a/scripts/validate_pr.py b/scripts/validate_pr.py index 70957571e..c87f30c7e 100644 --- a/scripts/validate_pr.py +++ b/scripts/validate_pr.py @@ -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 diff --git a/tests/sources.py b/tests/sources.py index 70a1392e1..2b2dace65 100644 --- a/tests/sources.py +++ b/tests/sources.py @@ -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"), diff --git a/tests/test_refresh_failures.py b/tests/test_refresh_failures.py index fc6379d46..392ce8638 100644 --- a/tests/test_refresh_failures.py +++ b/tests/test_refresh_failures.py @@ -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())" )], diff --git a/tests/test_validate_pr.py b/tests/test_validate_pr.py index ade5317e0..905be7ecd 100644 --- a/tests/test_validate_pr.py +++ b/tests/test_validate_pr.py @@ -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 diff --git a/tests/test_validate_pr_flow.py b/tests/test_validate_pr_flow.py index e64bae9a5..771251367 100644 --- a/tests/test_validate_pr_flow.py +++ b/tests/test_validate_pr_flow.py @@ -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 diff --git a/wiki/architecture.md b/wiki/architecture.md index 40c13ad81..a30078b85 100644 --- a/wiki/architecture.md +++ b/wiki/architecture.md @@ -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)