mirror of
https://github.com/Abdess/retroarch_system.git
synced 2026-11-06 01:53:56 -06:00
fix: resolve the data directory source link
The Fetched from line printed source_url with {version} unsubstituted, a
404 on six pages, and Revision showed a zip's ETag as a revision. The URL
now carries the registry version, and only a git commit is shown, linked.
This commit is contained in:
1 parent
81acb00536
commit
9efb34c761
2 files changed
+58
-9
No files matched your search
@@ -4759,6 +4759,33 @@ def data_directory_revisions(data_dir: Path = _REPO_ROOT / "data") -> dict[str,
|
||||
return json.loads(path.read_text(encoding="utf-8"))
|
||||
|
||||
|
||||
_GIT_COMMIT = re.compile(r"[0-9a-f]{40}")
|
||||
_GITHUB_REPO = re.compile(r"https://github\.com/([^/]+/[^/]+)/")
|
||||
|
||||
|
||||
def data_directory_origin(entry: dict, fetched: dict) -> list[str]:
|
||||
"""Where a data directory is fetched from, and the commit the packs hold.
|
||||
|
||||
The URL is written with the `{version}` refresh_data_dirs substitutes:
|
||||
printed raw it led to a 404. A zip source records the server's ETag,
|
||||
which names no revision anyone can fetch, so only a git commit is shown.
|
||||
"""
|
||||
lines = []
|
||||
url = str(entry.get("source_url") or "")
|
||||
if url:
|
||||
url = url.replace("{version}", str(entry.get("version", "master")))
|
||||
lines.append(f"Fetched from <{url}>")
|
||||
sha = str(fetched.get("sha", "")).strip('"')
|
||||
if _GIT_COMMIT.fullmatch(sha):
|
||||
repo = _GITHUB_REPO.match(url)
|
||||
commit = f"[{_code(sha[:12])}](https://github.com/{repo.group(1)}/commit/{sha})" \
|
||||
if repo else _code(sha)
|
||||
branch = str(fetched.get("version", ""))
|
||||
lines.append(f"Revision: {commit}" + (
|
||||
f", the head of `{branch}` when fetched" if branch and branch != sha else ""))
|
||||
return lines
|
||||
|
||||
|
||||
def page_data_directories(name: str, profiles: dict) -> list[dict]:
|
||||
"""The data directories an emulator page lists.
|
||||
|
||||
@@ -10075,15 +10102,8 @@ def emulator_pages(
|
||||
if entry.get("description"):
|
||||
line += f": {entry['description']}"
|
||||
lines.append(line)
|
||||
if entry.get("source_url"):
|
||||
lines.append(f" - Fetched from <{entry['source_url']}>")
|
||||
fetched = _DATA_REVISIONS.get(ref) or {}
|
||||
if fetched.get("version") or fetched.get("sha"):
|
||||
# The URL serves whatever is current: the revision says
|
||||
# which content the packs were built from.
|
||||
revision = str(fetched.get("sha", "")).strip('"')
|
||||
lines.append(f" - Revision: {fetched.get('version', '')}"
|
||||
+ (f" ({_code(revision)})" if revision else ""))
|
||||
lines.extend(f" - {line}" for line in data_directory_origin(
|
||||
entry, _DATA_REVISIONS.get(ref) or {}))
|
||||
if dd.get("mode"):
|
||||
lines.append(f" - Read by the {dd['mode']} build only")
|
||||
if dd.get("bundled"):
|
||||
|
||||
@@ -763,5 +763,34 @@ class SmallFixes(unittest.TestCase):
|
||||
self.assertEqual(said, [])
|
||||
|
||||
|
||||
class ADataDirectoryNamesAFetchableOrigin(unittest.TestCase):
|
||||
"""pcee2's page linked github.com/PCSX2/pcsx2/archive/{version}.tar.gz,
|
||||
a 404, and buildbot zips showed `Revision: master (2047720058)`: a branch
|
||||
that means nothing for a buildbot URL and the server's ETag."""
|
||||
|
||||
def test_the_url_is_substituted_and_a_commit_is_linked(self):
|
||||
entry = {"source_url": "https://github.com/PCSX2/pcsx2/archive/{version}.tar.gz",
|
||||
"version": "6db638dc0373769b4c5d5b5dd7ed6da641b9a18e"}
|
||||
lines = gs.data_directory_origin(entry, {"sha": entry["version"],
|
||||
"version": entry["version"]})
|
||||
self.assertEqual(lines[0], "Fetched from <https://github.com/PCSX2/pcsx2/archive/"
|
||||
"6db638dc0373769b4c5d5b5dd7ed6da641b9a18e.tar.gz>")
|
||||
self.assertIn("(https://github.com/PCSX2/pcsx2/commit/6db638dc0373769b4c5d5b5dd7ed6da641b9a18e)",
|
||||
lines[1])
|
||||
self.assertNotIn("{version}", " ".join(lines))
|
||||
|
||||
def test_an_etag_is_no_revision(self):
|
||||
entry = {"source_url": "https://buildbot.libretro.com/assets/system/Dolphin.zip"}
|
||||
lines = gs.data_directory_origin(entry, {"sha": '"2047720058"', "version": "master"})
|
||||
self.assertEqual(lines, ["Fetched from <https://buildbot.libretro.com/assets/system/Dolphin.zip>"])
|
||||
|
||||
def test_every_registered_url_resolves(self):
|
||||
registry = yaml.safe_load((REPO_ROOT / "platforms" / "_data_dirs.yml").read_text())
|
||||
for ref, entry in (registry.get("data_directories") or registry).items():
|
||||
if isinstance(entry, dict):
|
||||
with self.subTest(ref=ref):
|
||||
self.assertNotIn("{", " ".join(gs.data_directory_origin(entry, {})))
|
||||
|
||||
|
||||
if __name__ == "__main__":
|
||||
unittest.main()
|
||||
Reference in new issue
Block a user