refactor: move generate_pack modes into packs

Option checks go to packs/packoptions.py, the run modes to
packs/packmodes.py and the platform choice to packs/platformrun.py.
generate_pack.py keeps main() and build_parser(). Tests patch the
package modules instead of command attributes.
This commit is contained in:
Abdessamad Derraz committed 2026-11-21 15:47:20 +01:00
1 parent ac06822d2e
commit 37ec04aed1
7 files changed
+436 -415

No files matched your search

+1
View File
@@ -21,6 +21,7 @@ COMMANDS = {
"packs/manifestentry.py", "packs/manifestcores.py", "packs/standalone.py",
"packs/manifest.py", "packs/finalize.py", "packs/outputdir.py", "packs/variants.py",
"packs/manifestrun.py", "packs/packcheck.py", "packs/platformrun.py",
"packs/packoptions.py", "packs/packmodes.py",
),
"verify.py": (
"packs/verdicts.py", "packs/gaps.py", "packs/coverage.py", "packs/emulatorcheck.py",
+3 -2
View File
@@ -151,7 +151,7 @@ class AMissingDataDirectoryFailsTheRun(unittest.TestCase):
def test_the_pack_records_it_and_main_exits_non_zero(self):
import generate_pack as gp
from packs import datatrees
from packs import datatrees, packmodes
from packs import platformpack
root = Path(tempfile.mkdtemp())
@@ -179,7 +179,8 @@ class AMissingDataDirectoryFailsTheRun(unittest.TestCase):
)
self.assertEqual(datatrees.MISSING_DATA_DIRS, {"assets"})
# main() starts each run with no notices, so the run itself records it.
with mock.patch.object(gp, "_main", lambda held: datatrees.MISSING_DATA_DIRS.add("assets")), \
with mock.patch.object(packmodes, "run_pack_command",
lambda parser, held: datatrees.MISSING_DATA_DIRS.add("assets")), \
contextlib.redirect_stderr(io.StringIO()), \
self.assertRaises(SystemExit) as stop:
gp.main()
+3 -3
View File
@@ -68,7 +68,7 @@ class AMistypedTargetIsRefusedFirst(unittest.TestCase):
from unittest import mock
import generate_pack
from packs import platformrun
from packs import packmodes, platformrun
def touched(*_a, **_kw):
raise AssertionError("lock or refresh taken before the target check")
@@ -77,8 +77,8 @@ 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, "hold_data_dirs", touched), \
mock.patch.object(packmodes, "pack_output_lock", touched), \
mock.patch.object(packmodes, "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()), \