refactor: split common.py into three packages

core: cli (run_cli, input errors, name hints), github (token), paths.
model: sources, database, composition, registry, platforms,
declarations, targets, systems, profiles, cliargs. resolve: content,
ownership, datadirs, archives, localfile, directories, layout,
contentlayout, standalone, grouping, cores.

Definitions move verbatim; common.py and its re-exports are gone and
every importer, patch target and code-in-string names the new home. A
test that stubbed common.load_platform_config stubs each module that
reads the loader by its own name.
This commit is contained in:
Abdessamad Derraz committed 2026-11-18 11:09:13 +01:00
1 parent c784aef883
commit 83cfa6fd0f
281 files changed
+7036 -6794

No files matched your search

+41 -30
View File
@@ -25,7 +25,14 @@ from pathlib import Path
import yaml
import common
from model import cliargs, platforms
from resolve import cores, grouping, localfile
from model.database import load_database
from model.platforms import _platform_config_cache
from model.profiles import _emulator_profiles_cache, load_emulator_profiles
from model.registry import list_registered_platforms, load_data_dir_registry
from resolve.localfile import resolve_local_file
from resolve.ownership import BUCKET_FOLDERS, names_manufacturer
import generate_db
import generate_pack as builder
import generate_site
@@ -95,15 +102,15 @@ class _Collection(unittest.TestCase):
"--bios-dir", "bios", "--output", "database.json"],
check=True, capture_output=True,
)
self.db = common.load_database("database.json")
common._platform_config_cache.clear()
common._emulator_profiles_cache.clear()
self.config = common.load_platform_config("handheld", "platforms")
self.profiles = common.load_emulator_profiles("emulators")
self.db = load_database("database.json")
_platform_config_cache.clear()
_emulator_profiles_cache.clear()
self.config = platforms.load_platform_config("handheld", "platforms")
self.profiles = load_emulator_profiles("emulators")
def tearDown(self):
common._platform_config_cache.clear()
common._emulator_profiles_cache.clear()
_platform_config_cache.clear()
_emulator_profiles_cache.clear()
os.chdir(self._cwd)
self._tmp.cleanup()
@@ -138,33 +145,33 @@ class DiskRomGoesToThePc88File(_Collection):
def test_resolution(self):
entry = self._entry("nec-pc-88")
path, status = common.resolve_local_file(
path, status = resolve_local_file(
entry, self.db, dest_hint=entry["destination"]
)
self.assertEqual((path, status), ("bios/NEC/PC-88/n88sub.rom", "name_exact"))
def test_the_msx_system_keeps_the_msx_file(self):
entry = self._entry("microsoft-msx")
path, _status = common.resolve_local_file(
path, _status = resolve_local_file(
entry, self.db, dest_hint=entry["destination"]
)
self.assertEqual(path, "bios/Microsoft/MSX/DISK.ROM")
def test_a_declared_hash_still_decides(self):
entry = {**self._entry("nec-pc-88"), "md5": hashlib.md5(MSX_DISK).hexdigest()}
path, status = common.resolve_local_file(entry, self.db)
path, status = resolve_local_file(entry, self.db)
self.assertEqual((path, status), ("bios/Microsoft/MSX/DISK.ROM", "md5_exact"))
def test_an_emulator_entry_is_not_narrowed(self):
entry = {**self._entry("nec-pc-88"), "source_profile": "msx-emu"}
path, _status = common.resolve_local_file(entry, self.db)
path, _status = resolve_local_file(entry, self.db)
self.assertEqual(path, "bios/Microsoft/MSX/DISK.ROM")
def test_no_pc88_copy_leaves_it_missing_not_mismatched(self):
Path("bios/NEC/PC-88/n88sub.rom").unlink()
entry = self._entry("nec-pc-88")
self.assertEqual(
common.resolve_local_file(entry, self.db, dest_hint=entry["destination"]),
resolve_local_file(entry, self.db, dest_hint=entry["destination"]),
(None, "not_found"),
)
@@ -189,7 +196,9 @@ class DiskRomGoesToThePc88File(_Collection):
def test_the_manifest_changes_only_that_row(self):
manifest = self._manifest()
original = (common.load_platform_config, common.system_makers)
original = (platforms.load_platform_config, localfile.system_makers)
# Every module that reads the loader by its own name sees the stub.
readers = (builder, platforms, cliargs, cores, grouping)
def untagged(*args, **kwargs):
config = original[0](*args, **kwargs)
@@ -198,15 +207,17 @@ class DiskRomGoesToThePc88File(_Collection):
f.pop("platform_system", None)
return config
common._platform_config_cache.clear()
builder.load_platform_config = common.load_platform_config = untagged
common.system_makers = lambda *args: frozenset()
_platform_config_cache.clear()
for module in readers:
module.load_platform_config = untagged
localfile.system_makers = lambda *args: frozenset()
try:
before = self._manifest()
finally:
builder.load_platform_config = common.load_platform_config = original[0]
common.system_makers = original[1]
common._platform_config_cache.clear()
for module in readers:
module.load_platform_config = original[0]
localfile.system_makers = original[1]
_platform_config_cache.clear()
rows = {f["dest"]: f for f in manifest["files"]}
old_rows = {f["dest"]: f for f in before["files"]}
self.assertEqual(rows["bios/quasi88/DISK.ROM"]["size"], len(PC88_DISK))
@@ -225,8 +236,8 @@ class DiskRomGoesToThePc88File(_Collection):
class SiteSharesTheMakerTest(unittest.TestCase):
def test_one_copy(self):
self.assertIs(generate_site.names_manufacturer, common.names_manufacturer)
self.assertIs(generate_site.BUCKET_FOLDERS, common.BUCKET_FOLDERS)
self.assertIs(generate_site.names_manufacturer, names_manufacturer)
self.assertIs(generate_site.BUCKET_FOLDERS, BUCKET_FOLDERS)
class NoHashlessNameMatchCrossesMakers(unittest.TestCase):
@@ -238,24 +249,24 @@ class NoHashlessNameMatchCrossesMakers(unittest.TestCase):
db_path = REPO_ROOT / "database.json"
if not db_path.exists():
self.skipTest("database.json not built")
db = common.load_database(str(db_path))
registry = common.load_data_dir_registry("platforms")
db = load_database(str(db_path))
registry = load_data_dir_registry("platforms")
folders = {
parts[1]
for entry in db["files"].values()
if len(parts := entry["path"].split("/")) >= 3 and parts[0] == "bios"
} - common.BUCKET_FOLDERS
} - BUCKET_FOLDERS
crossings = []
for platform in common.list_registered_platforms("platforms"):
config = common.load_platform_config(platform, "platforms")
for platform in list_registered_platforms("platforms"):
config = platforms.load_platform_config(platform, "platforms")
for sys_id, system in config.get("systems", {}).items():
makers = {f for f in folders if common.names_manufacturer(sys_id, f)}
makers = {f for f in folders if names_manufacturer(sys_id, f)}
if not makers:
continue
for entry in system.get("files") or []:
if any(entry.get(k) for k in ("sha1", "md5", "sha256", "crc32")):
continue
path, status = common.resolve_local_file(
path, status = resolve_local_file(
entry, db, dest_hint=entry.get("destination", ""),
data_dir_registry=registry,
)
@@ -264,7 +275,7 @@ class NoHashlessNameMatchCrossesMakers(unittest.TestCase):
status.startswith("name")
and len(parts) >= 3
and parts[0] == "bios"
and parts[1] not in common.BUCKET_FOLDERS
and parts[1] not in BUCKET_FOLDERS
and parts[1] not in makers
):
crossings.append(f"{platform} {sys_id} {entry.get('name')}: {path}")