From 13f92eaf4a0415dbef11742aeaafa5ecf1dc4807 Mon Sep 17 00:00:00 2001 From: Abdessamad Derraz <3028866+Abdess@users.noreply.github.com> Date: Mon, 23 Nov 2026 22:07:47 +0100 Subject: [PATCH] refactor: move fixed_paths to shell_launchers --- scripts/scraper/emuelec_launchers.py | 2 +- scripts/scraper/rocknix_launchers.py | 28 ++-------------------------- scripts/scraper/shell_launchers.py | 27 +++++++++++++++++++++++++++ 3 files changed, 30 insertions(+), 27 deletions(-) diff --git a/scripts/scraper/emuelec_launchers.py b/scripts/scraper/emuelec_launchers.py index fb4efd72f..2f1d71118 100644 --- a/scripts/scraper/emuelec_launchers.py +++ b/scripts/scraper/emuelec_launchers.py @@ -19,11 +19,11 @@ from dataclasses import dataclass, field from model.launcherrecords import join_emulators from .configgen_launchers import Launcher -from .rocknix_launchers import fixed_paths from scraper.shell_launchers import ( config_placement, describe_keys, apply_evidence, + fixed_paths, first_boot_placement, LauncherPatternMissing, Link, diff --git a/scripts/scraper/rocknix_launchers.py b/scripts/scraper/rocknix_launchers.py index 4e380454d..80d0aed87 100644 --- a/scripts/scraper/rocknix_launchers.py +++ b/scripts/scraper/rocknix_launchers.py @@ -26,6 +26,8 @@ from scraper.shell_launchers import ( link_record, RepoTree, Script, + FixedPaths, + fixed_paths, Setting, settings, source_ref, @@ -142,32 +144,6 @@ def _file_under(value: str, root: str) -> bool: return value.startswith(root.rstrip("/") + "/") -@dataclass(frozen=True) -class FixedPaths: - """Keys of a config that name a file under one directory.""" - - keys: tuple[tuple[str, str], ...] - names: tuple[str, ...] - search_dir: str - - -def fixed_paths( - found: list[Setting], keys: list[tuple[str, str]], path: str -) -> tuple[FixedPaths, set[int]]: - """The values of keys, as names relative to the directory they share.""" - by_key = {(s.section, s.key): s for s in found} - missing = [k for k in keys if k not in by_key] - if missing: - raise LauncherPatternMissing(path, f"key {missing[0][1]}") - values = [by_key[k].value for k in keys if by_key[k].value] - lines = {by_key[k].line for k in keys} - if not values: - return FixedPaths(tuple(keys), (), ""), lines - folder = posixpath.commonpath([posixpath.dirname(v) for v in values]) - names = tuple(posixpath.relpath(v, folder) for v in values) - return FixedPaths(tuple(keys), names, folder), lines - - def bios_keys(tree: RepoTree, paths: list[str], root: str = BIOS_ROOT) -> list[tuple[str, str]]: """Keys whose value is a file under root in at least one of the configs.""" keys: list[tuple[str, str]] = [] diff --git a/scripts/scraper/shell_launchers.py b/scripts/scraper/shell_launchers.py index f76565e50..23edd72b4 100644 --- a/scripts/scraper/shell_launchers.py +++ b/scripts/scraper/shell_launchers.py @@ -10,6 +10,7 @@ gone, so a rewrite upstream stops the scrape instead of publishing nothing. from __future__ import annotations +import posixpath import re from collections.abc import Callable, Iterable from dataclasses import dataclass, field @@ -667,6 +668,32 @@ def settings(text: str, separator: str = "=") -> list[Setting]: return found +@dataclass(frozen=True) +class FixedPaths: + """Keys of a config that name a file under one directory.""" + + keys: tuple[tuple[str, str], ...] + names: tuple[str, ...] + search_dir: str + + +def fixed_paths( + found: list[Setting], keys: list[tuple[str, str]], path: str +) -> tuple[FixedPaths, set[int]]: + """The values of keys, as names relative to the directory they share.""" + by_key = {(s.section, s.key): s for s in found} + missing = [k for k in keys if k not in by_key] + if missing: + raise LauncherPatternMissing(path, f"key {missing[0][1]}") + values = [by_key[k].value for k in keys if by_key[k].value] + lines = {by_key[k].line for k in keys} + if not values: + return FixedPaths(tuple(keys), (), ""), lines + folder = posixpath.commonpath([posixpath.dirname(v) for v in values]) + names = tuple(posixpath.relpath(v, folder) for v in values) + return FixedPaths(tuple(keys), names, folder), lines + + def describe_keys(file: str, keys: tuple[tuple[str, str], ...]) -> str: """file [section] key, key [other] key, sections named where they change.""" described, section = file, None