mirror of
https://github.com/Abdess/retroarch_system.git
synced 2026-11-22 17:47:48 -06:00
refactor: log truth hash conflicts, not print
This commit is contained in:
1 parent
3e55385410
commit
3b16ee2633
5 files changed
+26
-31
No files matched your search
@@ -4,7 +4,6 @@ from __future__ import annotations
|
||||
|
||||
import contextlib
|
||||
import io
|
||||
import sys
|
||||
from collections.abc import Iterator
|
||||
from pathlib import Path
|
||||
|
||||
@@ -14,6 +13,7 @@ from exporter.originals import SOURCES_INDEX, SourcesIndexUnreadable, load_sourc
|
||||
from model.platforms import inheritance_chain
|
||||
from model.registry import list_registered_platforms
|
||||
from resolve.reconcile import build_native_model
|
||||
from resolve.truth import log as truth_log
|
||||
from freshness.findings import ERROR, OK, STALE, Finding
|
||||
|
||||
|
||||
@@ -92,25 +92,20 @@ def _transcribed_at(platforms_dir: Path, platform: str) -> float:
|
||||
)
|
||||
|
||||
|
||||
# How the truth model settles two cores' hashes: generate_truth reports it,
|
||||
# and it says nothing about whether a cached original is current.
|
||||
_MODEL_NOTES = ("WARNING: hash conflict",)
|
||||
|
||||
|
||||
@contextlib.contextmanager
|
||||
def _without_model_notes() -> Iterator[None]:
|
||||
"""Keep the model build's own notes out of the freshness report.
|
||||
"""Keep the truth model's own notes out of the freshness report.
|
||||
|
||||
Anything else written to stderr passes through.
|
||||
generate_truth reports how two cores' hashes were settled, and that says
|
||||
nothing about whether a cached original is current. Anything else
|
||||
written to stderr passes through.
|
||||
"""
|
||||
sink = io.StringIO()
|
||||
previous = truth_log.disabled
|
||||
truth_log.disabled = True
|
||||
try:
|
||||
with contextlib.redirect_stderr(sink):
|
||||
yield
|
||||
yield
|
||||
finally:
|
||||
for line in sink.getvalue().splitlines(keepends=True):
|
||||
if not line.startswith(_MODEL_NOTES):
|
||||
sys.stderr.write(line)
|
||||
truth_log.disabled = previous
|
||||
|
||||
|
||||
def check_native(
|
||||
|
||||
@@ -7,8 +7,8 @@ and diffs truth against scraped platform data to find divergences.
|
||||
from __future__ import annotations
|
||||
|
||||
import copy
|
||||
import logging
|
||||
import os
|
||||
import sys
|
||||
from dataclasses import dataclass
|
||||
|
||||
from model.declarations import OUTER_ROOTS
|
||||
@@ -30,6 +30,10 @@ from resolve.validation import (
|
||||
from core.paths import REPO_ROOT
|
||||
|
||||
|
||||
# Notes on how the model settled two cores: a caller that has no use for
|
||||
# them (check_freshness) silences this logger, never the text it writes.
|
||||
log = logging.getLogger(__name__)
|
||||
|
||||
_CONFLICTS_SHOWN: set[tuple[str, ...]] = set()
|
||||
|
||||
|
||||
@@ -336,11 +340,10 @@ def _merge_hashes(
|
||||
# Both cores and which value stays: naming only the second
|
||||
# core sent the reader through ten profiles for the first.
|
||||
first = existing.get("_hash_by", {}).get(h, "an earlier core")
|
||||
print(
|
||||
f"WARNING: hash conflict for {file_entry['name']}: "
|
||||
f"{h} {ours} ({first}) kept, {theirs} ({emu_name}) "
|
||||
log.warning(
|
||||
"WARNING: hash conflict for %s: %s %s (%s) kept, %s (%s) "
|
||||
"left out of the model",
|
||||
file=sys.stderr,
|
||||
file_entry["name"], h, ours, first, theirs, emu_name,
|
||||
)
|
||||
|
||||
|
||||
|
||||
@@ -7072,18 +7072,14 @@ class AHashConflictIsReportedOnce(unittest.TestCase):
|
||||
platform whose model met the same two GameIndex.yaml declarations."""
|
||||
|
||||
def test_the_same_pair_prints_once(self):
|
||||
import contextlib
|
||||
import io
|
||||
|
||||
from resolve import truth
|
||||
|
||||
truth._CONFLICTS_SHOWN.clear()
|
||||
err = io.StringIO()
|
||||
with contextlib.redirect_stderr(err):
|
||||
with self.assertLogs(truth.log, "WARNING") as logged:
|
||||
for _platform in range(6):
|
||||
existing = {"name": "x.yaml", "sha1": "a" * 40}
|
||||
truth._merge_hashes(existing, {"name": "x.yaml", "sha1": "b" * 40}, "core")
|
||||
self.assertEqual(err.getvalue().count("WARNING"), 1)
|
||||
self.assertEqual(len(logged.records), 1)
|
||||
|
||||
|
||||
class ThePipelineRunsTheSchemaCheckCIRuns(unittest.TestCase):
|
||||
|
||||
@@ -166,9 +166,10 @@ class NativeCacheTests(unittest.TestCase):
|
||||
import contextlib
|
||||
import io
|
||||
|
||||
from resolve.truth import log as truth_log
|
||||
|
||||
def noisy(truth, scraped):
|
||||
print("WARNING: hash conflict for GameIndex.yaml (sha1: a vs b, core yaps2)",
|
||||
file=sys.stderr)
|
||||
truth_log.warning("WARNING: hash conflict for GameIndex.yaml (sha1: a vs b, core yaps2)")
|
||||
print("other diagnostic", file=sys.stderr)
|
||||
return {}, None
|
||||
|
||||
|
||||
@@ -809,8 +809,7 @@ class AHashConflictNamesBothCores(unittest.TestCase):
|
||||
def test_both_cores_and_the_kept_value(self):
|
||||
truth._CONFLICTS_SHOWN.clear()
|
||||
system: dict = {}
|
||||
err = io.StringIO()
|
||||
with contextlib.redirect_stderr(err):
|
||||
with self.assertLogs(truth.log, "WARNING") as logged:
|
||||
truth._merge_file_into_system(
|
||||
system, {"name": "G.yaml", "path": "r/G.yaml", "sha1": "5e" * 20},
|
||||
"pcsx2", None,
|
||||
@@ -819,8 +818,9 @@ class AHashConflictNamesBothCores(unittest.TestCase):
|
||||
system, {"name": "G.yaml", "path": "r/G.yaml", "sha1": "7e" * 20},
|
||||
"yaps2", None,
|
||||
)
|
||||
self.assertIn(f"{'5e' * 20} (pcsx2) kept", err.getvalue())
|
||||
self.assertIn(f"{'7e' * 20} (yaps2)", err.getvalue())
|
||||
text = "\n".join(record.getMessage() for record in logged.records)
|
||||
self.assertIn(f"{'5e' * 20} (pcsx2) kept", text)
|
||||
self.assertIn(f"{'7e' * 20} (yaps2)", text)
|
||||
|
||||
def test_the_origin_is_not_written_to_the_model(self):
|
||||
profile = {"type": "libretro", "systems": ["sony-playstation"],
|
||||
|
||||
Reference in new issue
Block a user