refactor: load install.py as a module in one place

The event schema, the installer doc, the launcher index, the site and the README each executed install.py with their own importlib block. installer_build.module.installer_module is cached and read by all five.
This commit is contained in:
Abdessamad Derraz committed 2026-11-21 06:02:35 +01:00
1 parent fb17242a78
commit ccd440f67a
7 files changed
+33 -50

No files matched your search

+2 -6
View File
@@ -2,19 +2,15 @@
from __future__ import annotations
import importlib.util
import json
from core.paths import REPO_ROOT
from installer_build.module import installer_module
OUTPUT = REPO_ROOT / "schemas" / "install-events.schema.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)
_install = installer_module()
EVENT_KEYS: dict[str, tuple[str, ...]] = _install.EVENT_KEYS
EVENT_SCHEMA: int = _install.EVENT_SCHEMA
+2 -6
View File
@@ -6,7 +6,6 @@ import argparse
import ast
import contextlib
import http.server
import importlib.util
import json
import os
import re
@@ -23,6 +22,7 @@ from typing import Any, Callable, TYPE_CHECKING
from core.paths import REPO_ROOT
from installer_build import handhelds
from installer_build.module import installer_module
if TYPE_CHECKING:
from install import LocalCopy, Progress, _OsRule
@@ -31,11 +31,7 @@ if TYPE_CHECKING:
PAGE = REPO_ROOT / "wiki" / "installer.md"
INSTALLER = REPO_ROOT / "install.py"
_spec = importlib.util.spec_from_file_location("install", INSTALLER)
if _spec is None or _spec.loader is None:
raise ImportError(f"cannot load {INSTALLER}")
_install = importlib.util.module_from_spec(_spec)
_spec.loader.exec_module(_install)
_install = installer_module()
BLOCK = re.compile(
r"(?P<open><!-- generated: (?P<name>[a-z-]+) -->\n)(?P<body>.*?)"
+2 -6
View File
@@ -3,11 +3,11 @@
from __future__ import annotations
import hashlib
import importlib.util
import json
from pathlib import Path
from core.paths import REPO_ROOT
from installer_build.module import installer_module
from installer_build.pins import installer_sha256, pinned_sha256
from installer_build.port import (
BATOCERA_ZIP,
@@ -20,11 +20,7 @@ from installer_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)
_install = installer_module()
# The archive whose members each system gets, by its key in APP_PLACES.
LAUNCHER_ARCHIVES = {"muos": MUOS_APP, "knulli": BATOCERA_ZIP, "rocknix": TOOLS_ZIP}
+23
View File
@@ -0,0 +1,23 @@
"""install.py read as a module, once per run."""
from __future__ import annotations
import functools
import importlib.util
import types
from core.paths import REPO_ROOT
@functools.cache
def installer_module() -> types.ModuleType:
"""The generated install.py, the artifact served, for its constants and
words: the schema, the doc tables, the launcher index and the site read
the same module."""
path = REPO_ROOT / "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