refactor: read mame release tags in the model

The tag and version helpers lived in the romset DAT importer, so the site cards, which may not import a scraper, matched the label with their own pattern. model.mamerelease now owns mame_tag, mame_version and tag_version. Both scrapers and the cards call it. check_freshness only lifts tags out of labels and converts nothing, so it keeps its own search.
This commit is contained in:
Abdessamad Derraz committed 2026-11-21 10:30:22 +01:00
1 parent 8a8fa71fbc
commit 4acfd8f763
7 files changed
+41 -19

No files matched your search

+27
View File
@@ -0,0 +1,27 @@
"""MAME versions and the mamedev/mame release tags that name them."""
from __future__ import annotations
def mame_tag(version: str) -> str:
"""The mamedev/mame release tag of a version: 0.289 is mame0289."""
return "mame" + version.replace(".", "").zfill(4)
def tag_version(tag: str) -> str | None:
"""The version a mamedev/mame release tag names, None for anything else.
Release tags carry four digits or more (mame0121 is the first on GitHub).
"""
raw = tag.removeprefix("mame")
if raw.isdigit() and len(raw) >= 4:
return f"{raw[0]}.{raw[1:]}"
return None
def mame_version(tag: str) -> str:
"""The version a mamedev/mame release tag names: mame0289 is 0.289.
Anything else (a branch, a commit) is returned without its prefix.
"""
return tag_version(tag) or tag.removeprefix("mame")
+2 -1
View File
@@ -59,7 +59,8 @@ from core.upstream import parse_repo
from .base_scraper import BlobMismatchError, download, fetch_verified_blob
from .clex import DriverSourceError, blank_comments, call_args, call_span
from .listxml import Opener, attrs, iter_elements, open_listxml, rom_members
from .romset_dat_importer import MAME_LISTXML_URL, _api_json, fetch_pack, mame_tag
from model.mamerelease import mame_tag
from .romset_dat_importer import MAME_LISTXML_URL, _api_json, fetch_pack
SCHEMA_VERSION = 1
DEFAULT_OUTPUT = Path("games") / "arcade"
+2 -1
View File
@@ -53,7 +53,8 @@ from .mame_devices import (
source_path,
)
from .listxml import open_listxml
from .romset_dat_importer import fetch_pack, mame_tag, mame_version
from model.mamerelease import mame_tag, mame_version
from .romset_dat_importer import fetch_pack
from .sparse_clone import fresh_cache, remove_clone, sparse_clone
from .mame_parser import parse_mame_source_tree
from core.paths import EMULATORS_DIR, PLATFORMS_DIR, REPO_ROOT
-14
View File
@@ -400,20 +400,6 @@ MAME_LISTXML_URL = (
MAME_REPO = "mamedev/mame"
def mame_tag(version: str) -> str:
"""The mamedev/mame release tag of a version: 0.289 is mame0289."""
return "mame" + version.replace(".", "").zfill(4)
def mame_version(tag: str) -> str:
"""The version a mamedev/mame release tag names: mame0289 is 0.289.
Anything else (a branch, a commit) is returned as it is.
"""
raw = tag.removeprefix("mame")
if raw.isdigit() and len(raw) >= 4:
return f"{raw[0]}.{raw[1:]}"
return raw
FBNEO_REPO = "libretro/FBNeo"
FBNEO_API = f"https://api.github.com/repos/{FBNEO_REPO}"
+6 -2
View File
@@ -17,6 +17,7 @@ from packs.crossref import FileConsumers
from romrecipes.romsets import dat_snapshots, usable_recipe
from sitegen import markup, wanted as sitewanted
from core.paths import REPO_ROOT
from model.mamerelease import tag_version
from sitegen.fields import search_excluded
from sitegen.install import manifest_systems, platform_display
from sitegen.render import (
@@ -307,8 +308,11 @@ Release = tuple[int, str]
def _release_name(source: str, label: str, versions: dict) -> str:
""""MAME mame0220" as "0.220", an FBNeo DAT title as its version."""
match = re.fullmatch(r"MAME mame(\d)(\d+)", label) if source == "mame" else None
return f"{match[1]}.{match[2]}" if match else str(versions.get(label) or label)
if source == "mame" and label.startswith("MAME mame"):
version = tag_version(label.removeprefix("MAME "))
if version:
return version
return str(versions.get(label) or label)
@functools.lru_cache(maxsize=1)