mirror of
https://github.com/Abdess/retroarch_system.git
synced 2026-11-23 10:07:48 -06:00
fix: surface upstream entries a scraper drops
RomM skipped an unmapped IGDB slug and RetroDECK a second component's conflicting MD5 with a stderr warning only: the rescrape exited 0, the rewritten file showed no diff and check_freshness said OK. An unmapped slug now fails the RomM scrape. A deliberate drop goes in BaseScraper.dropped, scraper_cli prints it under DROPPED_PREFIX, and the freshness rescrape reports an otherwise unchanged platform UNKNOWN.
This commit is contained in:
1 parent
398782a5cd
commit
1b7d30967b
9 files changed
+171
-19
No files matched your search
@@ -44,7 +44,7 @@ def check_platforms(platforms_dir: Path, workdir: Path, jobs: int) -> list[Findi
|
||||
def run(row: tuple[str, str, Path]) -> Finding:
|
||||
name, _module, path = row
|
||||
try:
|
||||
fresh, error = scrape_into_copy("platforms", name, path, workdir, registry)
|
||||
fresh, error, dropped = scrape_into_copy("platforms", name, path, workdir, registry)
|
||||
except subprocess.TimeoutExpired:
|
||||
return Finding("platforms", name, ERROR, detail="scraper timed out")
|
||||
if error:
|
||||
@@ -52,14 +52,19 @@ def check_platforms(platforms_dir: Path, workdir: Path, jobs: int) -> list[Findi
|
||||
old = source_yaml_file(path) or {}
|
||||
new = source_yaml_file(fresh) or {}
|
||||
diff = diff_platform(old, new)
|
||||
status = STALE if diff.changed else OK
|
||||
# An entry the scraper left out is in no diff: upstream declares a
|
||||
# file the platform file does not transcribe.
|
||||
status = STALE if diff.changed else UNKNOWN if dropped else OK
|
||||
detail = diff.summary()
|
||||
if dropped:
|
||||
detail = f"{detail}; {len(dropped)} upstream entries not transcribed ({dropped[0]})"
|
||||
return Finding(
|
||||
"platforms",
|
||||
name,
|
||||
status,
|
||||
local=str(old.get("version", "")),
|
||||
remote=str(new.get("version", "")),
|
||||
detail=diff.summary(),
|
||||
detail=detail,
|
||||
)
|
||||
|
||||
with ThreadPoolExecutor(max_workers=jobs) as pool:
|
||||
|
||||
@@ -9,16 +9,18 @@ from pathlib import Path
|
||||
|
||||
from core.paths import REPO_ROOT
|
||||
from freshness.scrapers import rescrape_command
|
||||
from scraper.base_scraper import DROPPED_PREFIX
|
||||
|
||||
|
||||
def scrape_into_copy(
|
||||
area: str, name: str, source: Path, workdir: Path,
|
||||
registry: Mapping[str, Mapping] | None = None, timeout: int = 900,
|
||||
) -> tuple[Path, str | None]:
|
||||
) -> tuple[Path, str | None, list[str]]:
|
||||
"""Run a scraper's own write path on a throwaway copy of *source*.
|
||||
|
||||
The CLI merges into the file it writes, so the copy carries every field
|
||||
the scraper preserves and the diff shows only what the scrape changes.
|
||||
The third value lists the upstream entries the scraper left out.
|
||||
"""
|
||||
target = workdir / source.name
|
||||
command = rescrape_command(area, name, target, registry)
|
||||
@@ -35,5 +37,10 @@ def scrape_into_copy(
|
||||
)
|
||||
if proc.returncode != 0:
|
||||
tail = (proc.stderr or proc.stdout).strip().splitlines()[-1:]
|
||||
return target, tail[0] if tail else f"exit {proc.returncode}"
|
||||
return target, None
|
||||
return target, tail[0] if tail else f"exit {proc.returncode}", []
|
||||
dropped = [
|
||||
line.removeprefix(DROPPED_PREFIX)
|
||||
for line in (proc.stderr or "").splitlines()
|
||||
if line.startswith(DROPPED_PREFIX)
|
||||
]
|
||||
return target, None, dropped
|
||||
@@ -103,7 +103,7 @@ def check_targets(
|
||||
out.extend(_unresolved_findings(platform, missing))
|
||||
return out
|
||||
try:
|
||||
fresh, error = scrape_into_copy("targets", platform, path, workdir)
|
||||
fresh, error, _dropped = scrape_into_copy("targets", platform, path, workdir)
|
||||
except subprocess.TimeoutExpired:
|
||||
return [Finding("targets", platform, ERROR, detail="scraper timed out")]
|
||||
if error:
|
||||
|
||||
@@ -148,6 +148,11 @@ def requirement_entry(req: BiosRequirement) -> dict:
|
||||
return entry
|
||||
|
||||
|
||||
# The stderr line a scraper CLI writes for each upstream entry the platform
|
||||
# file does not carry. The freshness rescrape reads them on exit 0, where the
|
||||
# diff of the rewritten file cannot show an entry that was never written.
|
||||
DROPPED_PREFIX = "dropped: "
|
||||
|
||||
SCRAPER_AGENT = "retrobios-scraper/1.0"
|
||||
GITHUB_API = "https://api.github.com"
|
||||
|
||||
@@ -403,6 +408,8 @@ class BaseScraper(ABC):
|
||||
|
||||
def __init__(self, url: str = "") -> None:
|
||||
self.url = url
|
||||
# Upstream entries left out of the platform file, each with its reason.
|
||||
self.dropped: list[str] = []
|
||||
self._raw_data: str | None = None
|
||||
self._json_data: dict | None = None
|
||||
|
||||
@@ -688,6 +695,8 @@ def scraper_cli(
|
||||
exit_on_scrape_error(RuntimeError(
|
||||
f"{scraper_class.__module__}: upstream returned no BIOS entry"
|
||||
))
|
||||
for reason in scraper.dropped:
|
||||
print(f"{DROPPED_PREFIX}{reason}", file=sys.stderr)
|
||||
|
||||
if args.dry_run:
|
||||
_print_dry_run(reqs)
|
||||
|
||||
@@ -363,9 +363,11 @@ def _entry_requirement(entry: dict, comp_key: str, default_system: object) -> Bi
|
||||
)
|
||||
|
||||
|
||||
def _warn_md5_conflict(
|
||||
def _md5_conflict(
|
||||
requirements: list[BiosRequirement], key: tuple[str, str], req: BiosRequirement
|
||||
) -> None:
|
||||
) -> str | None:
|
||||
"""Why *req* is left out: an earlier component declares the same file
|
||||
with another MD5. None for a plain repeat."""
|
||||
existing = next(
|
||||
(
|
||||
r
|
||||
@@ -376,11 +378,11 @@ def _warn_md5_conflict(
|
||||
)
|
||||
md5 = req.md5
|
||||
if existing and md5 and existing.md5 and md5 != existing.md5:
|
||||
print(
|
||||
f" WARNING: {req.name} ({req.system}): MD5 conflict "
|
||||
f"({existing.md5[:12]}... vs {md5[:12]}...)",
|
||||
file=sys.stderr,
|
||||
return (
|
||||
f"{req.name} ({req.system}): MD5 conflict "
|
||||
f"({existing.md5[:12]}... vs {md5[:12]}... in {req.native['component']})"
|
||||
)
|
||||
return None
|
||||
|
||||
|
||||
class Scraper(BaseScraper):
|
||||
@@ -493,7 +495,9 @@ class Scraper(BaseScraper):
|
||||
continue
|
||||
key = (req.system, req.name.lower())
|
||||
if key in seen:
|
||||
_warn_md5_conflict(requirements, key, req)
|
||||
conflict = _md5_conflict(requirements, key, req)
|
||||
if conflict:
|
||||
self.dropped.append(conflict)
|
||||
continue
|
||||
seen.add(key)
|
||||
requirements.append(req)
|
||||
|
||||
@@ -23,7 +23,6 @@ Slugs are IGDB-style platform identifiers.
|
||||
from __future__ import annotations
|
||||
|
||||
import re
|
||||
import sys
|
||||
|
||||
from .base_scraper import (
|
||||
BaseScraper,
|
||||
@@ -174,6 +173,7 @@ class Scraper(BaseScraper):
|
||||
|
||||
data = self._fetch_json()
|
||||
requirements: list[BiosRequirement] = []
|
||||
unmapped: set[str] = set()
|
||||
|
||||
for key, entry in data.items():
|
||||
if ":" not in key:
|
||||
@@ -182,7 +182,7 @@ class Scraper(BaseScraper):
|
||||
igdb_slug, filename = key.split(":", 1)
|
||||
system = SLUG_MAP.get(igdb_slug)
|
||||
if not system:
|
||||
print(f"Warning: unmapped IGDB slug '{igdb_slug}'", file=sys.stderr)
|
||||
unmapped.add(igdb_slug)
|
||||
continue
|
||||
|
||||
sha1 = (entry.get("sha1") or "").strip() or None
|
||||
@@ -211,6 +211,10 @@ class Scraper(BaseScraper):
|
||||
for slug in (igdb_slug, *mirrors)
|
||||
)
|
||||
|
||||
# Skipped, the slug's files left romm.yml with exit 0 and the
|
||||
# rescrape diff showed nothing for entries never written.
|
||||
if unmapped:
|
||||
raise ValueError(f"unmapped IGDB slug {', '.join(sorted(unmapped))}: add it to SLUG_MAP")
|
||||
return requirements
|
||||
|
||||
def validate_format(self, raw_data: str) -> bool:
|
||||
|
||||
Reference in new issue
Block a user