refactor: render setup files from the library

dump_setup moves next to scrape_setup, so readers of the setup format
no longer import the command. base_scraper names its dumper
PlatformDumper, and the command writes through write_if_changed.
This commit is contained in:
Abdessamad Derraz committed 2026-11-21 16:43:46 +01:00
1 parent 12b00e024b
commit b6599375f5
6 files changed
+21 -23

No files matched your search

+11
View File
@@ -20,12 +20,16 @@ from collections.abc import Callable
from dataclasses import dataclass, field
from pathlib import Path
import yaml
if (_SCRIPTS_DIR := str(Path(__file__).resolve().parents[2])) not in sys.path:
sys.path.insert(0, _SCRIPTS_DIR)
from core import upstream
from model.sources import source_yaml_file
from ..base_scraper import PlatformDumper
CACHE_DIR = upstream.CACHE_DIR
# Keys a setup file carries, in the order they are written.
@@ -201,3 +205,10 @@ def scrape_setup(setup: str, spec: dict, fetcher: Fetcher) -> dict:
doc = {"setup": setup, **{k: spec[k] for k in SETUP_KEYS[1:-1] if k in spec}}
doc["folders"] = [folders[k] for k in sorted(folders, key=lambda f: (f.lower(), f))]
return doc
def dump_setup(doc: dict) -> str:
"""The bytes of platforms/romfolders/<setup>.yml for a setup document."""
return yaml.dump(
doc, Dumper=PlatformDumper, sort_keys=False, allow_unicode=True, width=100
)