From c6cac0ad1b6937aa6a6068678b12ffd8f55e2f79 Mon Sep 17 00:00:00 2001 From: Abdessamad Derraz <3028866+Abdess@users.noreply.github.com> Date: Fri, 16 Oct 2026 15:57:43 +0200 Subject: [PATCH] fix: read exportable through the exporter instance --- scripts/exporter/base_exporter.py | 8 ++++---- scripts/exporter/romm_exporter.py | 6 ++++++ tests/test_export_counts.py | 12 ++++++++++++ 3 files changed, 22 insertions(+), 4 deletions(-) diff --git a/scripts/exporter/base_exporter.py b/scripts/exporter/base_exporter.py index 7f160d3b..c0fd4fc4 100644 --- a/scripts/exporter/base_exporter.py +++ b/scripts/exporter/base_exporter.py @@ -81,9 +81,8 @@ class BaseExporter(ABC): # Shared helpers - @classmethod def exportable( - cls, + self, systems: dict[str, NativeSystem], require: str = "", ) -> list[tuple[NativeSystem, list[NativeFile]]]: @@ -92,11 +91,12 @@ class BaseExporter(ABC): `require` names a hash the format cannot omit. An entry the format has no way to express is dropped here and counted by the caller, never written as a half entry the platform would read as a file that - can never verify. + can never verify. Read through the instance: RomM decides on the + keys its render has seen. """ result: list[tuple[NativeSystem, list[NativeFile]]] = [] for system in systems.values(): - files = [fe for fe in system.files if fe.name and cls.writable(fe, require)] + files = [fe for fe in system.files if fe.name and self.writable(fe, require)] if files: result.append((system, files)) return result diff --git a/scripts/exporter/romm_exporter.py b/scripts/exporter/romm_exporter.py index c1b2f9a0..0cac671f 100644 --- a/scripts/exporter/romm_exporter.py +++ b/scripts/exporter/romm_exporter.py @@ -52,6 +52,12 @@ class Exporter(BaseExporter): def native_sources() -> dict[str, str]: return {"known_bios_files.json": SOURCE_URL} + def __init__(self) -> None: + super().__init__() + # Filled by render; empty until then, so writable() answers before it. + self._platform_keys: set[tuple[str, str]] = set() + self._first_addition: dict[tuple[str, str], int] = {} + @staticmethod def _verifiable(fe: NativeFile) -> bool: return bool(fe.size()) and any( diff --git a/tests/test_export_counts.py b/tests/test_export_counts.py index d23498fd..f35e4726 100644 --- a/tests/test_export_counts.py +++ b/tests/test_export_counts.py @@ -425,6 +425,18 @@ class RommKeepsItsOwnKeys(unittest.TestCase): self.assertEqual(written["dc:boot.bin"]["size"], "2097152") self.assertFalse(exporter.writable(ours)) + def test_the_shared_helper_reads_every_exporter_the_same_way(self): + """RomM's writable is per instance; the base helper bound fe as self.""" + from exporter import discover_exporters # noqa: PLC0415 + + theirs = NativeFile("boot.bin", "dc/boot.bin", "dc", + platform={"size": 2097152, "md5": A, "core": "libretro/flycast"}) + systems = {"dc": NativeSystem("dc", files=[theirs], from_platform=True)} + for name, cls in sorted(discover_exporters().items()): + with self.subTest(exporter=name): + pairs = cls().exportable(systems) + self.assertEqual([fe for _, files in pairs for fe in files], [theirs]) + class NamesInAnotherDirectory(unittest.TestCase): def test_a_truth_path_in_another_directory_does_not_match(self): scraped = {"systems": {"pc98": {"files": [