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

+3 -1
View File
@@ -15,7 +15,9 @@ from pathlib import Path
from typing import Any
from common import PROFILE_BACKUP_SUFFIX, write_text_atomic, yaml_load
from model.profiles import PROFILE_BACKUP_SUFFIX
from core.artifacts import write_text_atomic
from model.safeparse import yaml_load
_MAME_RELEASE_RE = re.compile(r"^0\.\d+")
+2 -1
View File
@@ -51,7 +51,8 @@ from pathlib import Path
from typing import IO
from core.artifacts import write_if_changed
from ..common import load_emulator_profiles, run_cli
from model.profiles import load_emulator_profiles
from core.cli import run_cli
from .romset_dat_importer import (
LISTXML_CHUNK,
MAME_LISTXML_URL,
+3 -1
View File
@@ -17,7 +17,9 @@ from dataclasses import dataclass, field
from pathlib import Path
from typing import Callable, NoReturn, Protocol
from common import github_token, write_text_atomic, yaml_load
from core.github import github_token
from core.artifacts import write_text_atomic
from model.safeparse import yaml_load
@dataclass
+2 -1
View File
@@ -18,7 +18,8 @@ from collections.abc import Callable
from pathlib import Path
from common import load_target_config, yaml_load
from model.targets import load_target_config
from model.safeparse import yaml_load
from core.hashing import cut_md5_owner
from model.safeparse import yaml_load_upstream
+1 -1
View File
@@ -20,7 +20,7 @@ from collections.abc import Iterator
from datetime import datetime, timezone
from pathlib import Path
from ..common import write_provenance_snapshot
from model.dumpcatalog import write_provenance_snapshot
from .logiqx_parser import LogiqxDat, parse_logiqx
MAX_MEMBER_SIZE = 100 * 1024 * 1024
+3 -1
View File
@@ -21,7 +21,9 @@ from typing import Any
import yaml
from common import source_yaml_paths, write_text_atomic, yaml_load
from model.profiles import source_yaml_paths
from core.artifacts import write_text_atomic
from model.safeparse import yaml_load
from scripts.scraper._hash_merge import compute_diff, merge_fbneo_profile
from scripts.scraper.fbneo_parser import parse_fbneo_source_tree
+1 -1
View File
@@ -40,7 +40,7 @@ if (_SCRIPTS_DIR := str(Path(__file__).resolve().parents[1])) not in sys.path:
sys.path.insert(0, _SCRIPTS_DIR)
from core.artifacts import copy_stream_atomic, write_if_changed, write_text_atomic
from common import parse_untrusted_xml
from model.safeparse import parse_untrusted_xml
from region import REGIONS, WORLD
from region_audit import NOINTRO
+1 -1
View File
@@ -15,7 +15,7 @@ from __future__ import annotations
import xml.etree.ElementTree as ET
from dataclasses import dataclass, field
from common import parse_untrusted_xml
from model.safeparse import parse_untrusted_xml
@dataclass
+1 -1
View File
@@ -27,7 +27,7 @@ from contextlib import contextmanager
from pathlib import Path
from typing import IO, NamedTuple
from common import yaml_load
from model.safeparse import yaml_load
from ._hash_merge import generated_start
from .mame_parser import _collect_rom_macros, _expand_macros, _parse_rom_entries
+6 -8
View File
@@ -24,14 +24,12 @@ from typing import Any
import yaml
from common import (
github_token,
list_registered_platforms,
load_platform_config,
source_yaml_paths,
write_text_atomic,
yaml_load,
)
from core.github import github_token
from model.registry import list_registered_platforms
from model.platforms import load_platform_config
from model.profiles import source_yaml_paths
from core.artifacts import write_text_atomic
from model.safeparse import yaml_load
import upstream
+1 -1
View File
@@ -15,7 +15,7 @@ Recalbox verification logic:
from __future__ import annotations
from common import parse_untrusted_xml
from model.safeparse import parse_untrusted_xml
from .base_scraper import BaseScraper, BiosRequirement, fetch_bytes, requirement_entry
from .recalbox_launchers import SOURCE_FILES as LAUNCHER_FILES
+1 -1
View File
@@ -22,7 +22,7 @@ import urllib.request
from datetime import datetime, timezone
from pathlib import Path
from ..common import write_provenance_snapshot
from model.dumpcatalog import write_provenance_snapshot
from .base_scraper import _read_limited
from .logiqx_parser import parse_logiqx, validate_logiqx_format
+4 -4
View File
@@ -49,7 +49,7 @@ ES_SYSTEMS_URL = (
def es_systems_dual(text: str) -> set[str]:
"""Emulators es_systems.cfg offers both as a libretro core and standalone."""
from common import parse_untrusted_xml
from model.safeparse import parse_untrusted_xml
libretro: set[str] = set()
standalone: set[str] = set()
@@ -70,7 +70,7 @@ def es_systems_cores(text: str) -> tuple[set[str], set[str]]:
name. batocera-systems.json names BIOS files only, so the platform read
from it alone had no core list and relied on one kept by hand.
"""
from common import parse_untrusted_xml
from model.safeparse import parse_untrusted_xml
root = parse_untrusted_xml(text, "es_systems.cfg")
cores: set[str] = set()
@@ -96,7 +96,7 @@ def es_systems_libretro_systems(text: str) -> dict[str, list[str]]:
reads below its save directory sits once in each of these system
folders. A commented-out system is no element and counts for nothing.
"""
from common import parse_untrusted_xml
from model.safeparse import parse_untrusted_xml
found: dict[str, set[str]] = {}
for system in parse_untrusted_xml(text, "es_systems.cfg").iter("system"):
@@ -127,7 +127,7 @@ def pinned_revision(platform_file: Path = PLATFORM_FILE) -> str:
A rescrape reads this commit unless told to move, so a change to an
extractor shows in the diff alone, without upstream's commits since.
"""
from common import yaml_load
from model.safeparse import yaml_load
with platform_file.open(encoding="utf-8") as fh:
source = str((yaml_load(fh) or {}).get("source") or "")
+2 -2
View File
@@ -77,7 +77,7 @@ def es_systems_libretro_systems(text: str) -> dict[str, list[str]]:
ROM>, the system's <path> folder below %ROMPATH%. A commented-out
command is no element and counts for nothing.
"""
from common import parse_untrusted_xml
from model.safeparse import parse_untrusted_xml
found: dict[str, set[str]] = {}
for system in parse_untrusted_xml(text, "es_systems.xml").iter("system"):
@@ -411,7 +411,7 @@ class Scraper(BaseScraper):
def _fetch_remote_manifests(self) -> list[tuple[str, dict]]:
"""Fetch component manifests via GitHub API."""
from common import github_token
from core.github import github_token
token = github_token()
headers = {"User-Agent": "retrobios-scraper/1.0"}
+4 -6
View File
@@ -45,12 +45,10 @@ from datetime import datetime, timezone
from pathlib import Path
from typing import IO
from ..common import (
list_registered_platforms,
load_emulator_profiles,
load_platform_config,
run_cli,
)
from model.registry import list_registered_platforms
from model.profiles import load_emulator_profiles
from model.platforms import load_platform_config
from core.cli import run_cli
from model.dumpcatalog import build_snapshot, load_provenance_snapshots, write_snapshot
from .logiqx_parser import LogiqxDat, parse_logiqx
+1 -1
View File
@@ -59,7 +59,7 @@ class BaseTargetScraper(ABC):
import yaml
except ImportError as exc:
raise ImportError("PyYAML required: pip install pyyaml") from exc
from common import write_text_atomic
from core.artifacts import write_text_atomic
write_text_atomic(
output_path, yaml.dump(data, default_flow_style=False, sort_keys=False)
@@ -20,7 +20,8 @@ from pathlib import Path
import yaml
from common import github_token, yaml_load
from core.github import github_token
from model.safeparse import yaml_load
from ..emudeck_launchers import SCRIPT_SUFFIXES, emulator_of_script
from . import BaseTargetScraper
@@ -68,7 +68,7 @@ _MODULE_FLAGS_RE = re.compile(r'rp_module_flags\s*=\s*["\']([^"\']*)["\']')
def _fetch(url: str, accept: str = "text/plain") -> str:
headers = {"User-Agent": "retrobios-scraper/1.0", "Accept": accept}
from common import github_token
from core.github import github_token
token = github_token()
if token and "api.github.com" in url: