From 18e91f8c07b20a10d88f356d0f16e1eb95cb77a2 Mon Sep 17 00:00:00 2001 From: Abdessamad Derraz <3028866+Abdess@users.noreply.github.com> Date: Wed, 18 Nov 2026 12:32:40 +0100 Subject: [PATCH] refactor: read the repo root from core.paths --- scripts/cross_reference.py | 3 ++- scripts/generate_pack.py | 10 +++++----- scripts/packresolve.py | 4 ++-- scripts/packverify.py | 2 +- scripts/validate_pr.py | 3 ++- scripts/verify.py | 5 ++--- tests/test_layers.py | 2 +- 7 files changed, 15 insertions(+), 14 deletions(-) diff --git a/scripts/cross_reference.py b/scripts/cross_reference.py index ea4702f46..7158772c5 100644 --- a/scripts/cross_reference.py +++ b/scripts/cross_reference.py @@ -41,6 +41,7 @@ from model.declarations import merged_platform_declared_contents from model.platforms import load_platform_config from resolve.content import content_fits, name_match_size_ok from core.hashing import parse_md5_list +from core.paths import REPO_ROOT from model.safeparse import require_yaml from resolve.localfile import resolve_local_file from resolve.standalone import platform_layouts, standalone_set @@ -465,7 +466,7 @@ class FileConsumers: self._data_dir_registry = ( data_dir_registry if data_dir_registry is not None else load_data_dir_registry( - str(Path(__file__).resolve().parent.parent / DEFAULT_PLATFORMS_DIR) + str(REPO_ROOT / DEFAULT_PLATFORMS_DIR) ) ) self._sha1_by_path = { diff --git a/scripts/generate_pack.py b/scripts/generate_pack.py index d8aab72b4..6499fc094 100644 --- a/scripts/generate_pack.py +++ b/scripts/generate_pack.py @@ -108,7 +108,7 @@ from model.platforms import load_platform_config from model.safeparse import require_yaml, yaml_load from model.declarations import declared_root from resolve.standalone import platform_layouts, standalone_set -from core.paths import sanitize_pack_path +from core.paths import REPO_ROOT, sanitize_pack_path import packresolve from refresh_data_dirs import cache_lock, hold_data_dirs from model import region @@ -2424,7 +2424,7 @@ def generate_emulator_pack( os.makedirs(output_dir, exist_ok=True) data_registry = load_data_dir_registry( - options.get("platforms_dir") or os.path.join(os.path.dirname(__file__), "..", "platforms") + options.get("platforms_dir") or str(REPO_ROOT / "platforms") ) region_drops: set[str] = ( emulator_region_drops( @@ -4402,7 +4402,7 @@ def _run_platform_mode( def _main(held: contextlib.ExitStack) -> None: parser = _build_parser() args = parser.parse_args() - from verify import work_from_repo_root + from model.cliargs import work_from_repo_root work_from_repo_root( args, parser, @@ -5940,7 +5940,7 @@ def _start_manifest( build = _ManifestBuild( platform_name, platforms_dir, db, bios_dir, opts, config, emu_profiles, zip_contents, data_registry, game_entries, plat_registry.get("install", {}), - os.path.dirname(os.path.dirname(os.path.abspath(__file__))), pack_systems, + str(REPO_ROOT), pack_systems, ) build.manifest_profiles = { name: emu_profiles[name] @@ -6213,7 +6213,7 @@ def _standalone_layouts( that entry. Another is written whole. A data tree member is left to the list's data directories. """ - repo_root = os.path.dirname(os.path.dirname(os.path.abspath(__file__))) + repo_root = str(REPO_ROOT) known = { copy["sha1"] for entry in [*result["files"], *result.get("truth_files", [])] diff --git a/scripts/packresolve.py b/scripts/packresolve.py index 493b60b55..a7950a4ea 100644 --- a/scripts/packresolve.py +++ b/scripts/packresolve.py @@ -17,7 +17,7 @@ from model.largefiles import fetch_large_file from core.hashing import cut_md5_owner from resolve.content import declared_hash_verdict from resolve.localfile import resolution_is_hash_exact, resolve_local_file -from core.paths import sanitize_pack_path +from core.paths import REPO_ROOT, sanitize_pack_path from resolve.validation import inner_rom_check # CLI-wide network policy. Public helpers can override it explicitly, while # every CLI mode inherits --offline (including large-file release fallback). @@ -32,7 +32,7 @@ def set_offline(value: bool) -> None: def scratch_dir() -> str: """The repository's tmp/, never the system /tmp (a 4 GB tmpfs on WSL).""" - path = Path(__file__).resolve().parent.parent / "tmp" + path = REPO_ROOT / "tmp" path.mkdir(exist_ok=True) return str(path) diff --git a/scripts/packverify.py b/scripts/packverify.py index 4f7fd893f..d5c4398d8 100644 --- a/scripts/packverify.py +++ b/scripts/packverify.py @@ -10,7 +10,7 @@ from collections import Counter from dataclasses import dataclass, field from typing import TYPE_CHECKING, TypedDict -from auto_fetch import DEFAULT_BIOS_DIR +from verify import DEFAULT_BIOS_DIR from core.artifacts import _build_timestamp from packpaths import MEDIA_MARKER, _has_path_conflict from core.ziptools import build_zip_contents_index diff --git a/scripts/validate_pr.py b/scripts/validate_pr.py index 9d4dc881e..e2002f24e 100644 --- a/scripts/validate_pr.py +++ b/scripts/validate_pr.py @@ -1149,7 +1149,8 @@ def main() -> None: # root. Run from elsewhere, every file read as referenced by no platform # and placed outside bios/. The files named are read from where they # were typed. - from verify import REPO_ROOT, work_from_repo_root + from core.paths import REPO_ROOT + from model.cliargs import work_from_repo_root if os.path.realpath(os.getcwd()) != os.path.realpath(REPO_ROOT): args.files = [os.path.abspath(f) for f in args.files] diff --git a/scripts/verify.py b/scripts/verify.py index 7529844cd..4cf96cd44 100644 --- a/scripts/verify.py +++ b/scripts/verify.py @@ -95,7 +95,7 @@ from resolve.cores import ( from model.safeparse import require_yaml from resolve.localfile import resolve_local_file from resolve.standalone import platform_layouts, standalone_set as platform_standalone_set -from core.paths import sanitize_pack_path +from core.paths import REPO_ROOT, sanitize_pack_path from resolve.categories import BIOS, EntryCategories from resolve.launchers import LauncherLayer, declared_destinations, held_record, launcher_unproven @@ -143,9 +143,8 @@ DEFAULT_PLATFORMS_DIR = "platforms" DEFAULT_BIOS_DIR = "bios" # The repository's platforms wherever the script runs from, for library calls # that pass no directory. -_REPO_PLATFORMS = os.path.join(os.path.dirname(__file__), "..", "platforms") +_REPO_PLATFORMS = str(REPO_ROOT / "platforms") DEFAULT_EMULATORS_DIR = "emulators" -REPO_ROOT = os.path.dirname(os.path.dirname(os.path.abspath(__file__))) # Status model: aligned with Batocera BiosStatus (batocera-systems:967-969) diff --git a/tests/test_layers.py b/tests/test_layers.py index 42ff824fc..11f6cda26 100644 --- a/tests/test_layers.py +++ b/tests/test_layers.py @@ -32,7 +32,7 @@ SIBLING_IMPORTS: dict[str, frozenset[str]] = { # Top-level modules other modules of scripts/ import: library code that a # later wave moves into a package. NOT_YET_PACKAGED = frozenset({ - "archive_build", "auto_fetch", "autorun", "build_port", "campaign", "campaign_profiles", + "archive_build", "autorun", "build_port", "campaign", "campaign_profiles", "campaign_rules", "check_buildbot_system", "check_release_assets", "commit_rules", "core_probe", "cross_reference", "dedup", "derivations", "generate_event_schema", "generate_pack", "generate_readme", "generate_site", "manifestselect", "measurement_records",