mirror of
https://github.com/Abdess/retroarch_system.git
synced 2026-12-03 06:48:52 -06:00
refactor: one loader for the rom-folder sources
This commit is contained in:
1 parent
17c64914ef
commit
1631ad0f4d
7 files changed
+32
-35
No files matched your search
@@ -6,20 +6,11 @@ from pathlib import Path
|
||||
|
||||
from core import upstream
|
||||
from model.registry import load_platform_registry
|
||||
from model.romfolders import row_sources
|
||||
from model.sources import source_yaml_file
|
||||
from model.romfolders import load_sources, row_sources, sources_dir
|
||||
from model.sourcerevision import scraped_revision
|
||||
from freshness.findings import OK, SKIPPED, STALE, UNKNOWN, Finding
|
||||
|
||||
|
||||
def romfolder_sources(platforms_dir: Path) -> dict[str, dict]:
|
||||
"""setup -> its platforms/romfolders/_sources/<setup>.yml."""
|
||||
out = {}
|
||||
for path in sorted((platforms_dir / "romfolders" / "_sources").glob("*.yml")):
|
||||
out[path.stem] = source_yaml_file(path) or {}
|
||||
return out
|
||||
|
||||
|
||||
def watched_sources(doc: dict) -> list[str]:
|
||||
"""The declared sources whose pins are compared: the setup's own pin
|
||||
(`os`, else the first declared), then every source its rows are read
|
||||
@@ -73,7 +64,7 @@ def check_romfolders(platforms_dir: Path, cache_dir: str, offline: bool) -> list
|
||||
"""
|
||||
return [
|
||||
_romfolder_pin(_subject(setup, doc, key), setup, doc["sources"][key], platforms_dir, cache_dir, offline)
|
||||
for setup, doc in romfolder_sources(platforms_dir).items()
|
||||
for setup, doc in load_sources(sources_dir(platforms_dir)).items()
|
||||
for key in watched_sources(doc)
|
||||
]
|
||||
|
||||
|
||||
@@ -24,8 +24,19 @@ from model.profiles import load_emulator_profiles, preferred_profile, upstream_p
|
||||
from model.platforms import load_platform_config, native_layer
|
||||
from model.sources import source_yaml_file
|
||||
|
||||
ROMFOLDERS_DIR = Path("platforms") / "romfolders"
|
||||
SOURCES_DIR = ROMFOLDERS_DIR / "_sources"
|
||||
|
||||
def romfolders_dir(platforms_dir: str | Path = PLATFORMS_DIR) -> Path:
|
||||
"""The rom-folder setups of a platforms directory."""
|
||||
return Path(platforms_dir) / "romfolders"
|
||||
|
||||
|
||||
def sources_dir(platforms_dir: str | Path = PLATFORMS_DIR) -> Path:
|
||||
"""The setups' declared sources and pins, beside the setup files."""
|
||||
return romfolders_dir(platforms_dir) / "_sources"
|
||||
|
||||
|
||||
ROMFOLDERS_DIR = romfolders_dir()
|
||||
SOURCES_DIR = sources_dir()
|
||||
|
||||
# "<source key> <path>:<line>[-<line>]", several joined by "; ".
|
||||
_REF_PART = re.compile(r"^(?P<key>[a-z0-9][a-z0-9-]*) (?P<path>\S+?)(?::(?P<lines>\d+(?:-\d+)?(?:,\d+(?:-\d+)?)*))?$")
|
||||
@@ -87,6 +98,11 @@ def setup_paths(directory: Path = ROMFOLDERS_DIR) -> list[Path]:
|
||||
return sorted(p for p in Path(directory).glob("*.yml") if not p.name.startswith("_"))
|
||||
|
||||
|
||||
def load_sources(directory: Path = SOURCES_DIR) -> dict[str, dict]:
|
||||
"""Each setup's declared sources and facts, keyed by its file name."""
|
||||
return {path.stem: source_yaml_file(path) or {} for path in sorted(Path(directory).glob("*.yml"))}
|
||||
|
||||
|
||||
def load_setup(path: Path) -> dict:
|
||||
return source_yaml_file(path)
|
||||
|
||||
|
||||
@@ -26,7 +26,6 @@ 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
|
||||
|
||||
@@ -160,14 +159,6 @@ def load_formats() -> dict[str, Parser]:
|
||||
return FORMATS
|
||||
|
||||
|
||||
def load_sources(directory: Path) -> dict[str, dict]:
|
||||
"""Each setup's declared sources and facts, keyed by its file name."""
|
||||
out: dict[str, dict] = {}
|
||||
for path in sorted(Path(directory).glob("*.yml")):
|
||||
out[path.stem] = source_yaml_file(path) or {}
|
||||
return out
|
||||
|
||||
|
||||
def _clean_row(row: dict) -> dict:
|
||||
unknown = set(row) - set(ROW_KEYS)
|
||||
if unknown:
|
||||
|
||||
@@ -11,11 +11,10 @@ import argparse
|
||||
import sys
|
||||
from pathlib import Path
|
||||
|
||||
from . import Fetcher, SourceError, dump_setup, load_sources, scrape_setup
|
||||
from . import Fetcher, SourceError, dump_setup, scrape_setup
|
||||
from core.upstream import UpstreamError
|
||||
from core.artifacts import write_if_changed
|
||||
|
||||
DEFAULT_DIR = Path("platforms") / "romfolders"
|
||||
from model.romfolders import ROMFOLDERS_DIR, SOURCES_DIR, load_sources
|
||||
|
||||
|
||||
def main() -> int:
|
||||
@@ -24,10 +23,10 @@ def main() -> int:
|
||||
which.add_argument("--setup", action="append", help="setup id (repeatable)")
|
||||
which.add_argument("--all", action="store_true", help="every setup of the sources file")
|
||||
which.add_argument("--list", action="store_true", help="list the setups and their format")
|
||||
parser.add_argument("--sources", type=Path, default=DEFAULT_DIR / "_sources",
|
||||
parser.add_argument("--sources", type=Path, default=SOURCES_DIR,
|
||||
help="the setups, their repositories and pinned revisions")
|
||||
parser.add_argument("--output-dir", type=Path, default=DEFAULT_DIR,
|
||||
help=f"where <setup>.yml is written (default {DEFAULT_DIR})")
|
||||
parser.add_argument("--output-dir", type=Path, default=ROMFOLDERS_DIR,
|
||||
help=f"where <setup>.yml is written (default {ROMFOLDERS_DIR})")
|
||||
parser.add_argument("--offline", action="store_true", help="read the revision cache only")
|
||||
parser.add_argument("--dry-run", action="store_true", help="print counts, write nothing")
|
||||
args = parser.parse_args()
|
||||
|
||||
@@ -55,7 +55,7 @@ from freshness.platformdiff import diff_platform, diff_targets
|
||||
from freshness.platforms import _scrapable_platforms, emulatorjs_pin
|
||||
from freshness.profiles import check_profiles, summarize_profile_sync
|
||||
from freshness.report import exit_code, render, unknown_areas_message
|
||||
from freshness.romfolders import check_romfolders, romfolder_pin_drift, romfolder_sources, watched_sources
|
||||
from freshness.romfolders import check_romfolders, romfolder_pin_drift, watched_sources
|
||||
from freshness.scrapers import rescrape_command, target_scrapers
|
||||
from freshness.targets import (
|
||||
_declared_cores,
|
||||
@@ -66,6 +66,7 @@ from freshness.targets import (
|
||||
unresolved_target_cores,
|
||||
)
|
||||
from model.registry import load_platform_registry
|
||||
from model.romfolders import load_sources, sources_dir
|
||||
from model.safeparse import yaml_load
|
||||
from model.targets import platform_overrides
|
||||
from profiling.reports import ProfileReport, report_to_dict
|
||||
@@ -524,7 +525,7 @@ class RomFolderPins(unittest.TestCase):
|
||||
|
||||
def test_the_committed_setups_agree_with_their_platform_files(self):
|
||||
platforms = REPO_ROOT / "platforms"
|
||||
drift = [d for setup, doc in romfolder_sources(platforms).items()
|
||||
drift = [d for setup, doc in load_sources(sources_dir(platforms)).items()
|
||||
for key in watched_sources(doc)
|
||||
if (d := romfolder_pin_drift(setup, doc["sources"][key], platforms))]
|
||||
self.assertEqual(drift, [])
|
||||
@@ -551,7 +552,7 @@ class RomFolderPins(unittest.TestCase):
|
||||
(STALE, "5 commits behind the branch head"))
|
||||
|
||||
def test_the_committed_mister_setup_watches_its_distribution(self):
|
||||
doc = romfolder_sources(REPO_ROOT / "platforms")["misterfpga"]
|
||||
doc = load_sources(sources_dir(REPO_ROOT / "platforms"))["misterfpga"]
|
||||
self.assertEqual(watched_sources(doc), ["main", "dist"])
|
||||
|
||||
|
||||
|
||||
@@ -13,9 +13,9 @@ import json
|
||||
import unittest
|
||||
from pathlib import Path
|
||||
|
||||
from model.romfolders import format_ref, row_sources, source_refs, split_refs
|
||||
from model.romfolders import format_ref, load_sources, row_sources, source_refs, split_refs
|
||||
from model.safeparse import yaml_load
|
||||
from scraper.romfolders import SourceError, dump_setup, load_sources, scrape_setup
|
||||
from scraper.romfolders import SourceError, dump_setup, scrape_setup
|
||||
from scraper.romfolders.card import (
|
||||
libretro_core,
|
||||
parse_allium,
|
||||
|
||||
@@ -15,13 +15,12 @@ import json
|
||||
import unittest
|
||||
from pathlib import Path
|
||||
|
||||
from model.romfolders import setup_paths, source_refs, split_refs
|
||||
from model.romfolders import load_sources, setup_paths, source_refs, split_refs
|
||||
from scraper.romfolders import (
|
||||
Fetcher,
|
||||
SourceError,
|
||||
dump_setup,
|
||||
load_formats,
|
||||
load_sources,
|
||||
scrape_setup,
|
||||
)
|
||||
from scraper.retropie_modules import module_enabled
|
||||
|
||||
Reference in new issue
Block a user