refactor: make writable an instance method

This commit is contained in:
Abdessamad Derraz committed 2026-11-17 09:48:13 +01:00
1 parent bc50106587
commit 81a94fc267
7 files changed
+31 -15

No files matched your search

+2 -3
View File
@@ -167,8 +167,7 @@ class BaseExporter(ABC, Generic[Content]):
list carries."""
return False
@classmethod
def writable(cls, fe: NativeFile, require: str = "") -> bool:
def writable(self, fe: NativeFile, require: str = "") -> bool:
"""Whether this format can carry the entry.
An entry the platform already declares is always carried, hash or
@@ -176,7 +175,7 @@ class BaseExporter(ABC, Generic[Content]):
hands back a file poorer than the one it corrects. The requirement
only gates what we would be adding.
"""
return cls._carried(fe, require, cls.SINGLE_HASH_FIELD)
return self._carried(fe, require, self.SINGLE_HASH_FIELD)
@classmethod
def _carried(cls, fe: NativeFile, require: str, single: str | None) -> bool:
+3 -1
View File
@@ -135,7 +135,9 @@ class Exporter(BaseExporter[str]):
if system.native_id != system_id:
continue
for fe in system.files:
if not cls.writable(fe):
# The base writable rule, which EmuDeck keeps: it needs no
# render state, so the class answers it.
if not cls._carried(fe, "", cls.SINGLE_HASH_FIELD):
continue
for value in cls._entry_md5s(fe):
if _MD5.match(value) and value not in seen:
+1 -2
View File
@@ -318,8 +318,7 @@ class Exporter(BaseExporter[str]):
for label in sorted(getattr(self, "_held_whole", {}).values())
]
@classmethod
def writable(cls, fe: NativeFile, require: str = "") -> bool:
def writable(self, fe: NativeFile, require: str = "") -> bool:
"""es_bios.xsd makes md5 and core required: without them, no element.
An entry Recalbox already ships has both, so this only ever gates
+1 -2
View File
@@ -83,8 +83,7 @@ class Exporter(BaseExporter[str]):
# one from BIOS data alone would throw the component away.
return True
@classmethod
def writable(cls, fe: NativeFile, require: str = "") -> bool:
def writable(self, fe: NativeFile, require: str = "") -> bool:
"""An addition lands only in a manifest it can be placed in."""
if fe.platform is None and not fe.native("component", ""):
return False
+1 -2
View File
@@ -114,8 +114,7 @@ class Exporter(BaseExporter[str]):
def native_sources() -> dict[str, str]:
return {"System.dat": SOURCE_URL}
@classmethod
def writable(cls, fe: NativeFile, require: str = "") -> bool:
def writable(self, fe: NativeFile, require: str = "") -> bool:
"""A clrmamepro rom line is a hash record, and the DAT has no other.
The original never states a rom it cannot hash, so neither do we.
+3 -3
View File
@@ -145,7 +145,7 @@ class RetroDeckWritesWhatItCounts(unittest.TestCase):
written = json.loads(produced["duckstation/component_manifest.json"])
names = [e["filename"] for e in written["duckstation"]["bios"]]
self.assertIn("b.bin", names)
self.assertFalse(RetroDeck.writable(spread.files[2]))
self.assertFalse(RetroDeck().writable(spread.files[2]))
class HashesTheFormatCannotHold(unittest.TestCase):
@@ -434,8 +434,8 @@ class OneMd5FormatsAddWhole(unittest.TestCase):
several = NativeFile("boot.bin", "boot.bin", "dc", truth={"md5": [A, B, C]})
single = NativeFile("boot2.bin", "boot2.bin", "dc", truth={"md5": A})
self.assertFalse(RetroBat.writable(several))
self.assertTrue(RetroBat.writable(single))
self.assertFalse(RetroBat().writable(several))
self.assertTrue(RetroBat().writable(single))
class BizHawkKeepsItsOwnHashes(unittest.TestCase):
+20 -2
View File
@@ -558,7 +558,7 @@ class Reconciliation(unittest.TestCase):
}
systems, _ = build_native_model({"systems": {}}, scraped)
entry = systems["nds"].files[0]
self.assertTrue(BaseExporter.writable(entry, require="md5"))
self.assertTrue(_BaseRule().writable(entry, require="md5"))
def test_no_format_drops_what_the_platform_already_declares(self):
"""An export poorer than the file it corrects is not usable."""
@@ -579,7 +579,25 @@ class Reconciliation(unittest.TestCase):
}
systems, _ = build_native_model(truth, None)
entry = systems["nintendo-ds"].files[0]
self.assertFalse(BaseExporter.writable(entry, require="md5"))
self.assertFalse(_BaseRule().writable(entry, require="md5"))
class _BaseRule(BaseExporter):
"""A concrete exporter that keeps every rule of the base class."""
@staticmethod
def platform_name() -> str:
return "base"
@staticmethod
def native_filename() -> str:
return "base"
def render(self, systems, report, originals, scraped=None):
return {}
def validate(self, systems, produced):
return []
class ExporterRegistry(unittest.TestCase):