mirror of
https://github.com/Abdess/retroarch_system.git
synced 2026-12-02 14:28:54 -06:00
fix: run every pipeline step from the repo root
The in-process steps read platforms/, database.json and bios/ from the caller's directory while child steps ran at the root. pipeline.main now moves to the root once --output-dir is resolved, and the step 5 comparisons run from the root when called directly.
This commit is contained in:
1 parent
9b2957fbe4
commit
6dd9eabcb8
6 files changed
+100
-8
No files matched your search
@@ -9,6 +9,7 @@ from core.paths import DB_FILE, EMULATORS_DIR, PLATFORMS_DIR
|
||||
from model.profiles import reads_own_files
|
||||
from orchestrate.compare import set_difference_lines
|
||||
from orchestrate.labels import STEP_LABELS, step_title
|
||||
from orchestrate.runner import at_repo_root
|
||||
from orchestrate.narrowed import matrix_coverage
|
||||
|
||||
# The narrowings an emulator or system pack takes, compared by
|
||||
@@ -37,6 +38,7 @@ def emulator_variants(profiles: list[dict], full: bool) -> list[tuple[str, dict]
|
||||
return variants
|
||||
|
||||
|
||||
@at_repo_root()
|
||||
def check_emulator_packs(
|
||||
emulators_dir: str = EMULATORS_DIR, platforms_dir: str = PLATFORMS_DIR,
|
||||
db_path: str = DB_FILE, full: bool = False,
|
||||
|
||||
@@ -8,6 +8,7 @@ import io
|
||||
from core.paths import DB_FILE, EMULATORS_DIR, PLATFORMS_DIR
|
||||
from orchestrate.compare import comparison_inputs, set_difference_lines
|
||||
from orchestrate.labels import STEP_LABELS, step_title
|
||||
from orchestrate.runner import at_repo_root
|
||||
from packs.archive import is_pack_note
|
||||
|
||||
# How each pack_narrowings() dimension of a platform pack is compared by
|
||||
@@ -72,6 +73,7 @@ def narrowed_variants(
|
||||
return variants
|
||||
|
||||
|
||||
@at_repo_root()
|
||||
def check_narrowed_packs(
|
||||
emulators_dir: str = EMULATORS_DIR, platforms_dir: str = PLATFORMS_DIR,
|
||||
db_path: str = DB_FILE, full: bool = False,
|
||||
|
||||
@@ -2,10 +2,12 @@
|
||||
|
||||
from __future__ import annotations
|
||||
|
||||
import contextlib
|
||||
import os
|
||||
import subprocess
|
||||
import time
|
||||
from pathlib import Path
|
||||
from typing import Iterator
|
||||
|
||||
from core.paths import REPO_ROOT
|
||||
from orchestrate.labels import step_title
|
||||
@@ -24,6 +26,30 @@ def pack_output_dir(typed: str | None) -> str:
|
||||
return str(Path(typed).resolve())
|
||||
|
||||
|
||||
def enter_repo_root() -> None:
|
||||
"""Move the run to the repository root, where every step reads its inputs.
|
||||
|
||||
The child steps already ran there, while the steps run in this process
|
||||
read platforms/, database.json and bios/ from the caller's directory:
|
||||
started from scripts/, the offline refusal found no registry and stayed
|
||||
silent, verify held no data directory, and step 5 stopped on a missing
|
||||
registry after every pack was built. Called once the typed
|
||||
--output-dir is resolved, since that one is read from where it was typed.
|
||||
"""
|
||||
os.chdir(REPO_ROOT)
|
||||
|
||||
|
||||
@contextlib.contextmanager
|
||||
def at_repo_root() -> Iterator[None]:
|
||||
"""Run the block from the repository root, then go back to the caller's directory."""
|
||||
previous = os.getcwd()
|
||||
os.chdir(REPO_ROOT)
|
||||
try:
|
||||
yield
|
||||
finally:
|
||||
os.chdir(previous)
|
||||
|
||||
|
||||
def run(cmd: list[str], label: str) -> tuple[bool, str]:
|
||||
"""Run a command, echoing its output as it comes. Returns (success, output).
|
||||
|
||||
|
||||
@@ -10,6 +10,7 @@ from typing import TYPE_CHECKING
|
||||
from core.paths import DB_FILE, EMULATORS_DIR, PLATFORMS_DIR
|
||||
from orchestrate.compare import comparison_inputs
|
||||
from orchestrate.labels import STEP_LABELS, step_title
|
||||
from orchestrate.runner import at_repo_root
|
||||
from packs.archive import is_pack_note
|
||||
|
||||
if TYPE_CHECKING:
|
||||
@@ -40,6 +41,7 @@ def split_differences(
|
||||
return lines
|
||||
|
||||
|
||||
@at_repo_root()
|
||||
def check_split_packs(
|
||||
emulators_dir: str = EMULATORS_DIR, platforms_dir: str = PLATFORMS_DIR,
|
||||
db_path: str = DB_FILE,
|
||||
|
||||
+3
-2
@@ -70,7 +70,7 @@ from orchestrate.guards import (
|
||||
from orchestrate.locks import hold_outputs
|
||||
from orchestrate.prepare import database_steps, refresh_steps, truth_steps
|
||||
from orchestrate.results import StepResults, print_summary
|
||||
from orchestrate.runner import pack_output_dir
|
||||
from orchestrate.runner import enter_repo_root, pack_output_dir
|
||||
|
||||
|
||||
def build_parser() -> argparse.ArgumentParser:
|
||||
@@ -134,6 +134,8 @@ def main() -> None:
|
||||
parser = build_parser()
|
||||
args = parser.parse_args()
|
||||
refuse_unapplied_flags(parser, args)
|
||||
args.output_dir = pack_output_dir(args.output_dir)
|
||||
enter_repo_root()
|
||||
refuse_offline_without_caches(parser, args)
|
||||
refuse_offline_export_without_originals(parser, args)
|
||||
if not args.offline:
|
||||
@@ -141,7 +143,6 @@ def main() -> None:
|
||||
# scrapers and refresh_data_dirs went anonymous unless the user had
|
||||
# exported GITHUB_TOKEN by hand, though gh was logged in.
|
||||
github_token()
|
||||
args.output_dir = pack_output_dir(args.output_dir)
|
||||
held = hold_outputs(args)
|
||||
|
||||
total_start = time.monotonic()
|
||||
|
||||
@@ -332,18 +332,77 @@ class EveryEmulatorPackMatchesItsReport(unittest.TestCase):
|
||||
self.skipTest("database.json is not built")
|
||||
from orchestrate.emulatorpacks import check_emulator_packs
|
||||
|
||||
# Run from elsewhere: the step resolves its inputs at the repository
|
||||
# root, as the pipeline's child steps do.
|
||||
previous = os.getcwd()
|
||||
os.chdir(REPO_ROOT)
|
||||
try:
|
||||
with contextlib.redirect_stdout(io.StringIO()) as out:
|
||||
ok = check_emulator_packs()
|
||||
finally:
|
||||
os.chdir(previous)
|
||||
with tempfile.TemporaryDirectory() as elsewhere:
|
||||
os.chdir(elsewhere)
|
||||
try:
|
||||
with contextlib.redirect_stdout(io.StringIO()) as out:
|
||||
ok = check_emulator_packs()
|
||||
finally:
|
||||
os.chdir(previous)
|
||||
self.assertTrue(ok, out.getvalue())
|
||||
# Packs of several profiles too: a placement rule that only goes
|
||||
# wrong when two profiles share a path never meets in one profile.
|
||||
self.assertIn("system packs compared, all equal", out.getvalue())
|
||||
|
||||
|
||||
class EveryStepReadsFromTheRepositoryRoot(unittest.TestCase):
|
||||
"""Started from scripts/, the steps run in the pipeline's own process read
|
||||
platforms/ and database.json there: the offline refusal saw no registry,
|
||||
and step 5 stopped on it after every pack was built."""
|
||||
|
||||
def test_the_run_moves_to_the_root_once_the_output_dir_is_read(self):
|
||||
import sys
|
||||
from unittest import mock
|
||||
|
||||
from scripts import pipeline
|
||||
|
||||
seen: dict[str, str] = {}
|
||||
|
||||
def stop(_parser, args):
|
||||
seen["cwd"] = os.getcwd()
|
||||
seen["output_dir"] = args.output_dir
|
||||
raise SystemExit(0)
|
||||
|
||||
previous = os.getcwd()
|
||||
self.addCleanup(os.chdir, previous)
|
||||
with tempfile.TemporaryDirectory() as elsewhere:
|
||||
os.chdir(elsewhere)
|
||||
argv = ["pipeline.py", "--offline", "--skip-docs", "--output-dir", "out"]
|
||||
with mock.patch.object(sys, "argv", argv), \
|
||||
mock.patch.object(pipeline, "refuse_offline_without_caches", stop), \
|
||||
self.assertRaises(SystemExit):
|
||||
pipeline.main()
|
||||
typed_from = Path(elsewhere).resolve()
|
||||
self.assertEqual(Path(seen["cwd"]), REPO_ROOT)
|
||||
self.assertEqual(Path(seen["output_dir"]), typed_from / "out")
|
||||
|
||||
def test_the_step_five_checks_read_from_the_root(self):
|
||||
from unittest import mock
|
||||
|
||||
from orchestrate import narrowed, splitcheck
|
||||
|
||||
previous = os.getcwd()
|
||||
self.addCleanup(os.chdir, previous)
|
||||
for module, check in ((narrowed, narrowed.check_narrowed_packs),
|
||||
(splitcheck, splitcheck.check_split_packs)):
|
||||
with self.subTest(check=check.__name__), tempfile.TemporaryDirectory() as elsewhere:
|
||||
os.chdir(elsewhere)
|
||||
seen: list[str] = []
|
||||
|
||||
def inputs(*_args, seen=seen):
|
||||
seen.append(os.getcwd())
|
||||
return {}, {}, {}, {}, []
|
||||
|
||||
with mock.patch.object(module, "comparison_inputs", inputs), \
|
||||
contextlib.redirect_stdout(io.StringIO()):
|
||||
check()
|
||||
self.assertEqual([Path(c) for c in seen], [REPO_ROOT])
|
||||
self.assertEqual(Path(os.getcwd()), Path(elsewhere).resolve())
|
||||
os.chdir(previous)
|
||||
|
||||
|
||||
if __name__ == "__main__":
|
||||
unittest.main()
|
||||
Reference in new issue
Block a user