mirror of
https://github.com/Abdess/retroarch_system.git
synced 2026-11-26 19:38:52 -06:00
refactor: public names for cross-module reads
This commit is contained in:
1 parent
f371790dc6
commit
3853ca2f1c
254 files changed
+2955
-2969
No files matched your search
@@ -9,10 +9,8 @@ from collections.abc import Iterator
|
||||
from dataclasses import dataclass, field
|
||||
from pathlib import Path
|
||||
|
||||
from core.paths import REPO_ROOT
|
||||
|
||||
|
||||
ROOT = REPO_ROOT
|
||||
PACKAGE = "installer"
|
||||
OUTPUT = "install.py"
|
||||
COMMAND = "python scripts/build_installer.py"
|
||||
|
||||
@@ -8,12 +8,11 @@ import json
|
||||
from core.paths import REPO_ROOT
|
||||
|
||||
|
||||
ROOT = REPO_ROOT
|
||||
OUTPUT = ROOT / "schemas" / "install-events.schema.json"
|
||||
OUTPUT = REPO_ROOT / "schemas" / "install-events.schema.json"
|
||||
|
||||
_spec = importlib.util.spec_from_file_location("install", ROOT / "install.py")
|
||||
_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 {ROOT / 'install.py'}")
|
||||
raise ImportError(f"cannot load {REPO_ROOT / 'install.py'}")
|
||||
_install = importlib.util.module_from_spec(_spec)
|
||||
_spec.loader.exec_module(_install)
|
||||
|
||||
|
||||
@@ -28,9 +28,8 @@ if TYPE_CHECKING:
|
||||
from install import LocalCopy, Progress, _OsRule
|
||||
|
||||
|
||||
ROOT = REPO_ROOT
|
||||
PAGE = ROOT / "wiki" / "installer.md"
|
||||
INSTALLER = ROOT / "install.py"
|
||||
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:
|
||||
@@ -216,7 +215,7 @@ def line_menu() -> str:
|
||||
import io
|
||||
from unittest import mock
|
||||
|
||||
manifest = json.loads((ROOT / "install" / "retroarch.json").read_text(encoding="utf-8"))
|
||||
manifest = json.loads((REPO_ROOT / "install" / "retroarch.json").read_text(encoding="utf-8"))
|
||||
files = [*manifest["files"], *(manifest.get("case_variants") or [])]
|
||||
folder = Path(MENU_FOLDER)
|
||||
out = io.StringIO()
|
||||
@@ -266,7 +265,7 @@ class _ListHandler(http.server.SimpleHTTPRequestHandler):
|
||||
|
||||
def __init__(self, request: socket.socket | tuple[bytes, socket.socket],
|
||||
client_address: tuple[str, int], server: socketserver.BaseServer) -> None:
|
||||
super().__init__(request, client_address, server, directory=str(ROOT))
|
||||
super().__init__(request, client_address, server, directory=str(REPO_ROOT))
|
||||
|
||||
def do_GET(self) -> None:
|
||||
if not re.fullmatch(r"/install/[a-z0-9_-]+\.json", self.path):
|
||||
@@ -398,8 +397,8 @@ class Sandbox:
|
||||
is printed here."""
|
||||
|
||||
def __enter__(self) -> Sandbox:
|
||||
(ROOT / "tmp").mkdir(exist_ok=True)
|
||||
self.root = Path(tempfile.mkdtemp(prefix="installer-doc-", dir=ROOT / "tmp"))
|
||||
(REPO_ROOT / "tmp").mkdir(exist_ok=True)
|
||||
self.root = Path(tempfile.mkdtemp(prefix="installer-doc-", dir=REPO_ROOT / "tmp"))
|
||||
self.home = self.root / "home"
|
||||
self.card = self.root / "card"
|
||||
config = self.home / ".config" / "retroarch" / "retroarch.cfg"
|
||||
@@ -458,7 +457,7 @@ class Sandbox:
|
||||
"RETROBIOS_BASE_URL": f"http://127.0.0.1:{self.server.server_address[1]}"}
|
||||
done = subprocess.run(
|
||||
[sys.executable, "-s", "-c", CHILD, json.dumps(spec)],
|
||||
cwd=ROOT, env=env, stdin=subprocess.DEVNULL, capture_output=True, text=True,
|
||||
cwd=REPO_ROOT, env=env, stdin=subprocess.DEVNULL, capture_output=True, text=True,
|
||||
check=False)
|
||||
if done.returncode not in codes:
|
||||
raise SampleFailed(f"install.py {' '.join(args)} exited "
|
||||
@@ -473,7 +472,7 @@ _RUNS: dict[tuple, str] = {}
|
||||
|
||||
def _stamp(platform: str) -> tuple[int, int]:
|
||||
return (hash(INSTALLER.read_bytes()),
|
||||
hash((ROOT / "install" / f"{platform}.json").read_bytes()))
|
||||
hash((REPO_ROOT / "install" / f"{platform}.json").read_bytes()))
|
||||
|
||||
|
||||
class _LazySandbox:
|
||||
@@ -529,7 +528,7 @@ def _fenced(lines: list[str]) -> str:
|
||||
|
||||
def list_date(platform: str) -> str:
|
||||
"""The day the committed list was generated, which dates its samples."""
|
||||
manifest = json.loads((ROOT / "install" / f"{platform}.json").read_text(encoding="utf-8"))
|
||||
manifest = json.loads((REPO_ROOT / "install" / f"{platform}.json").read_text(encoding="utf-8"))
|
||||
return manifest["generated"][:10]
|
||||
|
||||
|
||||
|
||||
@@ -13,7 +13,7 @@ from installer_build.port import (
|
||||
BATOCERA_ZIP,
|
||||
MUOS_APP,
|
||||
TOOLS_ZIP,
|
||||
_packs_table,
|
||||
packs_table,
|
||||
archive_members,
|
||||
pinned_installer_sha256,
|
||||
)
|
||||
@@ -35,7 +35,7 @@ def _entry(field: str, name: str, source: Path | None, root: Path) -> dict:
|
||||
"""A member as the list records it: where it comes from, its size and
|
||||
hash, and whether it is executable in the repository."""
|
||||
if source is None:
|
||||
data = _packs_table(root)
|
||||
data = packs_table(root)
|
||||
origin: dict = {"content": data.decode("utf-8")}
|
||||
executable = False
|
||||
else:
|
||||
|
||||
@@ -10,7 +10,6 @@ from core.paths import REPO_ROOT
|
||||
from model.guides import PS1_NAME, SH_NAME
|
||||
|
||||
|
||||
ROOT = REPO_ROOT
|
||||
INSTALLER = "install.py"
|
||||
# Each bootstrap and its one pin line, the value between the two groups.
|
||||
PINS: dict[str, re.Pattern[str]] = {
|
||||
@@ -25,11 +24,11 @@ PIN: dict[str, re.Pattern[str]] = {
|
||||
COMMAND = "python scripts/pin_installer.py"
|
||||
|
||||
|
||||
def installer_sha256(root: Path = ROOT) -> str:
|
||||
def installer_sha256(root: Path = REPO_ROOT) -> str:
|
||||
return hashlib.sha256((root / INSTALLER).read_bytes()).hexdigest()
|
||||
|
||||
|
||||
def stale_pins(root: Path = ROOT) -> list[str]:
|
||||
def stale_pins(root: Path = REPO_ROOT) -> list[str]:
|
||||
"""The bootstraps whose pin is not the SHA-256 of install.py."""
|
||||
digest = installer_sha256(root)
|
||||
stale = []
|
||||
@@ -42,7 +41,7 @@ def stale_pins(root: Path = ROOT) -> list[str]:
|
||||
return stale
|
||||
|
||||
|
||||
def write_pins(root: Path = ROOT) -> list[str]:
|
||||
def write_pins(root: Path = REPO_ROOT) -> list[str]:
|
||||
"""Rewrite each stale pin. Returns the bootstraps written."""
|
||||
digest = installer_sha256(root)
|
||||
written = []
|
||||
|
||||
@@ -112,23 +112,23 @@ def release_pack_labels(root: Path = REPO_ROOT) -> dict[str, str]:
|
||||
from resolve.grouping import group_identical_platforms
|
||||
from model.registry import list_release_pack_platforms
|
||||
from model.platforms import load_platform_config
|
||||
from packs.naming import _name_part, _platform_pack_stem
|
||||
from packs.naming import file_name_part, platform_pack_stem
|
||||
|
||||
platforms_dir = str(root / "platforms")
|
||||
pool = list_release_pack_platforms(platforms_dir)
|
||||
labels: dict[str, str] = {}
|
||||
for group, representative in group_identical_platforms(pool, platforms_dir):
|
||||
stem = _platform_pack_stem(group, representative, platforms_dir)
|
||||
stem = platform_pack_stem(group, representative, platforms_dir)
|
||||
config = load_platform_config(representative, platforms_dir)
|
||||
version = config.get("version", config.get("dat_version", ""))
|
||||
tag = f"_{_name_part(str(version))}" if version else ""
|
||||
tag = f"_{file_name_part(str(version))}" if version else ""
|
||||
label = stem[: -len(tag)] if tag and stem.endswith(tag) else stem
|
||||
for platform in group:
|
||||
labels[platform] = label
|
||||
return dict(sorted(labels.items()))
|
||||
|
||||
|
||||
def _packs_table(root: Path) -> bytes:
|
||||
def packs_table(root: Path) -> bytes:
|
||||
return "".join(f"{platform}\t{label}\n"
|
||||
for platform, label in release_pack_labels(root).items()).encode()
|
||||
|
||||
@@ -144,17 +144,17 @@ def build_archive(name: str, output: Path, root: Path = REPO_ROOT) -> Path:
|
||||
)
|
||||
# The packs' member writer: imported here, as it loads the whole
|
||||
# pack builder, which a caller reading ARCHIVES does not need.
|
||||
from packs.archive import _add_pack_member
|
||||
from packs.archive import add_pack_member
|
||||
|
||||
members = archive_members(name, root)
|
||||
output.parent.mkdir(parents=True, exist_ok=True)
|
||||
scratch = output.with_name(f".{output.name}.tmp")
|
||||
table = output.with_name(f".{output.name}.{PACKS_TABLE}")
|
||||
table.write_bytes(_packs_table(root))
|
||||
table.write_bytes(packs_table(root))
|
||||
try:
|
||||
with zipfile.ZipFile(scratch, "w", zipfile.ZIP_DEFLATED, compresslevel=9) as zf:
|
||||
for member, path in members:
|
||||
_add_pack_member(zf, str(path or table), member)
|
||||
add_pack_member(zf, str(path or table), member)
|
||||
finally:
|
||||
table.unlink()
|
||||
scratch.replace(output)
|
||||
|
||||
@@ -15,9 +15,8 @@ from model.guides import SH_NAME
|
||||
from installer_build.pins import PIN
|
||||
|
||||
|
||||
ROOT = REPO_ROOT
|
||||
PACKAGE_DIR = ROOT / "packaging" / "pypi"
|
||||
DEFAULT_OUTPUT = ROOT / "tmp" / "pypi-dist"
|
||||
PACKAGE_DIR = REPO_ROOT / "packaging" / "pypi"
|
||||
DEFAULT_OUTPUT = REPO_ROOT / "tmp" / "pypi-dist"
|
||||
MODULE = "retrobios"
|
||||
|
||||
# The launcher. runpy runs install.py as __main__, so its own __main__ block
|
||||
@@ -51,7 +50,7 @@ def package_version(stamps: list[int]) -> str:
|
||||
|
||||
def install_py_commits() -> list[int]:
|
||||
"""Commit times of install.py, newest first, from git."""
|
||||
out = subprocess.run(["git", "log", "--format=%ct", "--", "install.py"], cwd=ROOT,
|
||||
out = subprocess.run(["git", "log", "--format=%ct", "--", "install.py"], cwd=REPO_ROOT,
|
||||
capture_output=True, text=True, check=True).stdout
|
||||
return [int(line) for line in out.split()]
|
||||
|
||||
@@ -59,8 +58,8 @@ def install_py_commits() -> list[int]:
|
||||
def installer_bytes() -> bytes:
|
||||
"""install.py, refused unless it is the one install.sh pins: the package
|
||||
then runs the installer the one-line command runs, under the same id."""
|
||||
data = (ROOT / "install.py").read_bytes()
|
||||
pins = PIN[SH_NAME].findall((ROOT / "install.sh").read_text(encoding="utf-8"))
|
||||
data = (REPO_ROOT / "install.py").read_bytes()
|
||||
pins = PIN[SH_NAME].findall((REPO_ROOT / "install.sh").read_text(encoding="utf-8"))
|
||||
if pins != [hashlib.sha256(data).hexdigest()]:
|
||||
raise ValueError("install.py is not the installer install.sh pins: recompute the pin")
|
||||
return data
|
||||
@@ -72,7 +71,7 @@ def stage(folder: Path, version: str) -> None:
|
||||
module.mkdir(parents=True)
|
||||
for name in ("pyproject.toml", "README.md"):
|
||||
shutil.copyfile(PACKAGE_DIR / name, folder / name)
|
||||
shutil.copyfile(ROOT / "LICENSE", folder / "LICENSE")
|
||||
shutil.copyfile(REPO_ROOT / "LICENSE", folder / "LICENSE")
|
||||
shutil.copyfile(PACKAGE_DIR / MODULE / "__main__.py", module / "__main__.py")
|
||||
(module / "__init__.py").write_text(LAUNCHER.format(version=version), encoding="utf-8")
|
||||
(module / "install.py").write_bytes(installer_bytes())
|
||||
@@ -86,7 +85,7 @@ def build(output_dir: Path) -> tuple[Path, Path]:
|
||||
for pattern in ("*.whl", "*.tar.gz"):
|
||||
for old in output_dir.glob(f"{MODULE}-{pattern}"):
|
||||
old.unlink()
|
||||
scratch = ROOT / "tmp"
|
||||
scratch = REPO_ROOT / "tmp"
|
||||
scratch.mkdir(exist_ok=True)
|
||||
with tempfile.TemporaryDirectory(prefix="pypi-stage-", dir=scratch) as name:
|
||||
folder = Path(name) / "retrobios"
|
||||
|
||||
Reference in new issue
Block a user