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

+3 -15
View File
@@ -11,22 +11,13 @@ import argparse
import sys
from pathlib import Path
import yaml
from . import Fetcher, SourceError, load_sources, scrape_setup
from . import Fetcher, SourceError, dump_setup, load_sources, scrape_setup
from core.upstream import UpstreamError
from core.artifacts import write_text_atomic
from ..base_scraper import _PlatformDumper
from core.artifacts import write_if_changed
DEFAULT_DIR = Path("platforms") / "romfolders"
def dump_setup(doc: dict) -> str:
return yaml.dump(
doc, Dumper=_PlatformDumper, sort_keys=False, allow_unicode=True, width=100
)
def main() -> int:
parser = argparse.ArgumentParser(allow_abbrev=False, description=__doc__.splitlines()[0])
which = parser.add_mutually_exclusive_group(required=True)
@@ -64,10 +55,7 @@ def main() -> int:
print(f"{setup}: {len(doc['folders'])} folders")
if not args.dry_run:
args.output_dir.mkdir(parents=True, exist_ok=True)
target = args.output_dir / f"{setup}.yml"
text = dump_setup(doc)
if not target.exists() or target.read_text(encoding="utf-8") != text:
write_text_atomic(str(target), text)
write_if_changed(str(args.output_dir / f"{setup}.yml"), dump_setup(doc))
return 1 if failed else 0