refactor: harden codebase and remove unicode artifacts

- fix urllib.parse.quote import (was urllib.request.quote)
- add operator precedence parens in generate_pack dedup check
- narrow bare except to specific types in batocera target scraper
- cache load_platform_config and build_zip_contents_index results
- add selective algorithm support to compute_hashes
- atomic write for fetch_large_file (tmp + rename)
- add response size limit to base scraper fetch
- extract build_target_cores_cache to common.py (dedup verify/pack)
- hoist _build_supplemental_index out of per-platform loop
- migrate function-attribute caches to module-level dicts
- add @abstractmethod to BaseTargetScraper.fetch_targets
- remove backward-compat re-exports from common.py
- replace em-dashes and unicode arrows with ASCII equivalents
- remove decorative section dividers and obvious comments
This commit is contained in:
Abdessamad Derraz
2026-03-29 23:15:20 +02:00
parent 0c5cde83e1
commit 2e21d64a08
17 changed files with 102 additions and 165 deletions

View File

@@ -24,12 +24,12 @@ SOURCE_URL = (
# Libretro cores that expect BIOS files in a subdirectory of system/.
# System.dat lists filenames flat; the scraper prepends the prefix.
# ref: each core's libretro.c or equivalent see platforms/README.md
# ref: each core's libretro.c or equivalent -see platforms/README.md
CORE_SUBDIR_MAP = {
"nec-pc-98": "np2kai", # libretro-np2kai/sdl/libretro.c
"sharp-x68000": "keropi", # px68k/libretro/libretro.c
"sega-dreamcast": "dc", # flycast/shell/libretro/libretro.cpp
"sega-dreamcast-arcade": "dc", # flycast same subfolder
"sega-dreamcast-arcade": "dc", # flycast -same subfolder
}
SYSTEM_SLUG_MAP = {
@@ -254,7 +254,7 @@ class Scraper(BaseScraper):
systems[req.system]["files"].append(entry)
# Systems not in System.dat but needed for RetroArch added via
# Systems not in System.dat but needed for RetroArch -added via
# shared groups in _shared.yml. The includes directive is resolved
# at load time by load_platform_config().
EXTRA_SYSTEMS = {
@@ -264,7 +264,7 @@ class Scraper(BaseScraper):
"manufacturer": "NEC",
"docs": "https://docs.libretro.com/library/quasi88/",
},
# ref: Vircon32/libretro.c virtual console, single BIOS
# ref: Vircon32/libretro.c -virtual console, single BIOS
"vircon32": {
"files": [
{"name": "Vircon32Bios.v32", "destination": "Vircon32Bios.v32", "required": True},
@@ -273,7 +273,7 @@ class Scraper(BaseScraper):
"manufacturer": "Vircon",
"docs": "https://docs.libretro.com/library/vircon32/",
},
# ref: xrick/src/sysvid.c, xrick/src/data.c game data archive
# ref: xrick/src/sysvid.c, xrick/src/data.c -game data archive
"xrick": {
"files": [
{"name": "data.zip", "destination": "xrick/data.zip", "required": True},
@@ -290,7 +290,7 @@ class Scraper(BaseScraper):
# Arcade BIOS present in the repo but absent from System.dat.
# FBNeo expects them in system/ or system/fbneo/.
# ref: fbneo/src/burner/libretro/libretro.cpp
# ref: fbneo/src/burner/libretro/libretro.cpp search order:
# ref: fbneo/src/burner/libretro/libretro.cpp -search order:
# 1) romset dir 2) system/fbneo/ 3) system/
EXTRA_ARCADE_FILES = [
{"name": "namcoc69.zip", "destination": "namcoc69.zip", "required": True},
@@ -329,33 +329,33 @@ class Scraper(BaseScraper):
# Extra files missing from System.dat for specific systems.
# Each traced to the core's source code.
EXTRA_SYSTEM_FILES = {
# melonDS DS DSi mode ref: JesseTG/melonds-ds/src/libretro.cpp
# melonDS DS DSi mode -ref: JesseTG/melonds-ds/src/libretro.cpp
"nintendo-ds": [
{"name": "dsi_bios7.bin", "destination": "dsi_bios7.bin", "required": True},
{"name": "dsi_bios9.bin", "destination": "dsi_bios9.bin", "required": True},
{"name": "dsi_firmware.bin", "destination": "dsi_firmware.bin", "required": True},
{"name": "dsi_nand.bin", "destination": "dsi_nand.bin", "required": True},
],
# bsnes SGB naming ref: bsnes/target-libretro/libretro.cpp
# bsnes SGB naming -ref: bsnes/target-libretro/libretro.cpp
"nintendo-sgb": [
{"name": "sgb.boot.rom", "destination": "sgb.boot.rom", "required": False},
],
# JollyCV ref: jollycv/libretro.c
# JollyCV -ref: jollycv/libretro.c
"coleco-colecovision": [
{"name": "BIOS.col", "destination": "BIOS.col", "required": True},
{"name": "coleco.rom", "destination": "coleco.rom", "required": True},
{"name": "bioscv.rom", "destination": "bioscv.rom", "required": True},
],
# Kronos ST-V ref: libretro-kronos/libretro/libretro.c
# Kronos ST-V -ref: libretro-kronos/libretro/libretro.c
"sega-saturn": [
{"name": "stvbios.zip", "destination": "kronos/stvbios.zip", "required": True},
],
# PCSX ReARMed / Beetle PSX alt BIOS ref: pcsx_rearmed/libpcsxcore/misc.c
# PCSX ReARMed / Beetle PSX alt BIOS -ref: pcsx_rearmed/libpcsxcore/misc.c
# docs say PSXONPSP660.bin (uppercase) but core accepts any case
"sony-playstation": [
{"name": "psxonpsp660.bin", "destination": "psxonpsp660.bin", "required": False},
],
# Dolphin GC ref: DolphinLibretro/Boot.cpp:72-73,
# Dolphin GC -ref: DolphinLibretro/Boot.cpp:72-73,
# BootManager.cpp:200-217, CommonPaths.h:139 GC_IPL="IPL.bin"
# Core searches system/dolphin-emu/Sys/ for data and BIOS.
# System.dat gc-ntsc-*.bin names are NOT what Dolphin loads.
@@ -364,15 +364,15 @@ class Scraper(BaseScraper):
{"name": "gc-ntsc-12.bin", "destination": "dolphin-emu/Sys/GC/USA/IPL.bin", "required": False},
{"name": "gc-pal-12.bin", "destination": "dolphin-emu/Sys/GC/EUR/IPL.bin", "required": False},
{"name": "gc-ntsc-12.bin", "destination": "dolphin-emu/Sys/GC/JAP/IPL.bin", "required": False},
# DSP firmware ref: Source/Core/Core/HW/DSPLLE/DSPHost.cpp
# DSP firmware -ref: Source/Core/Core/HW/DSPLLE/DSPHost.cpp
{"name": "dsp_coef.bin", "destination": "dolphin-emu/Sys/GC/dsp_coef.bin", "required": True},
{"name": "dsp_rom.bin", "destination": "dolphin-emu/Sys/GC/dsp_rom.bin", "required": True},
# Fonts ref: Source/Core/Core/HW/EXI/EXI_DeviceIPL.cpp
# Fonts -ref: Source/Core/Core/HW/EXI/EXI_DeviceIPL.cpp
{"name": "font_western.bin", "destination": "dolphin-emu/Sys/GC/font_western.bin", "required": False},
{"name": "font_japanese.bin", "destination": "dolphin-emu/Sys/GC/font_japanese.bin", "required": False},
],
# minivmac casing ref: minivmac/src/MYOSGLUE.c
# doc says MacII.rom, repo has MacII.ROM both work on case-insensitive FS
# minivmac casing -ref: minivmac/src/MYOSGLUE.c
# doc says MacII.rom, repo has MacII.ROM -both work on case-insensitive FS
"apple-macintosh-ii": [
{"name": "MacII.ROM", "destination": "MacII.ROM", "required": True},
],
@@ -398,7 +398,7 @@ class Scraper(BaseScraper):
# Inject shared group references for systems that have core-specific
# subdirectory requirements already defined in _shared.yml.
# Note: fuse/ prefix NOT injected for sinclair-zx-spectrum.
# Verified in fuse-libretro/src/compat/paths.c core searches
# Verified in fuse-libretro/src/compat/paths.c -core searches
# system/ flat, not fuse/ subfolder. Docs are wrong on this.
SYSTEM_SHARED_GROUPS = {
"nec-pc-98": ["np2kai"],
@@ -421,12 +421,12 @@ class Scraper(BaseScraper):
{"ref": "ppsspp-assets", "destination": "PPSSPP"},
],
# single buildbot ZIP contains both Databases/ and Machines/
# ref: libretro.c:1118-1119 system_dir/Machines + system_dir/Databases
# ref: libretro.c:1118-1119 -system_dir/Machines + system_dir/Databases
"microsoft-msx": [
{"ref": "bluemsx", "destination": ""},
],
# FreeIntv overlays system/freeintv_overlays/<rom>.png
# ref: FreeIntv/src/libretro.c:273 stbi_load from system dir
# FreeIntv overlays -system/freeintv_overlays/<rom>.png
# ref: FreeIntv/src/libretro.c:273 -stbi_load from system dir
# ZIP contains FreeIntvTS_Overlays/ subfolder, cache preserves it
# pack destination maps cache root to system/freeintv_overlays
# so final path is system/freeintv_overlays/FreeIntvTS_Overlays/<rom>.png

View File

@@ -171,7 +171,7 @@ def _resolve_path(p: str) -> str:
def _extract_bios_entries(component_val: dict) -> list[dict]:
"""Extract BIOS entries from all three possible locations in a component.
No dedup here dedup is done in fetch_requirements() with full
No dedup here -dedup is done in fetch_requirements() with full
(system, filename) key to avoid dropping valid same-filename entries
across different systems.
"""
@@ -338,13 +338,13 @@ class Scraper(BaseScraper):
if resolved.startswith("saves"):
continue
# Build destination default to bios/ if no path specified
# Build destination -default to bios/ if no path specified
if resolved:
destination = f"{resolved}/{filename}"
else:
destination = f"bios/{filename}"
# MD5 handling sanitize upstream errors
# MD5 handling -sanitize upstream errors
md5_raw = entry.get("md5", "")
if isinstance(md5_raw, list):
parts = [str(m).strip().lower() for m in md5_raw if m]

View File

@@ -136,7 +136,7 @@ def _check_atom(tokens: list[str], pos: int, active: frozenset[str]) -> tuple[bo
if tok.startswith('"'):
pos += 1
return True, pos
# Unknown token treat as true to avoid false negatives
# Unknown token -treat as true to avoid false negatives
pos += 1
return True, pos

View File

@@ -1,8 +1,8 @@
"""Scraper for EmuDeck emulator targets.
Sources:
SteamOS: dragoonDorise/EmuDeck functions/EmuScripts/*.sh
Windows: EmuDeck/emudeck-we functions/EmuScripts/*.ps1
SteamOS: dragoonDorise/EmuDeck -functions/EmuScripts/*.sh
Windows: EmuDeck/emudeck-we -functions/EmuScripts/*.ps1
"""
from __future__ import annotations

View File

@@ -56,7 +56,7 @@ TARGETS: list[tuple[str, str, str]] = [
("nintendo/wiiu/latest", "nintendo-wiiu", "ppc"),
("playstation/ps2/latest", "playstation-ps2", "mips"),
("playstation/psp/latest", "playstation-psp", "mips"),
# vita: only VPK bundles on buildbot cores listed via libretro-super recipes
# vita: only VPK bundles on buildbot -cores listed via libretro-super recipes
]
# Recipe-based targets: (recipe_path_under_RECIPE_BASE_URL, target_name, architecture)