refactor: move generate_pack runs into packs

This commit is contained in:
Abdessamad Derraz committed 2026-11-21 14:58:17 +01:00
1 parent c58f3e624e
commit a1b8a10cf9
13 files changed
+866 -788

No files matched your search

+2 -1
View File
@@ -19,7 +19,8 @@ COMMANDS = {
"packs/archive.py", "packs/naming.py", "packs/scope.py", "packs/datatrees.py",
"packs/platformpack.py", "packs/emulatorpack.py", "packs/md5pack.py", "packs/targets.py",
"packs/manifestentry.py", "packs/manifestcores.py", "packs/standalone.py",
"packs/manifest.py", "packs/finalize.py",
"packs/manifest.py", "packs/finalize.py", "packs/outputdir.py", "packs/variants.py",
"packs/manifestrun.py", "packs/packcheck.py", "packs/platformrun.py",
),
"verify.py": (
"packs/verdicts.py", "packs/gaps.py", "packs/coverage.py", "packs/emulatorcheck.py",
+2 -2
View File
@@ -4517,7 +4517,7 @@ class ADataDirectoryIsHeldWhileRead(unittest.TestCase):
# against data/ while a refresh could swap a tree.
pack = script_source("generate_pack.py")
branch = pack.index("if args.verify_packs and not args.all_variants:")
run = pack.index("_run_verify_packs(args)", branch)
run = pack.index("run_verify_packs(args)", branch)
self.assertIn("hold_data_dirs(held,", pack[branch:run])
@@ -4889,7 +4889,7 @@ class VerifyPacksSaysWhatItExcluded(unittest.TestCase):
def test_the_result_is_unpacked_whole_and_every_error_printed(self):
source = script_source("generate_pack.py")
body = source[source.index("def _run_verify_packs"):]
body = source[source.index("def _check_pack"):]
body = body[:body.index("\ndef ")]
self.assertIn("bl_excluded, bl_absent) = result", body)
self.assertIn("baseline_shortfall(bl_excluded, bl_absent)", body)
+4 -4
View File
@@ -1,6 +1,6 @@
"""The conformance stage reads the directories the run was given.
``_run_platform_packs`` called ``verify_and_finalize_packs`` without them, so
``run_platform_packs`` called ``verify_and_finalize_packs`` without them, so
packs built from ``--platforms-dir`` and ``--emulators-dir`` were judged
against ``platforms/`` and ``emulators/``, or not matched to any platform at
all and never judged.
@@ -16,7 +16,7 @@ import unittest
from pathlib import Path
from unittest import mock
import generate_pack as gp
from packs import platformrun
from packs import finalize as packs_finalize
from packs import integrity as packverify
@@ -42,9 +42,9 @@ class ConformanceUsesTheRunDirectories(unittest.TestCase):
if split:
Path(self.tmp.name, "X_Split").mkdir(exist_ok=True)
with self.subTest(split=split), mock.patch.object(
gp, "verify_and_finalize_packs", return_value=True
platformrun, "verify_and_finalize_packs", return_value=True
) as finalize:
gp._run_platform_packs(
platformrun.run_platform_packs(
self._args(split), [], {}, {}, {}, {}, {}, None
)
self.assertTrue(finalize.call_args_list)
+9 -11
View File
@@ -16,9 +16,10 @@ import unittest
from pathlib import Path
from unittest import mock
import generate_pack as gp
from packs import manifest
from packs import manifestrun
from packs import platformpack
from packs import platformrun
REPO_ROOT = Path(__file__).resolve().parents[1]
@@ -45,23 +46,20 @@ class FailedPlatformFailsTheRun(unittest.TestCase):
)
def test_pack_mode(self):
with mock.patch.object(gp, "generate_pack", _boom), \
with mock.patch.object(platformrun, "generate_pack", _boom), \
mock.patch.object(platformpack, "generate_pack", _boom), \
mock.patch.object(gp, "verify_and_finalize_packs", return_value=True), \
self.assertRaises(SystemExit) as ctx:
gp._run_platform_packs(
mock.patch.object(platformrun, "verify_and_finalize_packs", return_value=True):
ok = platformrun.run_platform_packs(
self._args(), [(["retropie"], "retropie")], {}, {}, {}, {}, {}, None
)
self.assertEqual(ctx.exception.code, 1)
self.assertFalse(ok)
def test_manifest_mode(self):
with mock.patch.object(gp, "generate_manifest", _boom), \
mock.patch.object(manifest, "generate_manifest", _boom), \
self.assertRaises(SystemExit) as ctx:
gp._run_manifest_mode(
with mock.patch.object(manifest, "generate_manifest", _boom):
ok = manifestrun.run_manifest_mode(
self._args(), [(["retropie"], "retropie")], {}, {}, {}, {}
)
self.assertEqual(ctx.exception.code, 1)
self.assertFalse(ok)
if __name__ == "__main__":
+4 -2
View File
@@ -127,16 +127,18 @@ class NoPlatformIsSetApart(unittest.TestCase):
class TheBuildReadsTheField(unittest.TestCase):
def _groups(self, *argv: str) -> list[str]:
import generate_pack
from packs import platformrun
built: list[str] = []
def capture(args, groups, *rest, **kw):
built.extend(name for group, _rep in groups for name in group)
return True
with tempfile.TemporaryDirectory() as out, \
contextlib.chdir(REPO_ROOT), \
mock.patch.object(generate_pack, "_run_platform_packs", capture), \
mock.patch.object(generate_pack, "_run_manifest_mode", capture), \
mock.patch.object(platformrun, "run_platform_packs", capture), \
mock.patch.object(platformrun, "run_manifest_mode", capture), \
mock.patch.object(sys, "argv", ["generate_pack.py", *argv, "--output-dir", out]), \
contextlib.redirect_stdout(io.StringIO()):
generate_pack.main()
+4 -1
View File
@@ -68,6 +68,7 @@ class AMistypedTargetIsRefusedFirst(unittest.TestCase):
from unittest import mock
import generate_pack
from packs import platformrun
def touched(*_a, **_kw):
raise AssertionError("lock or refresh taken before the target check")
@@ -76,8 +77,10 @@ class AMistypedTargetIsRefusedFirst(unittest.TestCase):
"--output-dir", str(REPO_ROOT / "tmp" / "never-written")]
err = io.StringIO()
with mock.patch.object(sys, "argv", argv), \
mock.patch.object(generate_pack, "_pack_output_lock", touched), \
mock.patch.object(generate_pack, "pack_output_lock", touched), \
mock.patch.object(generate_pack, "hold_data_dirs", touched), \
mock.patch.object(platformrun, "pack_output_lock", touched), \
mock.patch.object(platformrun, "hold_data_dirs", touched), \
contextlib.redirect_stdout(io.StringIO()), \
contextlib.redirect_stderr(err), \
self.assertRaises(SystemExit) as ctx:
+14 -15
View File
@@ -15,8 +15,9 @@ import json
import os
import tempfile
import unittest
import generate_pack
from packs import naming
from packs import packcheck
from packs import variants
from pathlib import Path
from unittest import mock
@@ -69,8 +70,8 @@ class VerifyPackChoice(unittest.TestCase):
self.variants: list[tuple[str, bool]] = []
with mock.patch.object(generate_pack, "verify_pack_against_platform", record):
generate_pack._run_verify_packs(args)
with mock.patch.object(packcheck, "verify_pack_against_platform", record):
self.ok = packcheck.run_verify_packs(args)
return checked
def _touch(self, name: str) -> None:
@@ -94,9 +95,8 @@ class VerifyPackChoice(unittest.TestCase):
def test_named_platform_with_only_a_narrowed_pack_fails(self):
self._touch(f"{self.stem}_Truth_BIOS_Pack.zip")
with self.assertRaises(SystemExit) as ctx:
self._run(self._args())
self.assertEqual(ctx.exception.code, 1)
self._run(self._args())
self.assertFalse(self.ok)
def test_all_variants_checks_every_variant_as_it_was_built(self):
"""After --all-variants the check opened the full pack only, and then
@@ -104,7 +104,7 @@ class VerifyPackChoice(unittest.TestCase):
one missing a file its narrowed list requires passed. Each is now
held to the platform's list narrowed the same way."""
names = {}
for source, required in generate_pack.ALL_VARIANTS:
for source, required in variants.ALL_VARIANTS:
tags = "".join(
tag for tag, _ in naming.pack_narrowings(source, None, None, False, required)
)
@@ -143,11 +143,10 @@ class VerifyPackChoice(unittest.TestCase):
self._touch(pack)
out, err = io.StringIO(), io.StringIO()
failed = (False, 0, 0, ["x: missing"], 1, 0, 1, 1, 0, 0)
with mock.patch.object(generate_pack, "verify_pack_against_platform",
with mock.patch.object(packcheck, "verify_pack_against_platform",
return_value=failed), \
contextlib.redirect_stdout(out), contextlib.redirect_stderr(err), \
self.assertRaises(SystemExit):
generate_pack._run_verify_packs(self._args())
contextlib.redirect_stdout(out), contextlib.redirect_stderr(err):
self.assertFalse(packcheck.run_verify_packs(self._args()))
self.assertEqual(
err.getvalue().strip().splitlines()[-1],
f"ERROR: packs failed verification: retroarch ({pack})",
@@ -175,9 +174,9 @@ class VerifyPackChoice(unittest.TestCase):
class GroupRenameKeepsSystemTag(unittest.TestCase):
def test_single_system_pack_does_not_take_the_full_name(self):
import generate_pack as gp
from packs import naming
from packs import platformpack
from packs import platformrun
previous = os.getcwd()
os.chdir(REPO_ROOT)
@@ -198,10 +197,10 @@ class GroupRenameKeepsSystemTag(unittest.TestCase):
one_per_slot=False, offline=True, bios_dir="bios",
output_dir=tmp,
)
with mock.patch.object(gp, "generate_pack", fake_generate), \
with mock.patch.object(platformrun, "generate_pack", fake_generate), \
mock.patch.object(platformpack, "generate_pack", fake_generate), \
mock.patch.object(gp, "verify_and_finalize_packs", return_value=True):
gp._run_platform_packs(
mock.patch.object(platformrun, "verify_and_finalize_packs", return_value=True):
platformrun.run_platform_packs(
args, [(["retroarch", "lakka"], "retroarch")], {}, {}, {},
{}, {}, ["atari-lynx"],
)