diff --git a/.github/workflows/deploy-site.yml b/.github/workflows/deploy-site.yml index 52c0f1718..8170d52ab 100644 --- a/.github/workflows/deploy-site.yml +++ b/.github/workflows/deploy-site.yml @@ -50,6 +50,7 @@ on: - "scripts/model/database.py" - "scripts/model/declarations.py" - "scripts/model/dumpcatalog.py" + - "scripts/model/exportchanges.py" - "scripts/model/guides.py" - "scripts/model/largefiles.py" - "scripts/model/mamerelease.py" diff --git a/exports/amberelec.json b/exports/amberelec.json index c53a8fcb4..ec13dc394 100644 --- a/exports/amberelec.json +++ b/exports/amberelec.json @@ -11,7 +11,14 @@ "kept": 440, "added": 55, "not_added": 1917, - "not_kept": 0 + "not_kept": 0, + "hash_updated": 0, + "required_aligned": 0, + "hash_filled": 10, + "size_updated": 0, + "size_removed": 0, + "hash_cleared": 0, + "md5_lists": 0 }, "changes": [ { diff --git a/exports/batocera.json b/exports/batocera.json index 9c8d1b708..c95fef25a 100644 --- a/exports/batocera.json +++ b/exports/batocera.json @@ -11,7 +11,14 @@ "kept": 692, "added": 172, "not_added": 2554, - "not_kept": 0 + "not_kept": 0, + "hash_updated": 4, + "required_aligned": 0, + "hash_filled": 0, + "size_updated": 0, + "size_removed": 0, + "hash_cleared": 0, + "md5_lists": 0 }, "changes": [ { diff --git a/exports/bizhawk.json b/exports/bizhawk.json index 2c07dcc30..3a974e411 100644 --- a/exports/bizhawk.json +++ b/exports/bizhawk.json @@ -11,7 +11,14 @@ "kept": 121, "added": 0, "not_added": 0, - "not_kept": 0 + "not_kept": 0, + "hash_updated": 0, + "required_aligned": 0, + "hash_filled": 0, + "size_updated": 0, + "size_removed": 0, + "hash_cleared": 0, + "md5_lists": 0 }, "changes": [], "hashes_updated": [], diff --git a/exports/emudeck.json b/exports/emudeck.json index f45abd694..44e61d7c8 100644 --- a/exports/emudeck.json +++ b/exports/emudeck.json @@ -11,7 +11,14 @@ "kept": 170, "added": 0, "not_added": 2334, - "not_kept": 0 + "not_kept": 0, + "hash_updated": 0, + "required_aligned": 0, + "hash_filled": 0, + "size_updated": 0, + "size_removed": 0, + "hash_cleared": 0, + "md5_lists": 0 }, "changes": [], "hashes_updated": [], diff --git a/exports/emuelec.json b/exports/emuelec.json index 76de7911b..01c0e0dbe 100644 --- a/exports/emuelec.json +++ b/exports/emuelec.json @@ -11,7 +11,14 @@ "kept": 590, "added": 37, "not_added": 1885, - "not_kept": 0 + "not_kept": 0, + "hash_updated": 0, + "required_aligned": 0, + "hash_filled": 47, + "size_updated": 0, + "size_removed": 0, + "hash_cleared": 0, + "md5_lists": 0 }, "changes": [ { diff --git a/exports/knulli.json b/exports/knulli.json index 10b248dfe..210c21745 100644 --- a/exports/knulli.json +++ b/exports/knulli.json @@ -11,7 +11,14 @@ "kept": 566, "added": 105, "not_added": 2051, - "not_kept": 0 + "not_kept": 0, + "hash_updated": 4, + "required_aligned": 0, + "hash_filled": 0, + "size_updated": 0, + "size_removed": 0, + "hash_cleared": 0, + "md5_lists": 0 }, "changes": [ { diff --git a/exports/lakka.json b/exports/lakka.json index 14d2b4f88..2da3eeda9 100644 --- a/exports/lakka.json +++ b/exports/lakka.json @@ -11,7 +11,14 @@ "kept": 519, "added": 202, "not_added": 1799, - "not_kept": 0 + "not_kept": 0, + "hash_updated": 76, + "required_aligned": 0, + "hash_filled": 0, + "size_updated": 23, + "size_removed": 1, + "hash_cleared": 2, + "md5_lists": 0 }, "changes": [ { diff --git a/exports/misterfpga.json b/exports/misterfpga.json index 932d3c9cf..609ef59ca 100644 --- a/exports/misterfpga.json +++ b/exports/misterfpga.json @@ -12,7 +12,14 @@ "kept": 88, "added": 0, "not_added": 0, - "not_kept": 0 + "not_kept": 0, + "hash_updated": 0, + "required_aligned": 0, + "hash_filled": 0, + "size_updated": 0, + "size_removed": 0, + "hash_cleared": 0, + "md5_lists": 0 }, "changes": [], "hashes_updated": [], diff --git a/exports/recalbox.json b/exports/recalbox.json index 0a7cb2394..3bd7bd533 100644 --- a/exports/recalbox.json +++ b/exports/recalbox.json @@ -12,7 +12,14 @@ "kept": 357, "added": 90, "not_added": 522, - "not_kept": 0 + "not_kept": 0, + "hash_updated": 2, + "required_aligned": 131, + "hash_filled": 0, + "size_updated": 0, + "size_removed": 0, + "hash_cleared": 0, + "md5_lists": 1 }, "changes": [ { diff --git a/exports/retroarch.json b/exports/retroarch.json index 309404bc5..9381f7804 100644 --- a/exports/retroarch.json +++ b/exports/retroarch.json @@ -11,7 +11,14 @@ "kept": 519, "added": 213, "not_added": 1806, - "not_kept": 0 + "not_kept": 0, + "hash_updated": 76, + "required_aligned": 0, + "hash_filled": 0, + "size_updated": 23, + "size_removed": 1, + "hash_cleared": 2, + "md5_lists": 0 }, "changes": [ { diff --git a/exports/retrobat.json b/exports/retrobat.json index 39d8c4fee..8ee6ec688 100644 --- a/exports/retrobat.json +++ b/exports/retrobat.json @@ -11,7 +11,14 @@ "kept": 362, "added": 50, "not_added": 1931, - "not_kept": 0 + "not_kept": 0, + "hash_updated": 1, + "required_aligned": 0, + "hash_filled": 9, + "size_updated": 0, + "size_removed": 0, + "hash_cleared": 0, + "md5_lists": 0 }, "changes": [ { diff --git a/exports/retrodeck.json b/exports/retrodeck.json index 044c6c381..511fe6adc 100644 --- a/exports/retrodeck.json +++ b/exports/retrodeck.json @@ -29,7 +29,14 @@ "kept": 2021, "added": 77, "not_added": 1269, - "not_kept": 0 + "not_kept": 0, + "hash_updated": 0, + "required_aligned": 41, + "hash_filled": 118, + "size_updated": 0, + "size_removed": 0, + "hash_cleared": 0, + "md5_lists": 0 }, "changes": [ { diff --git a/exports/rocknix.json b/exports/rocknix.json index 0744609fb..97ec90675 100644 --- a/exports/rocknix.json +++ b/exports/rocknix.json @@ -12,7 +12,14 @@ "kept": 38, "added": 6, "not_added": 1853, - "not_kept": 0 + "not_kept": 0, + "hash_updated": 2, + "required_aligned": 0, + "hash_filled": 0, + "size_updated": 0, + "size_removed": 0, + "hash_cleared": 0, + "md5_lists": 0 }, "changes": [ { diff --git a/exports/romm.json b/exports/romm.json index 71ec8436e..777225b61 100644 --- a/exports/romm.json +++ b/exports/romm.json @@ -11,7 +11,14 @@ "kept": 374, "added": 94, "not_added": 342, - "not_kept": 0 + "not_kept": 0, + "hash_updated": 1, + "required_aligned": 0, + "hash_filled": 0, + "size_updated": 0, + "size_removed": 0, + "hash_cleared": 0, + "md5_lists": 0 }, "changes": [ { diff --git a/scripts/exporter/native.py b/scripts/exporter/native.py index 3b0a02644..21aa33165 100644 --- a/scripts/exporter/native.py +++ b/scripts/exporter/native.py @@ -21,6 +21,7 @@ from .doubled import doubled_destinations from .landed import LandedChanges, landed_changes from .originals import collect_originals, unpinned, wanted_sources from model.database import load_database +from model.exportchanges import change_phrases from model.platforms import load_platform_config, native_layer from model.profiles import load_emulator_profiles from model.registry import load_data_dir_registry, load_platform_registry @@ -249,9 +250,10 @@ def build_export( landed, refused, lost = _entry_outcomes(exporter, systems) own_summary = exporter.outcome(systems, produced) + counts = _change_counts(report, changes, landed, refused, lost) summary = own_summary if summary is None: - summary = _landed_summary(report, changes, landed, lost) + summary = _landed_summary(counts) withheld = exporter.withheld() unwritten = _unwritten(refused, withheld, report) # Reported, never removed: the platform's file keeps every entry. @@ -267,12 +269,7 @@ def build_export( "originals": wanted_sources(exporter, systems, scraped), "files": sorted(produced), "summary": summary, - "counts": None if own_summary is not None else { - "kept": report.files_kept, - "added": landed, - "not_added": refused, - "not_kept": lost, - }, + "counts": None if own_summary is not None else counts, "changes": changes.records, "hashes_updated": applied, "hashes_filled": filled, @@ -349,27 +346,29 @@ def _entry_outcomes(exporter: BaseExporter, systems: dict) -> tuple[int, int, in return landed, refused, lost -def _landed_summary(report: Report, changes: LandedChanges, landed: int, lost: int) -> str: - # What the written file carries, in the terms the exports page uses. +def _change_counts( + report: Report, changes: LandedChanges, landed: int, refused: int, lost: int +) -> dict[str, int]: + """How many entries each kind of change touches, as the report stores them.""" + return { + "kept": report.files_kept, + "added": landed, + "not_added": refused, + "not_kept": lost, + "hash_updated": len(changes.applied), + "required_aligned": changes.requirements, + "hash_filled": len(changes.filled), + "size_updated": len(changes.resized), + "size_removed": len(changes.unsized), + "hash_cleared": len(changes.cleared), + "md5_lists": changes.lists, + } + + +def _landed_summary(counts: dict[str, int]) -> str: + # What the written file carries, the same changes the exports page names. # What it does not carry is counted on a line of its own below. - parts = [f"{report.files_kept} kept"] - landed_counts = ( - (landed, "file", "", "added"), - (len(changes.applied), "hash", "", "updated to the emulator source"), - (changes.requirements, "required flag", "", "aligned with the code"), - (len(changes.filled), "hash", "", "added to an existing entry"), - (len(changes.resized), "size", "", "updated to the emulator source"), - (len(changes.unsized), "size", "", "removed"), - (len(changes.cleared), "hash", "", "removed"), - (lost, "entry", "entries", "removed, the format cannot state them"), - (changes.lists, "md5 list", "", "written, any listed value passes"), - ) - parts += [ - f"{count_text(number, noun, plural)} {verb}" - for number, noun, plural, verb in landed_counts - if number - ] - return ", ".join(parts) + return ", ".join([f"{counts['kept']} kept", *change_phrases(counts)]) def _unwritten(refused: int, withheld: list[str], report: Report) -> list[str]: diff --git a/scripts/model/exportchanges.py b/scripts/model/exportchanges.py new file mode 100644 index 000000000..8298083c1 --- /dev/null +++ b/scripts/model/exportchanges.py @@ -0,0 +1,45 @@ +"""The kinds of change an export writes into a platform's file, and how each is said.""" + +from __future__ import annotations + +from typing import NamedTuple + +from core.text import count_text + + +class ChangeKind(NamedTuple): + """One kind of change, its count key in the report and its two wordings.""" + + key: str + noun: str + plural: str + terse: str + plain: str + + +# In the order both sentences name them. `terse` is the run's summary, +# `plain` the exports page. +CHANGE_KINDS = ( + ChangeKind("added", "file", "", "added", "added"), + ChangeKind("hash_updated", "hash", "", "updated to the emulator source", "updated"), + ChangeKind("required_aligned", "required flag", "", + "aligned with the code", "aligned with the code"), + ChangeKind("hash_filled", "hash", "", "added to an existing entry", "added"), + ChangeKind("size_updated", "size", "", "updated to the emulator source", "updated"), + ChangeKind("size_removed", "size", "", "removed", "removed"), + ChangeKind("hash_cleared", "hash", "", "removed", "removed"), + ChangeKind("not_kept", "entry", "entries", "removed, the format cannot state them", + "not written, the format cannot state them"), + ChangeKind("md5_lists", "md5 list", "", + "written, any listed value passes", "written, any listed value passes"), +) + + +def change_phrases(counts: dict, plain: bool = False) -> list[str]: + """Each change the counts hold, as "2 hashes removed", none for a zero.""" + return [ + f"{count_text(counts[kind.key], kind.noun, kind.plural)} " + f"{kind.plain if plain else kind.terse}" + for kind in CHANGE_KINDS + if counts[kind.key] + ] diff --git a/scripts/sitegen/exports.py b/scripts/sitegen/exports.py index b69bdefae..60ade8749 100644 --- a/scripts/sitegen/exports.py +++ b/scripts/sitegen/exports.py @@ -12,6 +12,7 @@ import json from pathlib import Path from core.text import count_text +from model.exportchanges import change_phrases from sitegen import markup EXPORTS_DIR = "exports" @@ -95,24 +96,15 @@ def _lookup_only(block: list[str]) -> list[str]: def change_text(report: dict) -> str: """What the updated file changes, from the report's numbers. - The command line prints its own terse summary. The page states each - kind of change once, in plain terms, and leaves out what did not - happen. RetroPie's unit is a package, so its own sentence is kept. + The page names the changes the run's summary names, in plain terms, + and leaves out what did not happen. RetroPie's unit is a package, so + its own sentence is kept. """ counts = report.get("counts") if not counts: return report["summary"] - parts = [f"{count_text(counts['kept'], 'entry', 'entries')} kept"] - extra = [ - (counts["added"], "file", "files", "added"), - (len(report.get("hashes_updated") or []), "hash", "hashes", "updated"), - (report.get("required_aligned") or 0, "required flag", "required flags", - "aligned with the code"), - (len(report.get("hashes_filled") or []), "hash", "hashes", "added"), - (len(report.get("sizes_updated") or []), "size", "sizes", "updated"), - ] - parts += [f"{count_text(n, one, many)} {verb}" for n, one, many, verb in extra if n] - return ", ".join(parts) + kept = f"{count_text(counts['kept'], 'entry', 'entries')} kept" + return ", ".join([kept, *change_phrases(counts, plain=True)]) # Beyond this many entries a reason's list folds away. @@ -301,12 +293,6 @@ def generate_exports_page(reports: list[dict], names: dict[str, str]) -> str: "reasons above.", "", ]) - if counts.get("not_kept"): - lines.extend([ - f"{count_text(counts['not_kept'], 'entry', 'entries')} of the original " - "cannot be written in this format and should be checked by hand.", - "", - ]) lines.extend(candidate_lines(report.get("removal_candidates") or [])) lines.extend(doubled_lines(report.get("doubled") or [])) if report.get("invalid"): diff --git a/tests/sources.py b/tests/sources.py index 681eea86c..2a5cbf279 100644 --- a/tests/sources.py +++ b/tests/sources.py @@ -184,6 +184,7 @@ COMMANDS = { "bundled_only.py": ("packs/bundledonly.py",), "export_native.py": ( "exporter/runner.py", "exporter/native.py", "exporter/originals.py", "exporter/landed.py", + "model/exportchanges.py", ), } diff --git a/tests/test_export_report.py b/tests/test_export_report.py index c80b25ebf..53ac773a5 100644 --- a/tests/test_export_report.py +++ b/tests/test_export_report.py @@ -18,12 +18,20 @@ from pathlib import Path from exporter import native from exporter.landed import landed_changes from exporter.native import build_export, current_truth, write_report +from model.exportchanges import CHANGE_KINDS from model.profiles import load_emulator_profiles from sitegen.exports import generate_exports_page, load_export_reports ROOT = Path(__file__).resolve().parent.parent +def _counts(**changed: int) -> dict: + """A report's counts with every kind of change at zero but *changed*.""" + counts = {"kept": 0, "not_added": 0} | {kind.key: 0 for kind in CHANGE_KINDS} + counts.update(changed) + return counts + + def _report(platform: str, files: list[str], **changes: object) -> dict: report = { "platform": platform, @@ -156,16 +164,42 @@ class ThePageAddressesMaintainersAsPeers(unittest.TestCase): report = _report("batocera", ["batocera-systems"], hashes_updated=["a md5", "b md5"], required_aligned=3) - report["counts"] = {"kept": 692, "added": 253, "not_added": 10, "not_kept": 0} + report["counts"] = _counts(kept=692, added=253, not_added=10, + hash_updated=2, required_aligned=3) self.assertEqual( change_text(report), "692 entries kept, 253 files added, 2 hashes updated, " "3 required flags aligned with the code", ) + def test_the_page_names_every_change_the_run_names(self): + """The page rebuilt the sentence from its own five kinds and left out + the sizes and hashes removed and the md5 lists the file carries.""" + from exporter.native import _landed_summary + from sitegen.exports import change_text + + counts = _counts(kept=519, **{kind.key: 1 for kind in CHANGE_KINDS}) + report = _report("retroarch", ["System.dat"], counts=counts) + self.assertEqual( + _landed_summary(counts), + "519 kept, 1 file added, 1 hash updated to the emulator source, " + "1 required flag aligned with the code, 1 hash added to an existing entry, " + "1 size updated to the emulator source, 1 size removed, 1 hash removed, " + "1 entry removed, the format cannot state them, " + "1 md5 list written, any listed value passes", + ) + self.assertEqual( + change_text(report), + "519 entries kept, 1 file added, 1 hash updated, " + "1 required flag aligned with the code, 1 hash added, 1 size updated, " + "1 size removed, 1 hash removed, " + "1 entry not written, the format cannot state them, " + "1 md5 list written, any listed value passes", + ) + def test_no_wording_that_judges_the_original(self): report = _report("batocera", ["batocera-systems"], hashes_updated=["a md5"]) - report["counts"] = {"kept": 1, "added": 0, "not_added": 4, "not_kept": 1} + report["counts"] = _counts(kept=1, not_added=4, not_kept=1, hash_updated=1) page = generate_exports_page([report], {}).lower() for word in ("their file", "theirs", "corrected", "wrong", "drift", "left out"): self.assertNotIn(word, page)