mirror of
https://github.com/Abdess/retroarch_system.git
synced 2026-10-19 01:43:25 -05:00
refactor: annotate every remaining signature
This commit is contained in:
1 parent
5961b6bfe7
commit
faa8af0800
52 files changed
+261
-145
No files matched your search
@@ -537,7 +537,7 @@ def _append_new_entries(text: str, files: list[dict], original: str) -> str:
|
||||
return text
|
||||
|
||||
|
||||
def _yaml_scalar(value) -> str:
|
||||
def _yaml_scalar(value: object) -> str:
|
||||
"""Quote a scalar so YAML reads back exactly what the source said.
|
||||
|
||||
A MAME ROM named ``01`` written bare re-parses as the integer 1, and the
|
||||
|
||||
@@ -163,7 +163,7 @@ def fetch_bytes(
|
||||
class BaseScraper(ABC):
|
||||
"""Abstract base class for platform BIOS requirement scrapers."""
|
||||
|
||||
def __init__(self, url: str = ""):
|
||||
def __init__(self, url: str = "") -> None:
|
||||
self.url = url
|
||||
self._raw_data: str | None = None
|
||||
|
||||
|
||||
@@ -249,7 +249,7 @@ def _resolve_truncated_md5(md5: str, md5_index: dict[str, str]) -> str:
|
||||
class Scraper(BaseScraper):
|
||||
"""Scraper for batocera-systems Python dict."""
|
||||
|
||||
def __init__(self):
|
||||
def __init__(self) -> None:
|
||||
self.tag = fetch_stable_tag()
|
||||
super().__init__(url=SOURCE_URL.format(tag=self.tag))
|
||||
|
||||
@@ -466,7 +466,7 @@ class Scraper(BaseScraper):
|
||||
return result
|
||||
|
||||
|
||||
def main():
|
||||
def main() -> None:
|
||||
from scripts.scraper.base_scraper import scraper_cli
|
||||
|
||||
scraper_cli(Scraper, "Scrape batocera BIOS requirements")
|
||||
|
||||
@@ -331,7 +331,7 @@ def parse_firmware_database(
|
||||
class Scraper(BaseScraper):
|
||||
"""BizHawk firmware database scraper."""
|
||||
|
||||
def __init__(self):
|
||||
def __init__(self) -> None:
|
||||
self.tag = fetch_github_latest_version(GITHUB_REPO)
|
||||
super().__init__(url=SOURCE_URL.format(tag=self.tag))
|
||||
|
||||
@@ -386,7 +386,7 @@ class Scraper(BaseScraper):
|
||||
}
|
||||
|
||||
|
||||
def main():
|
||||
def main() -> None:
|
||||
scraper_cli(Scraper, "Scrape BizHawk BIOS requirements")
|
||||
|
||||
|
||||
|
||||
@@ -206,7 +206,7 @@ def _extract_md5_from_notes(info: dict) -> dict[str, str]:
|
||||
class Scraper(BaseScraper):
|
||||
"""Scraper for libretro-core-info firmware declarations."""
|
||||
|
||||
def __init__(self):
|
||||
def __init__(self) -> None:
|
||||
super().__init__()
|
||||
self._info_files: dict[str, dict] | None = None
|
||||
|
||||
@@ -303,7 +303,7 @@ class Scraper(BaseScraper):
|
||||
return {"version": version}
|
||||
|
||||
|
||||
def main():
|
||||
def main() -> None:
|
||||
"""CLI entry point."""
|
||||
import argparse
|
||||
|
||||
|
||||
@@ -16,6 +16,7 @@ from __future__ import annotations
|
||||
import argparse
|
||||
import sys
|
||||
import zipfile
|
||||
from collections.abc import Iterator
|
||||
from datetime import datetime, timezone
|
||||
from pathlib import Path
|
||||
|
||||
@@ -50,7 +51,7 @@ def _bios_entries(source: str, dat: LogiqxDat) -> list[dict]:
|
||||
]
|
||||
|
||||
|
||||
def _iter_dat_contents(pack: Path):
|
||||
def _iter_dat_contents(pack: Path) -> Iterator[tuple[str, bytes]]:
|
||||
"""Yield (member name, content bytes) for DAT files in a pack.
|
||||
|
||||
Accepts a ZIP archive or a directory of extracted DATs.
|
||||
|
||||
@@ -221,7 +221,7 @@ class Scraper(BaseScraper):
|
||||
|
||||
def __init__(
|
||||
self, checkbios_url: str = CHECKBIOS_URL, csv_base_url: str = CSV_BASE_URL
|
||||
):
|
||||
) -> None:
|
||||
super().__init__(url=checkbios_url)
|
||||
self.checkbios_url = checkbios_url
|
||||
self.csv_base_url = csv_base_url
|
||||
@@ -492,7 +492,7 @@ class Scraper(BaseScraper):
|
||||
return sorted(cores)
|
||||
|
||||
|
||||
def main():
|
||||
def main() -> None:
|
||||
from scripts.scraper.base_scraper import scraper_cli
|
||||
|
||||
scraper_cli(Scraper, "Scrape emudeck BIOS requirements")
|
||||
|
||||
@@ -125,7 +125,7 @@ def _core_info_files() -> list[str]:
|
||||
class Scraper(BaseScraper):
|
||||
"""Scraper for libretro System.dat."""
|
||||
|
||||
def __init__(self, url: str = SOURCE_URL):
|
||||
def __init__(self, url: str = SOURCE_URL) -> None:
|
||||
super().__init__(url=url)
|
||||
|
||||
def fetch_requirements(self) -> list[BiosRequirement]:
|
||||
@@ -516,7 +516,7 @@ class Scraper(BaseScraper):
|
||||
}
|
||||
|
||||
|
||||
def main():
|
||||
def main() -> None:
|
||||
from scripts.scraper.base_scraper import scraper_cli
|
||||
|
||||
scraper_cli(Scraper, "Scrape libretro BIOS requirements")
|
||||
|
||||
@@ -126,7 +126,7 @@ def system_of(path: str) -> str:
|
||||
class Scraper(BaseScraper):
|
||||
"""Scraper for the MiSTer BiosDB database."""
|
||||
|
||||
def __init__(self, url: str = SOURCE_URL):
|
||||
def __init__(self, url: str = SOURCE_URL) -> None:
|
||||
super().__init__(url=url)
|
||||
|
||||
def _fetch_raw(self) -> str:
|
||||
|
||||
@@ -199,7 +199,7 @@ def board_cores(text: str, board: str, enabled: set[str]) -> set[str]:
|
||||
class Scraper(BaseScraper):
|
||||
"""Scraper for Recalbox es_bios.xml."""
|
||||
|
||||
def __init__(self, tag: str | None = None):
|
||||
def __init__(self, tag: str | None = None) -> None:
|
||||
# A target scraper passes the tag platforms/recalbox.yml pins.
|
||||
self.tag = tag or _fetch_gitlab_stable_tag()
|
||||
super().__init__(url=SOURCE_URL.format(tag=self.tag))
|
||||
@@ -365,7 +365,7 @@ class Scraper(BaseScraper):
|
||||
}
|
||||
|
||||
|
||||
def main():
|
||||
def main() -> None:
|
||||
"""CLI entry point."""
|
||||
from .base_scraper import scraper_cli
|
||||
|
||||
|
||||
@@ -88,7 +88,7 @@ SYSTEM_SLUG_MAP = {
|
||||
class Scraper(BaseScraper):
|
||||
"""Scraper for RetroBat batocera-systems.json."""
|
||||
|
||||
def __init__(self, url: str = SOURCE_URL):
|
||||
def __init__(self, url: str = SOURCE_URL) -> None:
|
||||
super().__init__(url=url)
|
||||
self._parsed: dict | None = None
|
||||
|
||||
@@ -227,7 +227,7 @@ class Scraper(BaseScraper):
|
||||
}
|
||||
|
||||
|
||||
def main():
|
||||
def main() -> None:
|
||||
from scripts.scraper.base_scraper import scraper_cli
|
||||
|
||||
scraper_cli(Scraper, "Scrape retrobat BIOS requirements")
|
||||
|
||||
@@ -51,7 +51,7 @@ _PACKAGE_DIRS = ("emulators", "libretrocores", "ports")
|
||||
class Scraper(BaseScraper):
|
||||
"""Scraper for the RetroPie package list."""
|
||||
|
||||
def __init__(self, url: str = SOURCE_URL):
|
||||
def __init__(self, url: str = SOURCE_URL) -> None:
|
||||
super().__init__(url=url)
|
||||
self._modules: list[str] | None = None
|
||||
self._version = ""
|
||||
|
||||
@@ -147,7 +147,7 @@ def parse_systems(source: str) -> dict[str, dict]:
|
||||
class Scraper(BaseScraper):
|
||||
"""Scraper for the ROCKNIX rocknix-systems script."""
|
||||
|
||||
def __init__(self, url: str | None = None):
|
||||
def __init__(self, url: str | None = None) -> None:
|
||||
self.tag = None if url else fetch_github_latest_version(GITHUB_REPO)
|
||||
super().__init__(url=url or SOURCE_TEMPLATE.format(ref=self.tag))
|
||||
|
||||
|
||||
@@ -122,7 +122,7 @@ FIRMWARE_MIRRORS: dict[str, tuple[str, ...]] = {
|
||||
class Scraper(BaseScraper):
|
||||
"""Scraper for RomM known_bios_files.json."""
|
||||
|
||||
def __init__(self):
|
||||
def __init__(self) -> None:
|
||||
self.tag = fetch_github_latest_version(GITHUB_REPO)
|
||||
super().__init__(url=SOURCE_URL.format(tag=self.tag))
|
||||
self._parsed: dict | None = None
|
||||
@@ -225,7 +225,7 @@ class Scraper(BaseScraper):
|
||||
}
|
||||
|
||||
|
||||
def main():
|
||||
def main() -> None:
|
||||
from scripts.scraper.base_scraper import scraper_cli
|
||||
|
||||
scraper_cli(Scraper, "Scrape RomM BIOS requirements")
|
||||
|
||||
@@ -25,6 +25,7 @@ from __future__ import annotations
|
||||
|
||||
import argparse
|
||||
import hashlib
|
||||
import io
|
||||
import json
|
||||
import os
|
||||
import re
|
||||
@@ -32,6 +33,7 @@ import shutil
|
||||
import sys
|
||||
import urllib.request
|
||||
import zipfile
|
||||
from collections.abc import Callable, Iterator
|
||||
from datetime import datetime, timezone
|
||||
from pathlib import Path
|
||||
|
||||
@@ -146,7 +148,9 @@ def _machine_roms(blob: bytes) -> list[dict]:
|
||||
return members
|
||||
|
||||
|
||||
def _scan_listxml(stream, selector) -> dict[str, tuple[str | None, list[dict]]]:
|
||||
def _scan_listxml(
|
||||
stream: io.BufferedIOBase, selector: Callable[[str], bool]
|
||||
) -> dict[str, tuple[str | None, list[dict]]]:
|
||||
"""Stream a MAME -listxml document, keeping the machines *selector* wants.
|
||||
|
||||
The document is 311 MB for MAME 0.289, so it is never held whole: the
|
||||
@@ -178,7 +182,7 @@ def _scan_listxml(stream, selector) -> dict[str, tuple[str | None, list[dict]]]:
|
||||
|
||||
|
||||
def listxml_entries(
|
||||
open_stream, label: str, keep: set[str] | None
|
||||
open_stream: Callable[[], io.BufferedIOBase], label: str, keep: set[str] | None
|
||||
) -> list[dict]:
|
||||
"""Recipes from a MAME -listxml document, parents resolved.
|
||||
|
||||
@@ -291,7 +295,7 @@ def merge_snapshot(
|
||||
return write_snapshot(output, snapshot)
|
||||
|
||||
|
||||
def _iter_dat_contents(pack: Path):
|
||||
def _iter_dat_contents(pack: Path) -> Iterator[tuple[str, bytes]]:
|
||||
"""Yield (member name, content bytes) for DAT files in *pack*."""
|
||||
if pack.is_dir():
|
||||
for path in sorted(pack.rglob("*")):
|
||||
@@ -424,10 +428,10 @@ def _is_listxml(pack: Path) -> bool:
|
||||
return b"<!ELEMENT mame" in handle.read(4096)
|
||||
|
||||
|
||||
def _listxml_opener(pack: Path):
|
||||
def _listxml_opener(pack: Path) -> Callable[[], io.BufferedIOBase]:
|
||||
"""A callable giving a fresh byte stream over the listxml document."""
|
||||
if pack.suffix.lower() == ".zip":
|
||||
def opener():
|
||||
def opener() -> zipfile.ZipExtFile:
|
||||
archive = zipfile.ZipFile(pack)
|
||||
name = next(n for n in archive.namelist() if n.lower().endswith(".xml"))
|
||||
stream = archive.open(name)
|
||||
|
||||
@@ -15,7 +15,7 @@ from pathlib import Path
|
||||
class BaseTargetScraper(ABC):
|
||||
"""Base class for target scrapers."""
|
||||
|
||||
def __init__(self, url: str = ""):
|
||||
def __init__(self, url: str = "") -> None:
|
||||
self.url = url
|
||||
|
||||
@abstractmethod
|
||||
|
||||
@@ -292,7 +292,9 @@ def _arch_from_flag(flag: str) -> str:
|
||||
class Scraper(BaseTargetScraper):
|
||||
"""Cross-references Batocera boards, Config.in, and es_systems to build target lists."""
|
||||
|
||||
def __init__(self, url: str = "https://github.com/batocera-linux/batocera.linux"):
|
||||
def __init__(
|
||||
self, url: str = "https://github.com/batocera-linux/batocera.linux"
|
||||
) -> None:
|
||||
super().__init__(url=url)
|
||||
self.tag = ""
|
||||
|
||||
|
||||
@@ -90,7 +90,7 @@ def _script_to_core(filename: str) -> str | None:
|
||||
class Scraper(BaseTargetScraper):
|
||||
"""Fetches emulator lists for EmuDeck SteamOS and Windows targets."""
|
||||
|
||||
def __init__(self, url: str = "https://github.com/dragoonDorise/EmuDeck"):
|
||||
def __init__(self, url: str = "https://github.com/dragoonDorise/EmuDeck") -> None:
|
||||
super().__init__(url=url)
|
||||
|
||||
def _fetch_cores_for_target(
|
||||
|
||||
@@ -58,7 +58,7 @@ def defconfig_arch(defconfig: str) -> str:
|
||||
class Scraper(BaseTargetScraper):
|
||||
"""Per-board core lists from Recalbox's defconfigs and system.ini files."""
|
||||
|
||||
def __init__(self, url: str = "https://gitlab.com/recalbox/recalbox"):
|
||||
def __init__(self, url: str = "https://gitlab.com/recalbox/recalbox") -> None:
|
||||
super().__init__(url=url)
|
||||
|
||||
def fetch_targets(self) -> dict:
|
||||
|
||||
@@ -86,7 +86,7 @@ _CORE_NAME_RE = re.compile(r"^(.+?)_libretro")
|
||||
class Scraper(BaseTargetScraper):
|
||||
"""Fetches core lists per target from RetroArch buildbot nightly."""
|
||||
|
||||
def __init__(self, url: str = BUILDBOT_URL):
|
||||
def __init__(self, url: str = BUILDBOT_URL) -> None:
|
||||
super().__init__(url=url)
|
||||
|
||||
def _fetch_url(self, url: str) -> str:
|
||||
|
||||
@@ -113,7 +113,7 @@ def _parse_module(content: str) -> tuple[str | None, str]:
|
||||
class Scraper(BaseTargetScraper):
|
||||
"""Fetches RetroPie package availability by parsing scriptmodules."""
|
||||
|
||||
def __init__(self, url: str = GITHUB_API_URL):
|
||||
def __init__(self, url: str = GITHUB_API_URL) -> None:
|
||||
super().__init__(url=url)
|
||||
|
||||
def _list_scriptmodules(self) -> list[str]:
|
||||
|
||||
@@ -127,7 +127,7 @@ def metapackage_cores(package_mk: str, arch: str) -> list[str]:
|
||||
class Scraper(BaseTargetScraper):
|
||||
"""Per-device core lists from ROCKNIX's emulators metapackage."""
|
||||
|
||||
def __init__(self, url: str = "https://github.com/ROCKNIX/distribution"):
|
||||
def __init__(self, url: str = "https://github.com/ROCKNIX/distribution") -> None:
|
||||
super().__init__(url=url)
|
||||
self.tag = ""
|
||||
|
||||
|
||||
Reference in new issue
Block a user