From c82bb5405185b58fb8f9f2270a58b642bcde7d77 Mon Sep 17 00:00:00 2001 From: Abdessamad Derraz <3028866+Abdess@users.noreply.github.com> Date: Tue, 17 Nov 2026 09:33:10 +0100 Subject: [PATCH] chore: type the install.py loaders --- scripts/generate_event_schema.py | 2 ++ scripts/generate_launcher_index.py | 2 ++ scripts/generate_readme.py | 9 ++++++--- scripts/make_demo.py | 5 +++-- 4 files changed, 13 insertions(+), 5 deletions(-) diff --git a/scripts/generate_event_schema.py b/scripts/generate_event_schema.py index 78167681b..e12ced373 100644 --- a/scripts/generate_event_schema.py +++ b/scripts/generate_event_schema.py @@ -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) diff --git a/scripts/generate_launcher_index.py b/scripts/generate_launcher_index.py index 6592d26e4..f04275b29 100644 --- a/scripts/generate_launcher_index.py +++ b/scripts/generate_launcher_index.py @@ -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) diff --git a/scripts/generate_readme.py b/scripts/generate_readme.py index d9088ea54..c7f71f54c 100644 --- a/scripts/generate_readme.py +++ b/scripts/generate_readme.py @@ -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 diff --git a/scripts/make_demo.py b/scripts/make_demo.py index 5684f4cc5..4b9411834 100644 --- a/scripts/make_demo.py +++ b/scripts/make_demo.py @@ -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: