From cf7e13808fa40cffe09f650da0162e1c29040575 Mon Sep 17 00:00:00 2001 From: Abdessamad Derraz <3028866+Abdess@users.noreply.github.com> Date: Sat, 21 Nov 2026 17:23:54 +0100 Subject: [PATCH] refactor: one predicate for the pack notes --- scripts/orchestrate/compare.py | 9 --------- scripts/orchestrate/consistency.py | 3 ++- scripts/orchestrate/narrowed.py | 5 +++-- scripts/orchestrate/splitcheck.py | 7 ++++--- scripts/packs/archive.py | 16 +++++++++++++++- scripts/packs/integrity.py | 19 ++++--------------- tests/test_install_selection.py | 3 ++- 7 files changed, 30 insertions(+), 32 deletions(-) diff --git a/scripts/orchestrate/compare.py b/scripts/orchestrate/compare.py index 7accb6f96..976457320 100644 --- a/scripts/orchestrate/compare.py +++ b/scripts/orchestrate/compare.py @@ -3,18 +3,9 @@ from __future__ import annotations import os -import re from core.paths import EMULATORS_DIR from model.registry import load_data_dir_registry -from packs.paths import MEDIA_MARKER - -# Members the builder writes for the reader or the device rather than for a -# core: the documents, and the empty marker an Android pack carries. -PACK_NOTES = re.compile( - r"(^README\.txt$|^manifest\.json$|(^|/)(INSTRUCTIONS|RENAMED)_[^/]*\.txt$" - rf"|(^|/){re.escape(MEDIA_MARKER)}$)" -) def tree_members( diff --git a/scripts/orchestrate/consistency.py b/scripts/orchestrate/consistency.py index 4dc6626ce..96ecb5e23 100644 --- a/scripts/orchestrate/consistency.py +++ b/scripts/orchestrate/consistency.py @@ -6,6 +6,7 @@ from pathlib import Path from core.paths import PLATFORMS_DIR from orchestrate import compare +from packs.archive import is_pack_note from orchestrate.labels import STEP_LABELS, step_title from orchestrate.reports import ( match_key, @@ -138,7 +139,7 @@ def check_pack_destinations( written = { info.filename for info in zf.infolist() if not info.is_dir() - and not compare.PACK_NOTES.search(info.filename) + and not is_pack_note(info.filename) and not ( trees.get(info.filename) == info.file_size and info.filename not in credited diff --git a/scripts/orchestrate/narrowed.py b/scripts/orchestrate/narrowed.py index 8cf9d79f2..7083e87ae 100644 --- a/scripts/orchestrate/narrowed.py +++ b/scripts/orchestrate/narrowed.py @@ -6,8 +6,9 @@ import contextlib import io from core.paths import DB_FILE, EMULATORS_DIR, PLATFORMS_DIR -from orchestrate.compare import PACK_NOTES, comparison_inputs, set_difference_lines +from orchestrate.compare import comparison_inputs, set_difference_lines from orchestrate.labels import STEP_LABELS, step_title +from packs.archive import is_pack_note # How each pack_narrowings() dimension of a platform pack is compared by # check_narrowed_packs, or why it is not. A test reads the builder's @@ -142,7 +143,7 @@ def check_narrowed_packs( trees = set(record.trees) - credited written = { m for m in record.members - if not PACK_NOTES.search(m) and m not in trees + if not is_pack_note(m) and m not in trees } lines = set_difference_lines(name, credited, written) if lines: diff --git a/scripts/orchestrate/splitcheck.py b/scripts/orchestrate/splitcheck.py index af0170275..b5624cf4c 100644 --- a/scripts/orchestrate/splitcheck.py +++ b/scripts/orchestrate/splitcheck.py @@ -8,8 +8,9 @@ from collections.abc import Callable from typing import TYPE_CHECKING from core.paths import DB_FILE, EMULATORS_DIR, PLATFORMS_DIR -from orchestrate.compare import PACK_NOTES, comparison_inputs +from orchestrate.compare import comparison_inputs from orchestrate.labels import STEP_LABELS, step_title +from packs.archive import is_pack_note if TYPE_CHECKING: from packs.archive import PackRecord @@ -23,10 +24,10 @@ def split_differences( A path in a part and not in the full pack, a path of the full pack in no part, and a path a part fills with other bytes than the full pack. """ - full_members = {m for m in full.members if not PACK_NOTES.search(m)} + full_members = {m for m in full.members if not is_pack_note(m)} union = { m for record in parts.values() for m in record.members - if not PACK_NOTES.search(m) + if not is_pack_note(m) } lines = [f"in a part, not in the full pack: {m}" for m in sorted(union - full_members)] lines += [f"in the full pack, in no part: {m}" for m in sorted(full_members - union)] diff --git a/scripts/packs/archive.py b/scripts/packs/archive.py index 3d4c5a441..a2fddd24c 100644 --- a/scripts/packs/archive.py +++ b/scripts/packs/archive.py @@ -12,7 +12,7 @@ from dataclasses import dataclass, field from core.artifacts import atomic_scratch from core.hashing import compute_hashes from core.paths import comparable_destination, sanitize_pack_path -from packs.paths import has_path_conflict, register_path, placement_block +from packs.paths import MEDIA_MARKER, has_path_conflict, register_path, placement_block # The minimum ZIP timestamp, carried by every pack member so a pack is a @@ -127,6 +127,20 @@ def writing_pack(zip_path: str) -> Iterator[zipfile.ZipFile]: PACK_DOCUMENTS = ("README.txt", "manifest.json") +def is_pack_note(name: str) -> bool: + """Whether a member is a note the builder composes, not a collected file.""" + # The builder writes its notes beside the slot they explain + # (bios/INSTRUCTIONS_x.txt, games/keen6/INSTRUCTIONS_y.txt), so + # they are told by their own name, not by a root prefix. The empty + # marker an Android pack carries is written for the device. + base = name.rsplit("/", 1)[-1] + return ( + base.startswith(("INSTRUCTIONS_", "RENAMED_")) + or base == MEDIA_MARKER + or name in PACK_DOCUMENTS + ) + + @dataclass class Placed: """The destinations a build has taken, and the folders they open. diff --git a/scripts/packs/integrity.py b/scripts/packs/integrity.py index ae5d0733e..d86b42da0 100644 --- a/scripts/packs/integrity.py +++ b/scripts/packs/integrity.py @@ -11,6 +11,7 @@ from dataclasses import dataclass, field from typing import TYPE_CHECKING, TypedDict from core.artifacts import build_timestamp +from packs.archive import PACK_DOCUMENTS, is_pack_note from packs.paths import MEDIA_MARKER, has_path_conflict from core.ziptools import build_zip_contents_index, is_archive_path, zip_members from core.ziptools import safe_member_parts @@ -141,18 +142,6 @@ def _data_indexes(data_registry: dict | None) -> tuple[dict[str, list[str]], dic return _data_index, _data_path_index -def _is_pack_note(name: str) -> bool: - """Whether a member is a note the builder composes, not a collected file.""" - # The builder writes its notes beside the slot they explain - # (bios/INSTRUCTIONS_x.txt, games/keen6/INSTRUCTIONS_y.txt), so - # they are told by their own name, not by a root prefix. - base = name.rsplit("/", 1)[-1] - return base.startswith(("INSTRUCTIONS_", "RENAMED_")) or base == MEDIA_MARKER or name in ( - "manifest.json", - "README.txt", - ) - - def _member_digests(zf: zipfile.ZipFile, info: zipfile.ZipInfo) -> tuple[str, str, int]: """(sha1, md5, size) of a pack member.""" with zf.open(info) as f: @@ -241,7 +230,7 @@ def verify_pack( with zipfile.ZipFile(zip_path, "r") as zf: for info in zf.infolist(): - if info.is_dir() or _is_pack_note(info.filename): + if info.is_dir() or is_pack_note(info.filename): continue name = info.filename sha1, md5, size = _member_digests(zf, info) @@ -512,7 +501,7 @@ def _structural_errors(zf: zipfile.ZipFile, zip_set: set) -> list[str]: for info in zf.infolist() if info.file_size == 0 and not info.is_dir() and "GraphicMods" not in info.filename - and info.filename not in ("manifest.json", "README.txt") + and info.filename not in PACK_DOCUMENTS and info.filename.rsplit("/", 1)[-1] != MEDIA_MARKER ) @@ -748,7 +737,7 @@ def _pack_view(zf: zipfile.ZipFile, config: dict, base_dest: str) -> _PackView: is_flat = bool(base_dest) and not any( n.startswith(base_dest + "/") for n in zip_set - if n not in ("README.txt", "manifest.json", MEDIA_MARKER) and not n.endswith("/") + if n not in (*PACK_DOCUMENTS, MEDIA_MARKER) and not n.endswith("/") ) # Mirror the builder's path-conflict logic: a declaration whose path # collides file-vs-directory with a packed member was skipped by the diff --git a/tests/test_install_selection.py b/tests/test_install_selection.py index 3aba493aa..0b4025ca9 100644 --- a/tests/test_install_selection.py +++ b/tests/test_install_selection.py @@ -1464,6 +1464,7 @@ class ANativeNameSelectsOneSetEverywhere(unittest.TestCase): def test_pack_verify_and_installer_agree(self): from model.platforms import load_platform_config from model.systems import resolve_system_arg + from packs.archive import is_pack_note for platform, native, system_id in self.CASES: with self.subTest(platform=platform, name=native): @@ -1483,7 +1484,7 @@ class ANativeNameSelectsOneSetEverywhere(unittest.TestCase): members = self._packed(platform, chosen) written = { name for name, size in members.items() - if not self.compare.PACK_NOTES.search(name) + if not is_pack_note(name) and not (trees.get(name) == size and name not in credited) } self.assertTrue(written)