chore: type the install.py loaders

This commit is contained in:
Abdessamad Derraz committed 2026-11-17 09:33:10 +01:00
1 parent d096a31143
commit c82bb54051
4 files changed
+13 -5

No files matched your search

+2
View File
@@ -19,6 +19,8 @@ ROOT = Path(__file__).resolve().parent.parent
OUTPUT = ROOT / "schemas" / "install-events.schema.json"
_spec = importlib.util.spec_from_file_location("install", ROOT / "install.py")
if _spec is None or _spec.loader is None:
raise ImportError(f"cannot load {ROOT / 'install.py'}")
_install = importlib.util.module_from_spec(_spec)
_spec.loader.exec_module(_install)
+2
View File
@@ -36,6 +36,8 @@ from build_port import (
OUTPUT = REPO_ROOT / "install" / "launchers" / "index.json"
_spec = importlib.util.spec_from_file_location("install", REPO_ROOT / "install.py")
if _spec is None or _spec.loader is None:
raise ImportError(f"cannot load {REPO_ROOT / 'install.py'}")
_install = importlib.util.module_from_spec(_spec)
_spec.loader.exec_module(_install)
+6 -3
View File
@@ -18,6 +18,7 @@ import sys
from collections.abc import Callable
from datetime import datetime, timezone
from pathlib import Path
from types import ModuleType
sys.path.insert(0, os.path.dirname(__file__))
from common import (
@@ -46,13 +47,15 @@ import pr_checks
from verify import verify_platform
def _installer_words() -> object:
def _installer_words() -> ModuleType:
"""install.py read as a module, for the words its screen shows: the
README named a line menu the one-liner never opens."""
import importlib.util
spec = importlib.util.spec_from_file_location(
"install", Path(__file__).resolve().parent.parent / "install.py")
path = Path(__file__).resolve().parent.parent / "install.py"
spec = importlib.util.spec_from_file_location("install", path)
if spec is None or spec.loader is None:
raise ImportError(f"cannot load {path}")
module = importlib.util.module_from_spec(spec)
spec.loader.exec_module(module)
return module
+3 -2
View File
@@ -64,6 +64,7 @@ import shutil
import subprocess
import sys
import threading
import types
from collections.abc import Iterator
from contextlib import contextmanager
from dataclasses import dataclass
@@ -363,7 +364,7 @@ def session_env(base_url: str, work: Path, card: Path,
}
def _installer() -> object:
def _installer() -> types.ModuleType:
spec = importlib.util.spec_from_file_location("retrobios_install", ROOT / "install.py")
if spec is None or spec.loader is None:
raise RuntimeError("install.py cannot be loaded")
@@ -374,7 +375,7 @@ def _installer() -> object:
def format_size(size: int) -> str:
"""The size as the installer writes it."""
return str(_installer().format_size(size)) # type: ignore[attr-defined]
return str(_installer().format_size(size))
def describe(variant: str, facts: dict) -> str: