fix: emulator JSON-LD names every repository read

The structured data of an emulator page published one repository and one commit. A profile whose builds live in two repositories, or a port with an upstream_commit, now lists each repository with its own pin.
This commit is contained in:
Abdessamad Derraz committed 2026-10-20 06:17:40 +02:00
1 parent 08396be3c6
commit 1bbb1d4749
2 files changed
+40 -15

No files matched your search

+24 -15
View File
@@ -1498,21 +1498,30 @@ def emulator_structured_data(profile: dict) -> dict:
the core loads, their hashes, the source read or when.
"""
data: dict = {}
source = profile.get("source")
if isinstance(source, dict):
source = next(iter(source.values()), "")
commit = profile.get("source_commit")
if isinstance(commit, dict):
commit = next(iter(commit.values()), "")
if source:
about = {
"@type": "SoftwareSourceCode",
"name": str(profile.get("emulator", "")),
"codeRepository": str(source),
}
if commit:
about["version"] = str(commit)
data["about"] = about
# Every repository the profile reads, each with its own pin: xemu's
# libretro build lives in another repository at another commit, and a
# port's upstream_commit was never published.
about = []
seen: set[str] = set()
for field in ("source", "upstream"):
urls = profile.get(field)
pins = profile.get(f"{field}_commit")
for mode, url in (urls.items() if isinstance(urls, dict) else [("", urls)]):
if not url or not str(url).startswith("http") or str(url) in seen:
continue
seen.add(str(url))
pin = pins.get(mode) if isinstance(pins, dict) else pins
entry = {
"@type": "SoftwareSourceCode",
"name": str(profile.get("emulator", "")),
"codeRepository": str(url),
"description": " ".join(filter(None, [mode, field])),
}
if pin:
entry["version"] = str(pin)
about.append(entry)
if about:
data["about"] = about[0] if len(about) == 1 else about
if profile.get("profiled_date"):
data["dateModified"] = str(profile["profiled_date"])
parts = []
+16
View File
@@ -4125,6 +4125,22 @@ class EmulatorPagesStateTheirDataForMachines(unittest.TestCase):
self.assertEqual(data["hasPart"][0]["identifier"], ["sha1:" + "a" * 40, "md5:490f666e"])
self.assertNotIn("identifier", data["hasPart"][1])
def test_every_repository_with_its_own_pin(self):
"""xemu's libretro build lives in another repository at another
commit, and a port's upstream_commit was never published."""
from scripts.generate_site import emulator_structured_data
data = emulator_structured_data({
"emulator": "xemu",
"source": {"standalone": "https://github.com/xemu-project/xemu",
"libretro": "https://github.com/LibretroAdmin/xemu-libretro"},
"source_commit": {"standalone": "f9b14039", "libretro": "d9804db7"},
"upstream": "https://github.com/mborgerson/xemu", "upstream_commit": "aa11",
})
self.assertEqual(
[(a["codeRepository"].rsplit("/", 1)[1], a.get("version")) for a in data["about"]],
[("xemu", "f9b14039"), ("xemu-libretro", "d9804db7"), ("xemu", "aa11")])
class AManifestHashesAFileOnce(unittest.TestCase):