pmb: Make RunOutputTypeDefault and RunOutputTypePopen enums

This allows us to get rid of some of the validation in sanity_checks()
as mypy handles this validation at "build time", and any typos in the
enum instantiation would be a runtime error rather than a silent
failure.

Additionally, it allows us to encode some of the behaviour of the
different output types into the type definition itself by using methods.

Part-of: https://gitlab.postmarketos.org/postmarketOS/pmbootstrap/-/merge_requests/2642
(cherry picked from commit 7d2f055bcb)

pmb: Fix PmbArgs containing a string for output

While the annotations were changed to suggest that the output property
of PmbArgs contains a RunOutputType, at runtime it actually contained a
string because the argument parsing code hadn't been adapted to create a
RunOutputType. Fix this, and also change it to RunOutputTypeDefault as
while at it as that's more accurate.

Fixes 7d2f055bcb
Part-of: https://gitlab.postmarketos.org/postmarketOS/pmbootstrap/-/merge_requests/2644
This commit is contained in:
Newbyte 2025-07-07 17:00:58 +02:00
parent 3ea5a3433b
commit 861de1e507
No known key found for this signature in database
GPG key ID: 5AE7F5513E0885CB
21 changed files with 193 additions and 88 deletions

View file

@ -9,7 +9,7 @@ from typing import Any, cast
from pmb.core.arch import Arch
from pmb.core import Config
from pmb.types import PmbArgs
from pmb.types import PmbArgs, RunOutputTypeDefault
from pmb.helpers.exceptions import NonBugError
try:
@ -1088,12 +1088,13 @@ def get_parser() -> argparse.ArgumentParser:
chroot.add_argument("--user", help="run the command as user, not as root", action="store_true")
chroot.add_argument(
"--output",
choices=["log", "stdout", "interactive", "tui", "background"],
choices=list(RunOutputTypeDefault),
type=RunOutputTypeDefault.from_string,
help="how the output of the"
" program should be handled, choose from: 'log',"
" 'stdout', 'interactive', 'tui' (default),"
" 'background'. Details: pmb/helpers/run_core.py",
default="tui",
default=RunOutputTypeDefault.TUI,
)
chroot.add_argument(
"--image",