From e1bad01b827ef74a7fce1d0bf53bcaba3410c024 Mon Sep 17 00:00:00 2001 From: Abdessamad Derraz <3028866+Abdess@users.noreply.github.com> Date: Tue, 24 Nov 2026 10:20:00 +0100 Subject: [PATCH] refactor: group scraper modules by subject scraper/ held the platform scrapers next to three other subjects. The launcher readers move to scraper/launchers/ (their _launchers suffix dropped), the MAME and FBNeo hash scrapers and romset importers to scraper/arcade/, the DAT readers and dump catalog importers to scraper/dats/. The buildbot check is a freshness check and moves to freshness/buildbot.py. Every -m command, workflow job, schema description and page follows. The scraper discovery in scraper/__init__.py had no caller: the registry's scraper: field names the module, and the pages now say so. --- automation/jobs.yml | 4 +- schemas/arcade-parents.schema.json | 2 +- schemas/game-catalog.schema.json | 2 +- scripts/check_buildbot_system.py | 8 +- scripts/exporter/systemdat_exporter.py | 2 +- .../buildbot.py} | 2 +- scripts/freshness/catalogs.py | 6 +- scripts/freshness/data.py | 6 +- scripts/freshness/stalecommands.py | 4 +- scripts/orchestrate/prepare.py | 4 +- scripts/profiling/mamerefs.py | 4 +- scripts/refresh_stale.py | 6 +- scripts/resolve/launcherplaces.py | 6 +- scripts/resolve/launchers.py | 2 +- scripts/romrecipes/text.py | 2 +- scripts/schemas/games.py | 2 +- scripts/scraper/__init__.py | 58 ++++--------- scripts/scraper/amberelec_scraper.py | 4 +- scripts/scraper/arcade/__init__.py | 4 + scripts/scraper/{ => arcade}/_hash_merge.py | 0 scripts/scraper/{ => arcade}/_hash_write.py | 0 .../scraper/{ => arcade}/_mame_sections.py | 0 .../scraper/{ => arcade}/arcade_drivers.py | 2 +- .../{ => arcade}/arcade_parent_importer.py | 10 +-- scripts/scraper/{ => arcade}/arcade_sets.py | 2 +- scripts/scraper/{ => arcade}/clex.py | 0 scripts/scraper/{ => arcade}/dat_fetch.py | 2 +- .../{ => arcade}/fbneo_hash_scraper.py | 8 +- scripts/scraper/{ => arcade}/fbneo_parser.py | 0 scripts/scraper/{ => arcade}/mame_devices.py | 2 +- .../scraper/{ => arcade}/mame_hash_scraper.py | 4 +- scripts/scraper/{ => arcade}/mame_parser.py | 0 .../{ => arcade}/romset_dat_importer.py | 16 ++-- scripts/scraper/{ => arcade}/sparse_clone.py | 0 scripts/scraper/batocera_scraper.py | 4 +- scripts/scraper/bizhawk_scraper.py | 2 +- scripts/scraper/dats/__init__.py | 4 + .../scraper/{ => dats}/dat_pack_importer.py | 4 +- scripts/scraper/{ => dats}/dat_parser.py | 0 .../scraper/{ => dats}/game_dat_importer.py | 17 ++-- scripts/scraper/{ => dats}/listxml.py | 0 scripts/scraper/{ => dats}/logiqx_parser.py | 0 .../scraper/{ => dats}/redump_dat_scraper.py | 6 +- scripts/scraper/emudeck_scraper.py | 4 +- scripts/scraper/emuelec_scraper.py | 4 +- scripts/scraper/knulli_scraper.py | 8 +- scripts/scraper/launchers/__init__.py | 9 ++ .../amberelec.py} | 6 +- .../batocera.py} | 2 +- .../{ => launchers}/batocera_config_writes.py | 2 +- .../{ => launchers}/batocera_configgen.py | 2 +- .../{ => launchers}/batocera_searches.py | 2 +- .../configgen.py} | 0 .../{ => launchers}/configgen_sites.py | 2 +- .../scraper/{ => launchers}/csharp_source.py | 4 +- .../emudeck.py} | 4 +- .../emuelec.py} | 4 +- .../scraper/{ => launchers}/emuelec_runs.py | 4 +- .../knulli.py} | 13 +-- .../recalbox.py} | 2 +- .../{ => launchers}/recalbox_cascades.py | 2 +- .../{ => launchers}/recalbox_configgen.py | 2 +- .../{ => launchers}/recalbox_emulators.py | 2 +- .../retrobat.py} | 0 .../{ => launchers}/retrobat_arguments.py | 0 .../{ => launchers}/retrobat_computers.py | 0 .../{ => launchers}/retrobat_config_files.py | 0 .../retrobat_config_folders.py | 0 .../{ => launchers}/retrobat_generators.py | 0 .../{ => launchers}/retrobat_playstation.py | 8 +- .../{ => launchers}/retrobat_render.py | 0 .../scraper/{ => launchers}/retrobat_xbox.py | 9 +- .../retrodeck.py} | 0 .../retropie.py} | 0 .../{ => launchers}/retropie_reader.py | 0 .../{ => launchers}/retropie_scripts.py | 6 +- .../rocknix.py} | 4 +- .../{ => launchers}/rocknix_configs.py | 4 +- .../shell.py} | 4 +- scripts/scraper/libretro_scraper.py | 2 +- scripts/scraper/recalbox_scraper.py | 4 +- scripts/scraper/retrobat_scraper.py | 4 +- scripts/scraper/retrodeck_scraper.py | 2 +- scripts/scraper/retropie_scraper.py | 8 +- scripts/scraper/rocknix_scraper.py | 4 +- .../targets/emudeck_targets_scraper.py | 2 +- tests/launchersrecalboxsupport.py | 2 +- tests/launcherssupport.py | 2 +- tests/sources.py | 2 +- tests/test_arcade_parents.py | 10 +-- tests/test_audit_cli.py | 10 +-- tests/test_audit_project.py | 2 +- tests/test_audit_site.py | 4 +- tests/test_autorun.py | 6 +- tests/test_check_freshness.py | 11 +-- tests/test_doc_pages_rules.py | 6 +- tests/test_doc_pages_style.py | 2 +- tests/test_e2e_pack_sources.py | 8 +- tests/test_fbneo_parser.py | 2 +- tests/test_game_catalogs.py | 8 +- tests/test_hash_merge.py | 26 +++--- tests/test_launcher_evidence.py | 4 +- tests/test_launcher_layer.py | 5 +- tests/test_launcher_paths.py | 12 +-- tests/test_launchers_amberelec.py | 4 +- tests/test_launchers_batocera.py | 20 +++-- tests/test_launchers_emudeck.py | 4 +- tests/test_launchers_emuelec.py | 8 +- tests/test_launchers_knulli.py | 10 +-- tests/test_launchers_recalbox.py | 8 +- tests/test_launchers_retrobat_configs.py | 19 ++--- tests/test_launchers_retrobat_files.py | 16 ++-- tests/test_launchers_retrodeck.py | 2 +- tests/test_launchers_retropie.py | 8 +- tests/test_launchers_rocknix.py | 8 +- tests/test_lines.py | 4 +- tests/test_listxml.py | 4 +- tests/test_mame_devices.py | 16 ++-- tests/test_mame_parser.py | 6 +- tests/test_provenance.py | 6 +- tests/test_refresh_failures.py | 8 +- tests/test_refresh_stale.py | 6 +- tests/test_romset_recipes.py | 27 +++--- tests/test_scraper_contract.py | 6 +- tests/test_standalone_links.py | 23 ++++-- tests/test_target_scrapers.py | 4 +- wiki/adding-a-platform.md | 35 +++++--- wiki/adding-a-scraper.md | 46 ++++++----- wiki/architecture.md | 7 +- wiki/tools.md | 82 +++++++++++-------- 130 files changed, 445 insertions(+), 414 deletions(-) rename scripts/{scraper/buildbot_system.py => freshness/buildbot.py} (98%) create mode 100644 scripts/scraper/arcade/__init__.py rename scripts/scraper/{ => arcade}/_hash_merge.py (100%) rename scripts/scraper/{ => arcade}/_hash_write.py (100%) rename scripts/scraper/{ => arcade}/_mame_sections.py (100%) rename scripts/scraper/{ => arcade}/arcade_drivers.py (99%) rename scripts/scraper/{ => arcade}/arcade_parent_importer.py (98%) rename scripts/scraper/{ => arcade}/arcade_sets.py (99%) rename scripts/scraper/{ => arcade}/clex.py (100%) rename scripts/scraper/{ => arcade}/dat_fetch.py (99%) rename scripts/scraper/{ => arcade}/fbneo_hash_scraper.py (96%) rename scripts/scraper/{ => arcade}/fbneo_parser.py (100%) rename scripts/scraper/{ => arcade}/mame_devices.py (99%) rename scripts/scraper/{ => arcade}/mame_hash_scraper.py (99%) rename scripts/scraper/{ => arcade}/mame_parser.py (100%) rename scripts/scraper/{ => arcade}/romset_dat_importer.py (97%) rename scripts/scraper/{ => arcade}/sparse_clone.py (100%) create mode 100644 scripts/scraper/dats/__init__.py rename scripts/scraper/{ => dats}/dat_pack_importer.py (94%) rename scripts/scraper/{ => dats}/dat_parser.py (100%) rename scripts/scraper/{ => dats}/game_dat_importer.py (97%) rename scripts/scraper/{ => dats}/listxml.py (100%) rename scripts/scraper/{ => dats}/logiqx_parser.py (100%) rename scripts/scraper/{ => dats}/redump_dat_scraper.py (94%) create mode 100644 scripts/scraper/launchers/__init__.py rename scripts/scraper/{amberelec_launchers.py => launchers/amberelec.py} (99%) rename scripts/scraper/{batocera_launchers.py => launchers/batocera.py} (99%) rename scripts/scraper/{ => launchers}/batocera_config_writes.py (99%) rename scripts/scraper/{ => launchers}/batocera_configgen.py (98%) rename scripts/scraper/{ => launchers}/batocera_searches.py (99%) rename scripts/scraper/{configgen_launchers.py => launchers/configgen.py} (100%) rename scripts/scraper/{ => launchers}/configgen_sites.py (99%) rename scripts/scraper/{ => launchers}/csharp_source.py (99%) rename scripts/scraper/{emudeck_launchers.py => launchers/emudeck.py} (99%) rename scripts/scraper/{emuelec_launchers.py => launchers/emuelec.py} (99%) rename scripts/scraper/{ => launchers}/emuelec_runs.py (98%) rename scripts/scraper/{knulli_launchers.py => launchers/knulli.py} (98%) rename scripts/scraper/{recalbox_launchers.py => launchers/recalbox.py} (99%) rename scripts/scraper/{ => launchers}/recalbox_cascades.py (99%) rename scripts/scraper/{ => launchers}/recalbox_configgen.py (99%) rename scripts/scraper/{ => launchers}/recalbox_emulators.py (99%) rename scripts/scraper/{retrobat_launchers.py => launchers/retrobat.py} (100%) rename scripts/scraper/{ => launchers}/retrobat_arguments.py (100%) rename scripts/scraper/{ => launchers}/retrobat_computers.py (100%) rename scripts/scraper/{ => launchers}/retrobat_config_files.py (100%) rename scripts/scraper/{ => launchers}/retrobat_config_folders.py (100%) rename scripts/scraper/{ => launchers}/retrobat_generators.py (100%) rename scripts/scraper/{ => launchers}/retrobat_playstation.py (99%) rename scripts/scraper/{ => launchers}/retrobat_render.py (100%) rename scripts/scraper/{ => launchers}/retrobat_xbox.py (99%) rename scripts/scraper/{retrodeck_launchers.py => launchers/retrodeck.py} (100%) rename scripts/scraper/{retropie_launchers.py => launchers/retropie.py} (100%) rename scripts/scraper/{ => launchers}/retropie_reader.py (100%) rename scripts/scraper/{ => launchers}/retropie_scripts.py (99%) rename scripts/scraper/{rocknix_launchers.py => launchers/rocknix.py} (99%) rename scripts/scraper/{ => launchers}/rocknix_configs.py (99%) rename scripts/scraper/{shell_launchers.py => launchers/shell.py} (99%) diff --git a/automation/jobs.yml b/automation/jobs.yml index 47ce23a98..81b923886 100644 --- a/automation/jobs.yml +++ b/automation/jobs.yml @@ -53,9 +53,9 @@ jobs: - run: [python, scripts/refresh_stale.py, --findings, tmp/autorun/freshness.json, --only, "data,catalogs"] github_token: true - - run: [python, -m, scripts.scraper.mame_hash_scraper] + - run: [python, -m, scripts.scraper.arcade.mame_hash_scraper] github_token: true - - run: [python, -m, scripts.scraper.fbneo_hash_scraper] + - run: [python, -m, scripts.scraper.arcade.fbneo_hash_scraper] github_token: true gate: - [python, scripts/pipeline.py, --offline] diff --git a/schemas/arcade-parents.schema.json b/schemas/arcade-parents.schema.json index 7e4e0c02b..914feaa58 100644 --- a/schemas/arcade-parents.schema.json +++ b/schemas/arcade-parents.schema.json @@ -2,7 +2,7 @@ "$schema": "https://json-schema.org/draft/2020-12/schema", "$id": "https://abdess.github.io/retrobios/api/v1/schemas/arcade-parents.schema.json", "title": "RetroBIOS arcade parent index of one core version", - "description": "games/arcade/.json, written by python -m scripts.scraper.arcade_parent_importer from the DAT or the driver code the profile pins. A game set needs every BIOS set it is listed under (the romof chain read to its end) and, for the MAME family, every device set with ROMs it is listed under.", + "description": "games/arcade/.json, written by python -m scripts.scraper.arcade.arcade_parent_importer from the DAT or the driver code the profile pins. A game set needs every BIOS set it is listed under (the romof chain read to its end) and, for the MAME family, every device set with ROMs it is listed under.", "type": "object", "additionalProperties": false, "required": ["schema", "profile", "core_version", "source", "bios", "devices", "chd", "missing_parents", "no_bios", "bios_sets", "counts"], diff --git a/schemas/game-catalog.schema.json b/schemas/game-catalog.schema.json index 071407324..89c61150f 100644 --- a/schemas/game-catalog.schema.json +++ b/schemas/game-catalog.schema.json @@ -2,7 +2,7 @@ "$schema": "https://json-schema.org/draft/2020-12/schema", "$id": "https://abdess.github.io/retrobios/api/v1/schemas/game-catalog.schema.json", "title": "RetroBIOS game catalog of one system", - "description": "Games of one No-Intro or Redump DAT, keyed by what identifies a game file (games/catalogs//.json, written by python -m scripts.scraper.game_dat_importer). A row's region is the market the DAT names, never the value a core computes.", + "description": "Games of one No-Intro or Redump DAT, keyed by what identifies a game file (games/catalogs//.json, written by python -m scripts.scraper.dats.game_dat_importer). A row's region is the market the DAT names, never the value a core computes.", "type": "object", "additionalProperties": false, "required": ["source", "system", "dat", "version", "fetched_from", "fetched", "archive", "licence", "fields", "regions", "games"], diff --git a/scripts/check_buildbot_system.py b/scripts/check_buildbot_system.py index c92ef170f..290148e09 100644 --- a/scripts/check_buildbot_system.py +++ b/scripts/check_buildbot_system.py @@ -21,13 +21,7 @@ from core.cli import InputMissing from core.paths import DATA_DIRS_FILE from model.registry import data_dir_registry_at from packs.datadirs import refresh_keys -from scraper.buildbot_system import ( - check, - pending, - print_report, - unanswered, - updated, -) +from freshness.buildbot import check, pending, print_report, unanswered, updated def main() -> None: diff --git a/scripts/exporter/systemdat_exporter.py b/scripts/exporter/systemdat_exporter.py index 75e235955..88201f552 100644 --- a/scripts/exporter/systemdat_exporter.py +++ b/scripts/exporter/systemdat_exporter.py @@ -13,7 +13,7 @@ from pathlib import Path sys.path.insert(0, str(Path(__file__).resolve().parent.parent)) -from scraper.dat_parser import parse_dat +from scraper.dats.dat_parser import parse_dat from .base_exporter import BaseExporter from resolve.nativemodel import NativeFile, NativeSystem, Report diff --git a/scripts/scraper/buildbot_system.py b/scripts/freshness/buildbot.py similarity index 98% rename from scripts/scraper/buildbot_system.py rename to scripts/freshness/buildbot.py index 8406de3c1..7547c7495 100644 --- a/scripts/scraper/buildbot_system.py +++ b/scripts/freshness/buildbot.py @@ -9,7 +9,7 @@ import urllib.parse from core.forgehttp import remote_etag as get_remote_etag from core.paths import DATA_DIRS_FILE from model.registry import data_dir_registry_at, load_versions, versions_file_for -from .base_scraper import fetch_text +from scraper.base_scraper import fetch_text log = logging.getLogger(__name__) diff --git a/scripts/freshness/catalogs.py b/scripts/freshness/catalogs.py index 61e2d9702..9b93cb2fc 100644 --- a/scripts/freshness/catalogs.py +++ b/scripts/freshness/catalogs.py @@ -12,9 +12,9 @@ from pathlib import Path from core import upstream from core import forgehttp from core.paths import REPO_ROOT -from scripts.scraper import game_dat_importer -from scripts.scraper.dat_fetch import is_tracked_dat, label_version -from scripts.scraper.redump_dat_scraper import fetch_snapshot +from scripts.scraper.dats import game_dat_importer +from scripts.scraper.arcade.dat_fetch import is_tracked_dat, label_version +from scripts.scraper.dats.redump_dat_scraper import fetch_snapshot from freshness.findings import ( FBNEO_RECIPES, MAME_RECIPES, NO_INTRO_GAMES, OK, REDUMP_GAMES, SKIPPED, STALE, UNKNOWN, Finding, diff --git a/scripts/freshness/data.py b/scripts/freshness/data.py index 21c361517..088ea2bea 100644 --- a/scripts/freshness/data.py +++ b/scripts/freshness/data.py @@ -37,13 +37,13 @@ def _check_buildbot_system(platforms_dir: Path) -> Finding: The registry entries are refreshed above. An asset published since, or one the buildbot no longer serves, is only seen by reading its .index. """ - from scraper import buildbot_system + from freshness import buildbot with contextlib.redirect_stdout(io.StringIO()): - report = buildbot_system.check(str(platforms_dir / Path(DATA_DIRS_FILE).name)) + report = buildbot.check(str(platforms_dir / Path(DATA_DIRS_FILE).name)) if report.get("error"): return Finding("data", "buildbot system", UNKNOWN, detail="index unreachable") - todo = buildbot_system.pending(report) + todo = buildbot.pending(report) if not todo: return Finding("data", "buildbot system", OK) every = [f"{e['status'].lower()} {e['zip']}" for e in todo] diff --git a/scripts/freshness/stalecommands.py b/scripts/freshness/stalecommands.py index 7ff541d7d..961c98971 100644 --- a/scripts/freshness/stalecommands.py +++ b/scripts/freshness/stalecommands.py @@ -120,7 +120,7 @@ def _catalog_command(subject: str, registry: dict[str, dict]) -> list[str] | Non return [ sys.executable, "-m", - "scripts.scraper.romset_dat_importer", + "scripts.scraper.arcade.romset_dat_importer", "--source", _RECIPE_SOURCES[subject], "--fetch", @@ -130,7 +130,7 @@ def _catalog_command(subject: str, registry: dict[str, dict]) -> list[str] | Non return [ sys.executable, "-m", - "scripts.scraper.game_dat_importer", + "scripts.scraper.dats.game_dat_importer", "--source", _GAME_SOURCES[subject], "--fetch", diff --git a/scripts/orchestrate/prepare.py b/scripts/orchestrate/prepare.py index 170334b9a..6eee4eb9b 100644 --- a/scripts/orchestrate/prepare.py +++ b/scripts/orchestrate/prepare.py @@ -103,7 +103,7 @@ def refresh_steps(args: argparse.Namespace, results: dict) -> bool: # Step 2a: Refresh MAME BIOS hashes if not args.offline: ok, _ = runner.run( - [sys.executable, "-m", "scripts.scraper.mame_hash_scraper"], + [sys.executable, "-m", "scripts.scraper.arcade.mame_hash_scraper"], STEP_LABELS["mame_hashes"], ) results["mame_hashes"] = ok @@ -115,7 +115,7 @@ def refresh_steps(args: argparse.Namespace, results: dict) -> bool: # Step 2a2: Refresh FBNeo BIOS hashes if not args.offline: ok, _ = runner.run( - [sys.executable, "-m", "scripts.scraper.fbneo_hash_scraper"], + [sys.executable, "-m", "scripts.scraper.arcade.fbneo_hash_scraper"], STEP_LABELS["fbneo_hashes"], ) results["fbneo_hashes"] = ok diff --git a/scripts/profiling/mamerefs.py b/scripts/profiling/mamerefs.py index a975e171d..b018c9484 100644 --- a/scripts/profiling/mamerefs.py +++ b/scripts/profiling/mamerefs.py @@ -8,8 +8,8 @@ from dataclasses import dataclass from core import upstream from model.sources import source_yaml_file from profiling.citations import collect_citations -from scraper.clex import blank_comments -from scraper.mame_parser import MACHINE_MACROS +from scraper.arcade.clex import blank_comments +from scraper.arcade.mame_parser import MACHINE_MACROS # An optional role word names the repository the lines are in. DRIVER_REF = re.compile(r"^(?:(source|upstream) )?(src/[\w./+-]+):(\d+)$") diff --git a/scripts/refresh_stale.py b/scripts/refresh_stale.py index b5b8ff9ca..d3d73df30 100755 --- a/scripts/refresh_stale.py +++ b/scripts/refresh_stale.py @@ -23,11 +23,11 @@ Mapping (stale -> command): -o platforms/targets/.yml data/ python scripts/refresh_data_dirs.py --key --force - catalogs/mame recipes python -m scripts.scraper.romset_dat_importer + catalogs/mame recipes python -m scripts.scraper.arcade.romset_dat_importer --source mame --fetch - catalogs/fbneo recipes python -m scripts.scraper.romset_dat_importer + catalogs/fbneo recipes python -m scripts.scraper.arcade.romset_dat_importer --source fbneo --fetch - catalogs/no-intro games python -m scripts.scraper.game_dat_importer + catalogs/no-intro games python -m scripts.scraper.dats.game_dat_importer catalogs/redump games --source --fetch --refresh --floor ci/install.py pin python scripts/pin_installer.py diff --git a/scripts/resolve/launcherplaces.py b/scripts/resolve/launcherplaces.py index 7a5d14c25..d6b776849 100644 --- a/scripts/resolve/launcherplaces.py +++ b/scripts/resolve/launcherplaces.py @@ -20,8 +20,8 @@ PLACE_KINDS = ("names_searched", "fixed_name", "core_option", "links") # How each launcher extractor spells the BIOS directory in search_dir, as the # platform's own scripts name it: RetroPie's scriptmodules ($biosdir, # retropie_reader.BIOSDIR), EmuDeck's EmuScripts (${biosPath}, -# emudeck_launchers.BIOS) and RetroDECK's framework ($bios_path, -# retrodeck_launchers.BIOS). +# launchers.emudeck.BIOS) and RetroDECK's framework ($bios_path, +# launchers.retrodeck.BIOS). BIOS_ROOT_TOKENS = ("$biosdir", "${biosdir}", "${biosPath}", "$bios_path", "${bios_path}") # A path spelled from a home or filesystem root names the BIOS directory by @@ -139,7 +139,7 @@ def name_settings(record: dict, names: list[str]) -> dict[str, str]: """The setting each name of a record is written to. A record naming several files of one config spells passes_to as - describe_keys does (shell_launchers.py), "atari800.cfg ROM_OS_A_PAL, + describe_keys does (launchers/shell.py), "atari800.cfg ROM_OS_A_PAL, ROM_5200_A, ...", one key per name and in the order of the names. When the counts differ, each name keeps the whole description. """ diff --git a/scripts/resolve/launchers.py b/scripts/resolve/launchers.py index 47d0a2bd1..740de8c86 100644 --- a/scripts/resolve/launchers.py +++ b/scripts/resolve/launchers.py @@ -20,7 +20,7 @@ from resolve.launcherplaces import bios_relative, record_directories BIOS_ROOT_VARIABLES = ("$biosdir", "$home/RetroPie/BIOS", "${biosPath}", "$bios_path") # The name a platform's launch code gives its roms root: RetroDECK's -# component scripts write $roms_path (retrodeck_launchers), the setting whose +# component scripts write $roms_path (launchers/retrodeck.py), the setting whose # default is the roms root (config/retrodeck/retrodeck.json:5), RetroPie's # scriptmodules $romdir (retropie_packages.sh:47-49). ROMS_ROOT_VARIABLES = ("$roms_path", "${roms_path}", "$romdir", "${romdir}") diff --git a/scripts/romrecipes/text.py b/scripts/romrecipes/text.py index 836638e2e..2d42fa48a 100644 --- a/scripts/romrecipes/text.py +++ b/scripts/romrecipes/text.py @@ -20,7 +20,7 @@ def print_survey(result: dict) -> None: if not result["dat_recipes"]: print( " No DAT recipe: import one with " - "`python -m scripts.scraper.romset_dat_importer --source mame --fetch mame0289`" + "`python -m scripts.scraper.arcade.romset_dat_importer --source mame --fetch mame0289`" ) for problem in result.get("unreadable_archives", []): print(f" UNREADABLE: {problem}") diff --git a/scripts/schemas/games.py b/scripts/schemas/games.py index 365926b5a..d8f5107b8 100644 --- a/scripts/schemas/games.py +++ b/scripts/schemas/games.py @@ -61,7 +61,7 @@ def arcade_pin_errors() -> list[str]: f"the profile says {profile.get('core_version')!r}") if drifted: out.append(f"{label}: {'; '.join(drifted)} " - f"(python -m scripts.scraper.arcade_parent_importer --profile {doc.get('profile')})") + f"(python -m scripts.scraper.arcade.arcade_parent_importer --profile {doc.get('profile')})") return out diff --git a/scripts/scraper/__init__.py b/scripts/scraper/__init__.py index d055023f4..44a088b68 100644 --- a/scripts/scraper/__init__.py +++ b/scripts/scraper/__init__.py @@ -1,54 +1,24 @@ -"""Scraper plugin discovery module. +"""Readers of upstream sources, each written to a file of this repository. -Auto-detects *_scraper.py files and exposes their scrapers. -Each scraper module must define: - PLATFORM_NAME: str - Scraper: class inheriting BaseScraper +The `_scraper.py` modules at this level each read one platform's BIOS +list into `platforms/.yml`: the registry's `scraper:` field names +the module, and `freshness.scrapers.platform_scraper` turns it into the +command that runs it. base_scraper.py holds what they share, the network +access included. The subpackages hold the other subjects: `targets/` the +cores each hardware target ships, `romfolders/` each setup's rom folders, +`launchers/` what each platform's launch code reads and passes to a core, +`arcade/` the MAME and FBNeo hashes and romset recipes, and `dats/` the dump +catalogs read from DAT files. """ from __future__ import annotations -import importlib -import pkgutil import sys from pathlib import Path -# Scrapers run both as `python -m scripts.scraper.x` and as plain scripts, and -# they share helpers with the rest of scripts/. Putting that directory on the -# path once here is what lets every submodule say `from core.cli import ...` -# instead of carrying its own bootstrap. +# Scrapers run both as `python -m scripts.scraper.` and as plain +# scripts, and they share helpers with the rest of scripts/. Putting that +# directory on the path once here is what lets every submodule say +# `from core.cli import ...` instead of carrying its own bootstrap. if (_SCRIPTS_DIR := str(Path(__file__).resolve().parent.parent)) not in sys.path: sys.path.insert(0, _SCRIPTS_DIR) - -from .base_scraper import BaseScraper - -_scrapers: dict[str, type] = {} - - -def discover_scrapers() -> dict[str, type]: - """Auto-discover all *_scraper.py modules and return {platform_name: ScraperClass}.""" - if _scrapers: - return _scrapers - - package_dir = Path(__file__).parent - - for _finder, name, _ispkg in pkgutil.iter_modules([str(package_dir)]): - if not name.endswith("_scraper"): - continue - - module = importlib.import_module(f".{name}", package=__package__) - - platform_name = getattr(module, "PLATFORM_NAME", None) - scraper_class = getattr(module, "Scraper", None) - - if platform_name and scraper_class and issubclass(scraper_class, BaseScraper): - _scrapers[platform_name] = scraper_class - - return _scrapers - - -def get_scraper(platform_name: str) -> BaseScraper | None: - """Get an instantiated scraper for a platform.""" - scrapers = discover_scrapers() - cls = scrapers.get(platform_name) - return cls() if cls else None diff --git a/scripts/scraper/amberelec_scraper.py b/scripts/scraper/amberelec_scraper.py index df3851d80..887f26ab5 100644 --- a/scripts/scraper/amberelec_scraper.py +++ b/scripts/scraper/amberelec_scraper.py @@ -24,7 +24,7 @@ Verification (batocera-systems at that commit): `--strictfilter`, which the script's argument switch (lines 665-687) does not handle: that call prints nothing and exits 0. -The launcher layer is read at the same commit (amberelec_launchers): runemu.py, +The launcher layer is read at the same commit (launchers/amberelec.py): runemu.py, the scripts its standalone table runs and the configs their packages install. """ @@ -33,7 +33,7 @@ from __future__ import annotations import re from model.targets import not_cores -from .amberelec_launchers import extract_launchers +from .launchers.amberelec import extract_launchers from .base_scraper import fetch_text, github_json from .batocera_scraper import ( SYSTEM_SLUG_MAP as BATOCERA_SLUGS, diff --git a/scripts/scraper/arcade/__init__.py b/scripts/scraper/arcade/__init__.py new file mode 100644 index 000000000..5b04c9a1b --- /dev/null +++ b/scripts/scraper/arcade/__init__.py @@ -0,0 +1,4 @@ +"""MAME and FBNeo: the BIOS set hashes read from their source, merged into the +emulator profiles, the romset recipes read from their DATs, and the BIOS set +each arcade game loads. +""" diff --git a/scripts/scraper/_hash_merge.py b/scripts/scraper/arcade/_hash_merge.py similarity index 100% rename from scripts/scraper/_hash_merge.py rename to scripts/scraper/arcade/_hash_merge.py diff --git a/scripts/scraper/_hash_write.py b/scripts/scraper/arcade/_hash_write.py similarity index 100% rename from scripts/scraper/_hash_write.py rename to scripts/scraper/arcade/_hash_write.py diff --git a/scripts/scraper/_mame_sections.py b/scripts/scraper/arcade/_mame_sections.py similarity index 100% rename from scripts/scraper/_mame_sections.py rename to scripts/scraper/arcade/_mame_sections.py diff --git a/scripts/scraper/arcade_drivers.py b/scripts/scraper/arcade/arcade_drivers.py similarity index 99% rename from scripts/scraper/arcade_drivers.py rename to scripts/scraper/arcade/arcade_drivers.py index 76d5721c2..214e3d0fb 100644 --- a/scripts/scraper/arcade_drivers.py +++ b/scripts/scraper/arcade/arcade_drivers.py @@ -10,7 +10,7 @@ from dataclasses import dataclass from pathlib import Path from .arcade_sets import SetEntry -from .base_scraper import BlobMismatchError, download +from ..base_scraper import BlobMismatchError, download from .clex import DriverSourceError, blank_comments, call_args, call_span from .dat_fetch import api_json from core.hashing import git_blob_sha diff --git a/scripts/scraper/arcade_parent_importer.py b/scripts/scraper/arcade/arcade_parent_importer.py similarity index 98% rename from scripts/scraper/arcade_parent_importer.py rename to scripts/scraper/arcade/arcade_parent_importer.py index c2e7a4543..54eb67dca 100644 --- a/scripts/scraper/arcade_parent_importer.py +++ b/scripts/scraper/arcade/arcade_parent_importer.py @@ -9,9 +9,9 @@ own archive. The answer is read at the revision the profile pins, from the DAT of the core version that runs the game where that DAT is the code's own output, and from the driver code where it is not: - python -m scripts.scraper.arcade_parent_importer --all - python -m scripts.scraper.arcade_parent_importer --profile mame2003_plus - python -m scripts.scraper.arcade_parent_importer --all --offline + python -m scripts.scraper.arcade.arcade_parent_importer --all + python -m scripts.scraper.arcade.arcade_parent_importer --profile mame2003_plus + python -m scripts.scraper.arcade.arcade_parent_importer --all --offline A BIOS set is ``isbios="yes"`` (MAME 0.139 and later, FBNeo). mame2000, mame2003 and mame2003-plus carry a DAT in metadata/ that their code has @@ -50,8 +50,8 @@ from model.profiles import load_emulator_profiles from core.cli import add_repo_inputs, run_cli from core.hashing import compute_hashes, git_blob_sha from core.upstream import parse_repo -from .base_scraper import fetch_verified_blob -from .listxml import Opener, open_listxml +from ..base_scraper import fetch_verified_blob +from ..dats.listxml import Opener, open_listxml from model.mamerelease import mame_tag from .dat_fetch import MAME_LISTXML_URL, api_json, cached_pack, fetch_pack from .arcade_drivers import driver_source_sets, fetch_driver_source diff --git a/scripts/scraper/arcade_sets.py b/scripts/scraper/arcade/arcade_sets.py similarity index 99% rename from scripts/scraper/arcade_sets.py rename to scripts/scraper/arcade/arcade_sets.py index 928e983a1..539c3032a 100644 --- a/scripts/scraper/arcade_sets.py +++ b/scripts/scraper/arcade/arcade_sets.py @@ -10,7 +10,7 @@ from typing import IO from .clex import blank_comments from .fbneo_parser import zip_name -from .listxml import Opener, attrs, iter_elements, rom_members +from ..dats.listxml import Opener, attrs, iter_elements, rom_members @dataclass diff --git a/scripts/scraper/clex.py b/scripts/scraper/arcade/clex.py similarity index 100% rename from scripts/scraper/clex.py rename to scripts/scraper/arcade/clex.py diff --git a/scripts/scraper/dat_fetch.py b/scripts/scraper/arcade/dat_fetch.py similarity index 99% rename from scripts/scraper/dat_fetch.py rename to scripts/scraper/arcade/dat_fetch.py index ed020e5bc..a31dd90e4 100644 --- a/scripts/scraper/dat_fetch.py +++ b/scripts/scraper/arcade/dat_fetch.py @@ -6,7 +6,7 @@ import re from pathlib import Path from core.hashing import git_blob_sha -from .base_scraper import ( +from ..base_scraper import ( BlobMismatchError, download, fetch_branch_head, diff --git a/scripts/scraper/fbneo_hash_scraper.py b/scripts/scraper/arcade/fbneo_hash_scraper.py similarity index 96% rename from scripts/scraper/fbneo_hash_scraper.py rename to scripts/scraper/arcade/fbneo_hash_scraper.py index 5c902d068..1b2376687 100644 --- a/scripts/scraper/fbneo_hash_scraper.py +++ b/scripts/scraper/arcade/fbneo_hash_scraper.py @@ -25,10 +25,10 @@ from model.profiles import source_yaml_paths from core.artifacts import write_text_atomic from model.safeparse import yaml_load -from scripts.scraper._hash_merge import compute_diff, load_profile, merge_fbneo_profile -from scripts.scraper._hash_write import write_fbneo_profile -from scripts.scraper.fbneo_parser import parse_fbneo_source_tree -from scripts.scraper.sparse_clone import fresh_cache, remove_clone, sparse_clone +from ._hash_merge import compute_diff, load_profile, merge_fbneo_profile +from ._hash_write import write_fbneo_profile +from .fbneo_parser import parse_fbneo_source_tree +from .sparse_clone import fresh_cache, remove_clone, sparse_clone log = logging.getLogger(__name__) diff --git a/scripts/scraper/fbneo_parser.py b/scripts/scraper/arcade/fbneo_parser.py similarity index 100% rename from scripts/scraper/fbneo_parser.py rename to scripts/scraper/arcade/fbneo_parser.py diff --git a/scripts/scraper/mame_devices.py b/scripts/scraper/arcade/mame_devices.py similarity index 99% rename from scripts/scraper/mame_devices.py rename to scripts/scraper/arcade/mame_devices.py index ed812b6ea..e2a1a16a6 100644 --- a/scripts/scraper/mame_devices.py +++ b/scripts/scraper/arcade/mame_devices.py @@ -28,7 +28,7 @@ from model.safeparse import yaml_load from ._hash_write import generated_start from .clex import blank_comments -from .listxml import LISTXML_CHUNK, attrs, iter_elements, rom_members +from ..dats.listxml import LISTXML_CHUNK, attrs, iter_elements, rom_members from .mame_parser import _collect_rom_macros, _expand_macros, _parse_rom_entries _BUILD = re.compile(rb' list[str] | None: return [WORLD] unknown = set(slugs) - REGIONS if unknown: - raise ValueError(f"region slugs {sorted(unknown)} are outside scripts/region.py") + raise ValueError(f"region slugs {sorted(unknown)} are outside scripts/model/region.py") return slugs return None diff --git a/scripts/scraper/listxml.py b/scripts/scraper/dats/listxml.py similarity index 100% rename from scripts/scraper/listxml.py rename to scripts/scraper/dats/listxml.py diff --git a/scripts/scraper/logiqx_parser.py b/scripts/scraper/dats/logiqx_parser.py similarity index 100% rename from scripts/scraper/logiqx_parser.py rename to scripts/scraper/dats/logiqx_parser.py diff --git a/scripts/scraper/redump_dat_scraper.py b/scripts/scraper/dats/redump_dat_scraper.py similarity index 94% rename from scripts/scraper/redump_dat_scraper.py rename to scripts/scraper/dats/redump_dat_scraper.py index 5af5d306d..043b30d5d 100644 --- a/scripts/scraper/redump_dat_scraper.py +++ b/scripts/scraper/dats/redump_dat_scraper.py @@ -8,8 +8,8 @@ downloads page is scanned for either shape, so new BIOS DATs are picked up without code changes. Run manually, then commit the snapshot: - python -m scripts.scraper.redump_dat_scraper --dry-run - python -m scripts.scraper.redump_dat_scraper --output provenance/redump.json + python -m scripts.scraper.dats.redump_dat_scraper --dry-run + python -m scripts.scraper.dats.redump_dat_scraper --output provenance/redump.json """ from __future__ import annotations @@ -21,7 +21,7 @@ from datetime import datetime, timezone from pathlib import Path from model.dumpcatalog import write_provenance_snapshot -from .base_scraper import fetch_bytes +from ..base_scraper import fetch_bytes from .logiqx_parser import parse_logiqx, validate_logiqx_format BASE_URL = "https://redump.info" diff --git a/scripts/scraper/emudeck_scraper.py b/scripts/scraper/emudeck_scraper.py index 8a3ad0a12..0acb158a9 100644 --- a/scripts/scraper/emudeck_scraper.py +++ b/scripts/scraper/emudeck_scraper.py @@ -25,8 +25,8 @@ from .base_scraper import ( github_json, systems_from_requirements, ) -from .emudeck_launchers import emulator_of_script, extract_launchers -from scraper.shell_launchers import RepoTree +from .launchers.emudeck import emulator_of_script, extract_launchers +from scraper.launchers.shell import RepoTree PLATFORM_NAME = "emudeck" diff --git a/scripts/scraper/emuelec_scraper.py b/scripts/scraper/emuelec_scraper.py index 52dade8bd..cfa3f6391 100644 --- a/scripts/scraper/emuelec_scraper.py +++ b/scripts/scraper/emuelec_scraper.py @@ -36,14 +36,14 @@ from .batocera_scraper import ( from .batocera_scraper import ( CheckBiosScraper, ) -from .emuelec_launchers import extract_launchers +from .launchers.emuelec import extract_launchers from .es_emulators import ( attach_system_cores, es_cores, json_systems, system_cores, ) -from scraper.shell_launchers import RepoTree +from scraper.launchers.shell import RepoTree from .emuelec_systems import ( BUILDS_OF, ES_SYSTEMS_TEMPLATE, diff --git a/scripts/scraper/knulli_scraper.py b/scripts/scraper/knulli_scraper.py index 2d9650137..083365f28 100644 --- a/scripts/scraper/knulli_scraper.py +++ b/scripts/scraper/knulli_scraper.py @@ -20,7 +20,7 @@ Verification (knulli-systems at the release tag): es_systems.yml and configgen-defaults.yml have Batocera's shape, so the cores are read with Batocera's code. The launcher layer comes from KNULLI's own -configgen package and board scripts at the same tag (knulli_launchers): +configgen package and board scripts at the same tag (launchers/knulli.py): Batocera's extractors where a generator is still Batocera's code, KNULLI's where it is older or its own. """ @@ -48,9 +48,9 @@ from .batocera_scraper import ( from .es_emulators import attach_system_cores from .es_systems import es_systems_by_system, es_systems_libretro_systems from .targets.knulli_targets_scraper import Scraper as BoardTargets -from .batocera_configgen import configs_root -from .knulli_launchers import BATOCERA_SUBMODULE, extract_launchers -from .knulli_launchers import configgen as knulli_configgen +from .launchers.batocera_configgen import configs_root +from .launchers.knulli import BATOCERA_SUBMODULE, extract_launchers +from .launchers.knulli import configgen as knulli_configgen PLATFORM_NAME = "knulli" diff --git a/scripts/scraper/launchers/__init__.py b/scripts/scraper/launchers/__init__.py new file mode 100644 index 000000000..20cdcedea --- /dev/null +++ b/scripts/scraper/launchers/__init__.py @@ -0,0 +1,9 @@ +"""The launcher layer of each platform: what its launch code looks for, under +which name and in which folder, and what it hands to the core or emulator, +read from that code at the revision the platform file pins. + +One module per platform reads its launchers (batocera.py, retrobat.py...). +configgen.py holds the record every reader returns and the errors a reader +raises when the code no longer has the shape it reads. shell.py and +csharp_source.py read the shell and C# sources several platforms share. +""" diff --git a/scripts/scraper/amberelec_launchers.py b/scripts/scraper/launchers/amberelec.py similarity index 99% rename from scripts/scraper/amberelec_launchers.py rename to scripts/scraper/launchers/amberelec.py index 14378883a..fdd902d5c 100644 --- a/scripts/scraper/amberelec_launchers.py +++ b/scripts/scraper/launchers/amberelec.py @@ -9,7 +9,7 @@ install, say which file under /storage/roms/bios is opened: yabasanshiro.sh tests saturn_bios.bin and passes it with -b, Hatari's default config names tos.img. -runemu.py is read with ast, the scripts with shell_launchers' readers. An +runemu.py is read with ast, the scripts with shell.py's readers. An extractor whose construct is gone raises instead of returning nothing. """ @@ -21,8 +21,8 @@ import re from collections.abc import Callable from typing import Any -from .configgen_launchers import Launcher, Source -from scraper.shell_launchers import ( +from .configgen import Launcher, Source +from scraper.launchers.shell import ( LauncherPatternMissing, Script, config_placement, diff --git a/scripts/scraper/batocera_launchers.py b/scripts/scraper/launchers/batocera.py similarity index 99% rename from scripts/scraper/batocera_launchers.py rename to scripts/scraper/launchers/batocera.py index 440ec0d9c..ffd307967 100644 --- a/scripts/scraper/batocera_launchers.py +++ b/scripts/scraper/launchers/batocera.py @@ -21,7 +21,7 @@ from dataclasses import dataclass from typing import Any from model.launcherrecords import emulator_names, join_emulators -from .configgen_launchers import ( +from .configgen import ( Launcher, LauncherShapeError, end_line, diff --git a/scripts/scraper/batocera_config_writes.py b/scripts/scraper/launchers/batocera_config_writes.py similarity index 99% rename from scripts/scraper/batocera_config_writes.py rename to scripts/scraper/launchers/batocera_config_writes.py index e0f71527d..64288f754 100644 --- a/scripts/scraper/batocera_config_writes.py +++ b/scripts/scraper/launchers/batocera_config_writes.py @@ -7,7 +7,7 @@ from collections.abc import Callable from .batocera_configgen import Configgen, _path_value from .batocera_searches import option_names -from .configgen_launchers import ( +from .configgen import ( Launcher, Source, _assigned_name, diff --git a/scripts/scraper/batocera_configgen.py b/scripts/scraper/launchers/batocera_configgen.py similarity index 98% rename from scripts/scraper/batocera_configgen.py rename to scripts/scraper/launchers/batocera_configgen.py index 626c219b5..f9153c129 100644 --- a/scripts/scraper/batocera_configgen.py +++ b/scripts/scraper/launchers/batocera_configgen.py @@ -10,7 +10,7 @@ from collections.abc import Callable from typing import Any from model.launcherrecords import join_emulators -from .configgen_launchers import LauncherShapeError, Source, _assigned_name, assigned_value +from .configgen import LauncherShapeError, Source, _assigned_name, assigned_value CONFIGGEN = "package/batocera/core/batocera-configgen/configgen/configgen" diff --git a/scripts/scraper/batocera_searches.py b/scripts/scraper/launchers/batocera_searches.py similarity index 99% rename from scripts/scraper/batocera_searches.py rename to scripts/scraper/launchers/batocera_searches.py index 63ca7a866..a62f651b0 100644 --- a/scripts/scraper/batocera_searches.py +++ b/scripts/scraper/launchers/batocera_searches.py @@ -5,7 +5,7 @@ from __future__ import annotations import ast from .batocera_configgen import Configgen, _config_option, _path_value -from .configgen_launchers import ( +from .configgen import ( Launcher, Source, _assigned_name, diff --git a/scripts/scraper/configgen_launchers.py b/scripts/scraper/launchers/configgen.py similarity index 100% rename from scripts/scraper/configgen_launchers.py rename to scripts/scraper/launchers/configgen.py diff --git a/scripts/scraper/configgen_sites.py b/scripts/scraper/launchers/configgen_sites.py similarity index 99% rename from scripts/scraper/configgen_sites.py rename to scripts/scraper/launchers/configgen_sites.py index 45bc58901..ddb2a081e 100644 --- a/scripts/scraper/configgen_sites.py +++ b/scripts/scraper/launchers/configgen_sites.py @@ -15,7 +15,7 @@ from dataclasses import dataclass, field from model.launcherrecords import join_emulators from .batocera_configgen import Configgen, _path_value -from .configgen_launchers import Launcher, Source, _assigned_name, end_line +from .configgen import Launcher, Source, _assigned_name, end_line def _bound(node: ast.AST) -> ast.expr | None: diff --git a/scripts/scraper/csharp_source.py b/scripts/scraper/launchers/csharp_source.py similarity index 99% rename from scripts/scraper/csharp_source.py rename to scripts/scraper/launchers/csharp_source.py index 372df357d..450f83487 100644 --- a/scripts/scraper/csharp_source.py +++ b/scripts/scraper/launchers/csharp_source.py @@ -11,8 +11,8 @@ from collections.abc import Iterator from core.lines import LineIndex from model.sourceref import span -from .configgen_launchers import LauncherPatternMissing -from .shell_launchers import merge_lines +from .configgen import LauncherPatternMissing +from .shell import merge_lines STRING = r'"((?:[^"\\\n]|\\.)*)"' diff --git a/scripts/scraper/emudeck_launchers.py b/scripts/scraper/launchers/emudeck.py similarity index 99% rename from scripts/scraper/emudeck_launchers.py rename to scripts/scraper/launchers/emudeck.py index 7658c047d..d35c73dec 100644 --- a/scripts/scraper/emudeck_launchers.py +++ b/scripts/scraper/launchers/emudeck.py @@ -14,8 +14,8 @@ import posixpath import re from collections.abc import Callable -from .configgen_launchers import Launcher -from scraper.shell_launchers import ( +from .configgen import Launcher +from scraper.launchers.shell import ( describe_keys, LauncherPatternMissing, link_record, diff --git a/scripts/scraper/emuelec_launchers.py b/scripts/scraper/launchers/emuelec.py similarity index 99% rename from scripts/scraper/emuelec_launchers.py rename to scripts/scraper/launchers/emuelec.py index fa2e58fb2..71dc155eb 100644 --- a/scripts/scraper/emuelec_launchers.py +++ b/scripts/scraper/launchers/emuelec.py @@ -16,8 +16,8 @@ import posixpath import re from collections.abc import Callable -from .configgen_launchers import Launcher -from scraper.shell_launchers import ( +from .configgen import Launcher +from scraper.launchers.shell import ( describe_keys, fixed_paths, LauncherPatternMissing, diff --git a/scripts/scraper/emuelec_runs.py b/scripts/scraper/launchers/emuelec_runs.py similarity index 98% rename from scripts/scraper/emuelec_runs.py rename to scripts/scraper/launchers/emuelec_runs.py index 484e85c60..1e1460342 100644 --- a/scripts/scraper/emuelec_runs.py +++ b/scripts/scraper/launchers/emuelec_runs.py @@ -7,8 +7,8 @@ import re from collections.abc import Iterable from dataclasses import dataclass, field -from .configgen_launchers import Launcher -from .shell_launchers import ( +from .configgen import Launcher +from .shell import ( RepoTree, Script, apply_evidence, diff --git a/scripts/scraper/knulli_launchers.py b/scripts/scraper/launchers/knulli.py similarity index 98% rename from scripts/scraper/knulli_launchers.py rename to scripts/scraper/launchers/knulli.py index 776848da2..049379a58 100644 --- a/scripts/scraper/knulli_launchers.py +++ b/scripts/scraper/launchers/knulli.py @@ -28,7 +28,7 @@ from dataclasses import dataclass import yaml from model.launcherrecords import emulator_names, join_emulators -from .batocera_launchers import ( +from .batocera import ( PATH_PATCHES, Extraction, extraction, @@ -40,13 +40,8 @@ from .batocera_launchers import ( from .batocera_config_writes import render, system_branches, melonds, mupen64plus, x16emu, xemu from .batocera_searches import duckstation, duckstation_legacy, hatari from .batocera_configgen import Configgen, _path_value -from .configgen_launchers import ( - Launcher, - LauncherShapeError, - Source, - _assigned_name, -) -from scraper.shell_launchers import LauncherPatternMissing, Script, source_ref +from .configgen import Launcher, LauncherShapeError, Source, _assigned_name +from scraper.launchers.shell import LauncherPatternMissing, Script, source_ref from .configgen_sites import ( COMMAND_NAMES, GenericSites, @@ -226,7 +221,7 @@ def _quoted(node: ast.AST) -> str | None: # libretro core options whose value names the BIOS file the core opens, -# the same two batocera_launchers.FILE_OPTIONS reads. +# the same two batocera.FILE_OPTIONS reads. FILE_OPTIONS = ("o2em_bios", "neocd_bios") diff --git a/scripts/scraper/recalbox_launchers.py b/scripts/scraper/launchers/recalbox.py similarity index 99% rename from scripts/scraper/recalbox_launchers.py rename to scripts/scraper/launchers/recalbox.py index e6a2f799e..43af50bf9 100644 --- a/scripts/scraper/recalbox_launchers.py +++ b/scripts/scraper/launchers/recalbox.py @@ -18,7 +18,7 @@ from collections.abc import Callable from typing import Any from model.launcherrecords import emulator_names, join_emulators -from .configgen_launchers import ( +from .configgen import ( Launcher, LauncherShapeError, _assigned_name, diff --git a/scripts/scraper/recalbox_cascades.py b/scripts/scraper/launchers/recalbox_cascades.py similarity index 99% rename from scripts/scraper/recalbox_cascades.py rename to scripts/scraper/launchers/recalbox_cascades.py index cde2ede32..4005b6f19 100644 --- a/scripts/scraper/recalbox_cascades.py +++ b/scripts/scraper/launchers/recalbox_cascades.py @@ -7,7 +7,7 @@ import posixpath from collections.abc import Mapping from dataclasses import dataclass, field -from .configgen_launchers import ( +from .configgen import ( Launcher, Source, _assigned_name, diff --git a/scripts/scraper/recalbox_configgen.py b/scripts/scraper/launchers/recalbox_configgen.py similarity index 99% rename from scripts/scraper/recalbox_configgen.py rename to scripts/scraper/launchers/recalbox_configgen.py index 1b710e491..cdb06bba2 100644 --- a/scripts/scraper/recalbox_configgen.py +++ b/scripts/scraper/launchers/recalbox_configgen.py @@ -8,7 +8,7 @@ import re from collections.abc import Callable, Iterable, Iterator, Mapping from typing import Any -from .configgen_launchers import LauncherShapeError, Source, _calls, assigned_value +from .configgen import LauncherShapeError, Source, _calls, assigned_value from model.launcherrecords import join_emulators diff --git a/scripts/scraper/recalbox_emulators.py b/scripts/scraper/launchers/recalbox_emulators.py similarity index 99% rename from scripts/scraper/recalbox_emulators.py rename to scripts/scraper/launchers/recalbox_emulators.py index 44dace19e..344145b08 100644 --- a/scripts/scraper/recalbox_emulators.py +++ b/scripts/scraper/launchers/recalbox_emulators.py @@ -6,7 +6,7 @@ import ast from collections.abc import Mapping from functools import partial -from .configgen_launchers import ( +from .configgen import ( Launcher, LauncherShapeError, Source, diff --git a/scripts/scraper/retrobat_launchers.py b/scripts/scraper/launchers/retrobat.py similarity index 100% rename from scripts/scraper/retrobat_launchers.py rename to scripts/scraper/launchers/retrobat.py diff --git a/scripts/scraper/retrobat_arguments.py b/scripts/scraper/launchers/retrobat_arguments.py similarity index 100% rename from scripts/scraper/retrobat_arguments.py rename to scripts/scraper/launchers/retrobat_arguments.py diff --git a/scripts/scraper/retrobat_computers.py b/scripts/scraper/launchers/retrobat_computers.py similarity index 100% rename from scripts/scraper/retrobat_computers.py rename to scripts/scraper/launchers/retrobat_computers.py diff --git a/scripts/scraper/retrobat_config_files.py b/scripts/scraper/launchers/retrobat_config_files.py similarity index 100% rename from scripts/scraper/retrobat_config_files.py rename to scripts/scraper/launchers/retrobat_config_files.py diff --git a/scripts/scraper/retrobat_config_folders.py b/scripts/scraper/launchers/retrobat_config_folders.py similarity index 100% rename from scripts/scraper/retrobat_config_folders.py rename to scripts/scraper/launchers/retrobat_config_folders.py diff --git a/scripts/scraper/retrobat_generators.py b/scripts/scraper/launchers/retrobat_generators.py similarity index 100% rename from scripts/scraper/retrobat_generators.py rename to scripts/scraper/launchers/retrobat_generators.py diff --git a/scripts/scraper/retrobat_playstation.py b/scripts/scraper/launchers/retrobat_playstation.py similarity index 99% rename from scripts/scraper/retrobat_playstation.py rename to scripts/scraper/launchers/retrobat_playstation.py index 4f6e4eb19..a8b04856c 100644 --- a/scripts/scraper/retrobat_playstation.py +++ b/scripts/scraper/launchers/retrobat_playstation.py @@ -15,7 +15,13 @@ from .csharp_source import ( _unique, source_ref, ) -from .retrobat_generators import BIOS, FEATURES, GENERATORS, launcher_record, feature_choices +from .retrobat_generators import ( + BIOS, + FEATURES, + GENERATORS, + launcher_record, + feature_choices, +) def pcsx2(sources: dict[str, Source]) -> list[Record]: diff --git a/scripts/scraper/retrobat_render.py b/scripts/scraper/launchers/retrobat_render.py similarity index 100% rename from scripts/scraper/retrobat_render.py rename to scripts/scraper/launchers/retrobat_render.py diff --git a/scripts/scraper/retrobat_xbox.py b/scripts/scraper/launchers/retrobat_xbox.py similarity index 99% rename from scripts/scraper/retrobat_xbox.py rename to scripts/scraper/launchers/retrobat_xbox.py index a46f5fe75..bd6338269 100644 --- a/scripts/scraper/retrobat_xbox.py +++ b/scripts/scraper/launchers/retrobat_xbox.py @@ -5,7 +5,14 @@ from __future__ import annotations import re from .csharp_source import Record, Source, _array_at, _strings, _unique, source_ref -from .retrobat_generators import BIOS, FEATURES, GENERATORS, joined, launcher_record, feature_choices +from .retrobat_generators import ( + BIOS, + FEATURES, + GENERATORS, + joined, + launcher_record, + feature_choices, +) from model.launcherrecords import join_emulators diff --git a/scripts/scraper/retrodeck_launchers.py b/scripts/scraper/launchers/retrodeck.py similarity index 100% rename from scripts/scraper/retrodeck_launchers.py rename to scripts/scraper/launchers/retrodeck.py diff --git a/scripts/scraper/retropie_launchers.py b/scripts/scraper/launchers/retropie.py similarity index 100% rename from scripts/scraper/retropie_launchers.py rename to scripts/scraper/launchers/retropie.py diff --git a/scripts/scraper/retropie_reader.py b/scripts/scraper/launchers/retropie_reader.py similarity index 100% rename from scripts/scraper/retropie_reader.py rename to scripts/scraper/launchers/retropie_reader.py diff --git a/scripts/scraper/retropie_scripts.py b/scripts/scraper/launchers/retropie_scripts.py similarity index 99% rename from scripts/scraper/retropie_scripts.py rename to scripts/scraper/launchers/retropie_scripts.py index c3074b13a..6534a4dc5 100644 --- a/scripts/scraper/retropie_scripts.py +++ b/scripts/scraper/launchers/retropie_scripts.py @@ -11,8 +11,8 @@ from itertools import product from pathlib import PurePosixPath from typing import Any, ClassVar -from .configgen_launchers import Launcher as ConfiggenLauncher -from .retropie_modules import module_field_lines +from .configgen import Launcher as ConfiggenLauncher +from ..retropie_modules import module_field_lines SCRIPTMODULES = "scriptmodules" @@ -479,7 +479,7 @@ def merge_records(records: list[Launcher]) -> list[Launcher]: def source_ref(lines: list[tuple[str, int]]) -> str: """`path:a-b, c` per file, in first-seen file order, adjacent lines joined.""" - # Not shell_launchers.merge_lines: joining across a one-line gap would turn + # Not shell.merge_lines: joining across a one-line gap would turn # the committed lr-prboom.sh:86, 88 of four retropie.yml records into 86-88. by_path: dict[str, list[int]] = {} for path, number in lines: diff --git a/scripts/scraper/rocknix_launchers.py b/scripts/scraper/launchers/rocknix.py similarity index 99% rename from scripts/scraper/rocknix_launchers.py rename to scripts/scraper/launchers/rocknix.py index bf3b6aa8b..a158d9a01 100644 --- a/scripts/scraper/rocknix_launchers.py +++ b/scripts/scraper/launchers/rocknix.py @@ -15,8 +15,8 @@ import posixpath import re from collections.abc import Callable -from .configgen_launchers import Launcher -from scraper.shell_launchers import ( +from .configgen import Launcher +from scraper.launchers.shell import ( describe_keys, LauncherPatternMissing, Link, diff --git a/scripts/scraper/rocknix_configs.py b/scripts/scraper/launchers/rocknix_configs.py similarity index 99% rename from scripts/scraper/rocknix_configs.py rename to scripts/scraper/launchers/rocknix_configs.py index b5bd88953..e6ae034a0 100644 --- a/scripts/scraper/rocknix_configs.py +++ b/scripts/scraper/launchers/rocknix_configs.py @@ -8,8 +8,8 @@ from collections.abc import Callable, Hashable from dataclasses import dataclass from typing import TypeVar -from .configgen_launchers import Launcher -from .shell_launchers import ( +from .configgen import Launcher +from .shell import ( FixedPaths, LauncherPatternMissing, RepoTree, diff --git a/scripts/scraper/shell_launchers.py b/scripts/scraper/launchers/shell.py similarity index 99% rename from scripts/scraper/shell_launchers.py rename to scripts/scraper/launchers/shell.py index 23edd72b4..f83a13a3e 100644 --- a/scripts/scraper/shell_launchers.py +++ b/scripts/scraper/launchers/shell.py @@ -17,8 +17,8 @@ from dataclasses import dataclass, field from model.sourceref import span -from .base_scraper import fetch_bytes, github_tree -from .configgen_launchers import Launcher, LauncherPatternMissing +from ..base_scraper import fetch_bytes, github_tree +from .configgen import Launcher, LauncherPatternMissing NAME = r"[A-Za-z_][A-Za-z0-9_]*" # A single-quoted "$" is literal: it is carried as this mark through expansion. diff --git a/scripts/scraper/libretro_scraper.py b/scripts/scraper/libretro_scraper.py index 6032dcd14..adad46345 100644 --- a/scripts/scraper/libretro_scraper.py +++ b/scripts/scraper/libretro_scraper.py @@ -17,7 +17,7 @@ from .base_scraper import ( fetch_github_latest_version, systems_from_requirements, ) -from .dat_parser import parse_dat, parse_dat_metadata, validate_dat_format +from .dats.dat_parser import parse_dat, parse_dat_metadata, validate_dat_format PLATFORM_NAME = "libretro" diff --git a/scripts/scraper/recalbox_scraper.py b/scripts/scraper/recalbox_scraper.py index ffe322a31..676d96ff6 100644 --- a/scripts/scraper/recalbox_scraper.py +++ b/scripts/scraper/recalbox_scraper.py @@ -21,8 +21,8 @@ from core import upstreamtree from model.safeparse import parse_untrusted_xml from .base_scraper import BaseScraper, BiosRequirement, fetch_bytes, systems_from_requirements -from .recalbox_launchers import SOURCE_FILES as LAUNCHER_FILES -from .recalbox_launchers import LauncherShapeError, extract_launchers +from .launchers.recalbox import SOURCE_FILES as LAUNCHER_FILES +from .launchers.recalbox import LauncherShapeError, extract_launchers from .recalbox_romfs import read_system_ini PLATFORM_NAME = "recalbox" diff --git a/scripts/scraper/retrobat_scraper.py b/scripts/scraper/retrobat_scraper.py index 1f3b3358c..3667fdd6e 100644 --- a/scripts/scraper/retrobat_scraper.py +++ b/scripts/scraper/retrobat_scraper.py @@ -24,8 +24,8 @@ from .base_scraper import ( ) from .batocera_scraper import SYSTEM_SLUG_MAP as BATOCERA_SLUGS from .es_emulators import es_cores, libretro_systems, xml_systems -from .retrobat_launchers import SOURCE_FILES as LAUNCHER_FILES -from .retrobat_launchers import extract_launchers +from .launchers.retrobat import SOURCE_FILES as LAUNCHER_FILES +from .launchers.retrobat import extract_launchers PLATFORM_NAME = "retrobat" PLATFORM_FILE = Path(__file__).resolve().parents[2] / "platforms" / "retrobat.yml" diff --git a/scripts/scraper/retrodeck_scraper.py b/scripts/scraper/retrodeck_scraper.py index 0c6cadd54..b80e9f728 100644 --- a/scripts/scraper/retrodeck_scraper.py +++ b/scripts/scraper/retrodeck_scraper.py @@ -56,7 +56,7 @@ from .base_scraper import ( md5_field, systems_from_requirements, ) -from .retrodeck_launchers import extract_launchers +from .launchers.retrodeck import extract_launchers from .romfolders.esde import command_core, esde_systems PLATFORM_NAME = "retrodeck" diff --git a/scripts/scraper/retropie_scraper.py b/scripts/scraper/retropie_scraper.py index 7f0b4a08f..e8141a671 100644 --- a/scripts/scraper/retropie_scraper.py +++ b/scripts/scraper/retropie_scraper.py @@ -16,7 +16,7 @@ RetroArch: RetroPie claimed every libretro core in existence while shipping (openmsx, pcsx2, xroar, sdltrs, amiberry and the rest). Both halves were wrong, in opposite directions. -The same scripts carry the launcher layer (retropie_launchers): where each +The same scripts carry the launcher layer (launchers/retropie.py): where each package links, copies or passes a BIOS file, what it builds and which systems it registers. """ @@ -29,9 +29,9 @@ import tarfile from collections.abc import Iterator from .base_scraper import BaseScraper, BiosRequirement, fetch_branch_head, fetch_bytes -from .retropie_scripts import SCRIPTMODULES -from .retropie_scripts import SECTIONS as PACKAGE_SECTIONS -from .retropie_launchers import extract_launchers +from .launchers.retropie_scripts import SCRIPTMODULES +from .launchers.retropie_scripts import SECTIONS as PACKAGE_SECTIONS +from .launchers.retropie import extract_launchers from .retropie_modules import module_fields PLATFORM_NAME = "retropie" diff --git a/scripts/scraper/rocknix_scraper.py b/scripts/scraper/rocknix_scraper.py index c8996584a..9d86c7568 100644 --- a/scripts/scraper/rocknix_scraper.py +++ b/scripts/scraper/rocknix_scraper.py @@ -24,8 +24,8 @@ from .base_scraper import ( fetch_text, github_json, ) -from .rocknix_launchers import extract_launchers -from scraper.shell_launchers import RepoTree +from .launchers.rocknix import extract_launchers +from scraper.launchers.shell import RepoTree from .rocknix_packages import dual_mode_emulators, standalone_emulators from .targets.rocknix_targets_scraper import Scraper as DeviceTargets diff --git a/scripts/scraper/targets/emudeck_targets_scraper.py b/scripts/scraper/targets/emudeck_targets_scraper.py index 903020bdc..885638e3b 100644 --- a/scripts/scraper/targets/emudeck_targets_scraper.py +++ b/scripts/scraper/targets/emudeck_targets_scraper.py @@ -18,7 +18,7 @@ from pathlib import Path from model.safeparse import yaml_load -from ..emudeck_launchers import SCRIPT_SUFFIXES, emulator_of_script +from ..launchers.emudeck import SCRIPT_SUFFIXES, emulator_of_script from . import BaseTargetScraper, fetch_text, forge_headers, target_cli PLATFORM_NAME = "emudeck" diff --git a/tests/launchersrecalboxsupport.py b/tests/launchersrecalboxsupport.py index b9634bc55..996b9d884 100644 --- a/tests/launchersrecalboxsupport.py +++ b/tests/launchersrecalboxsupport.py @@ -9,7 +9,7 @@ from __future__ import annotations import tests -from scraper.recalbox_configgen import ( +from scraper.launchers.recalbox_configgen import ( AMIBERRY_CONFIG, AMIBERRY_GLOBAL, AMIBERRY_KICKSTARTS, diff --git a/tests/launcherssupport.py b/tests/launcherssupport.py index ff2ce42a3..8079a0c70 100644 --- a/tests/launcherssupport.py +++ b/tests/launcherssupport.py @@ -6,7 +6,7 @@ import tests import textwrap -from scraper.csharp_source import Source +from scraper.launchers.csharp_source import Source def placed(blocks: dict[int, str]) -> str: diff --git a/tests/sources.py b/tests/sources.py index 032592db2..ad2f8fdfc 100644 --- a/tests/sources.py +++ b/tests/sources.py @@ -71,7 +71,7 @@ COMMANDS = { "commit_rules.py": ("devtools/commitrules.py",), "pr_checks.py": ("devtools/prchecks.py",), "check_buildbot_system.py": ( - "scraper/buildbot_system.py", "packs/datadirs.py", "packs/datadirextract.py", + "freshness/buildbot.py", "packs/datadirs.py", "packs/datadirextract.py", ), "generate_site.py": ( "sitegen/config.py", "sitegen/emulatorsindex.py", "sitegen/places.py", "sitegen/home.py", diff --git a/tests/test_arcade_parents.py b/tests/test_arcade_parents.py index 11a8b20ff..3c29686f2 100644 --- a/tests/test_arcade_parents.py +++ b/tests/test_arcade_parents.py @@ -11,11 +11,11 @@ import unittest import zipfile from pathlib import Path -from scripts.scraper import arcade_parent_importer as api -from scripts.scraper import arcade_drivers -from scripts.scraper import arcade_sets -from scripts.scraper import clex -from scripts.scraper import listxml +from scripts.scraper.arcade import arcade_parent_importer as api +from scripts.scraper.arcade import arcade_drivers +from scripts.scraper.arcade import arcade_sets +from scripts.scraper.arcade import clex +from scripts.scraper.dats import listxml ROOT = Path(__file__).resolve().parent.parent FIXTURES = ROOT / "tests" / "fixtures" / "arcade_parents" diff --git a/tests/test_audit_cli.py b/tests/test_audit_cli.py index 4b407c2ef..b872e1955 100644 --- a/tests/test_audit_cli.py +++ b/tests/test_audit_cli.py @@ -372,20 +372,20 @@ class ACheckThatCannotAnswerDoesNotPass(unittest.TestCase): """Every HEAD unanswered printed "16 unknown" and exited 0, so the online pipeline printed check_buildbot OK.""" import check_buildbot_system as cbs - from scraper import buildbot_system + from freshness import buildbot registry = str(REPO_ROOT / "platforms" / "_data_dirs.yml") - tracked = buildbot_system.load_tracked_entries(registry) + tracked = buildbot.load_tracked_entries(registry) self.assertTrue(tracked) cases = { "index unreachable": mock.patch.object( - buildbot_system, "fetch_index", side_effect=OSError("down")), + buildbot, "fetch_index", side_effect=OSError("down")), "every HEAD unanswered": mock.patch.object( - buildbot_system, "fetch_index", return_value=set(tracked)), + buildbot, "fetch_index", return_value=set(tracked)), } for label, index in cases.items(): with self.subTest(label), index, \ - mock.patch.object(buildbot_system, "get_remote_etag", return_value=None), \ + mock.patch.object(buildbot, "get_remote_etag", return_value=None), \ mock.patch.object(sys, "argv", ["check_buildbot_system.py", "--registry", registry]), \ contextlib.redirect_stdout(io.StringIO()), \ diff --git a/tests/test_audit_project.py b/tests/test_audit_project.py index d82ecfaf8..0ab61bb2a 100644 --- a/tests/test_audit_project.py +++ b/tests/test_audit_project.py @@ -1135,7 +1135,7 @@ class CommentsSayWhy(unittest.TestCase): cwd=REPO_ROOT, capture_output=True, text=True, check=True, ).stdout.split() self.assertIn("install.py", tracked) - self.assertIn("scripts/scraper/mame_parser.py", tracked) + self.assertIn("scripts/scraper/arcade/mame_parser.py", tracked) found = [] for name in sorted(set(tracked)): lines = (REPO_ROOT / name).read_text(encoding="utf-8").splitlines() diff --git a/tests/test_audit_site.py b/tests/test_audit_site.py index bbc1c6141..c74a8ba3c 100644 --- a/tests/test_audit_site.py +++ b/tests/test_audit_site.py @@ -558,7 +558,7 @@ class TheCollectionShipsADat(unittest.TestCase): converter from files.csv.""" def test_round_trip_through_the_logiqx_parser(self): - sys.path.insert(0, str(REPO_ROOT / "scripts" / "scraper")) + sys.path.insert(0, str(REPO_ROOT / "scripts" / "scraper" / "dats")) from logiqx_parser import parse_logiqx from scripts.sitegen.structured import collection_dat @@ -581,7 +581,7 @@ class TheCollectionShipsADat(unittest.TestCase): """A Batocera user auditing share/bios against the collection DAT met thousands of sets laid out by manufacturer, and nothing of the folder Batocera reads.""" - sys.path.insert(0, str(REPO_ROOT / "scripts" / "scraper")) + sys.path.insert(0, str(REPO_ROOT / "scripts" / "scraper" / "dats")) from logiqx_parser import parse_logiqx from scripts.sitegen.platformfiles import platform_data_links from scripts.sitegen.structured import platform_dat diff --git a/tests/test_autorun.py b/tests/test_autorun.py index 4a4dccb7a..0a0df5177 100644 --- a/tests/test_autorun.py +++ b/tests/test_autorun.py @@ -274,7 +274,7 @@ class GithubTokenPerStep(Scratch): return unattended_jobs.parse_jobs({"jobs": {name: {"steps": [{"run": run, "github_token": True}]}}}) def test_allowed_on_the_scrapers_and_freshness_scripts(self): - for run in ([PY, "-m", "scripts.scraper.mame_hash_scraper"], + for run in ([PY, "-m", "scripts.scraper.arcade.mame_hash_scraper"], [PY, "scripts/check_freshness.py", "--json"], [PY, "scripts/refresh_stale.py", "--only", "data"]): with self.subTest(run=run): @@ -293,11 +293,11 @@ class GithubTokenPerStep(Scratch): def test_refused_in_the_campaign_job_even_on_a_scraper(self): with self.assertRaisesRegex(ValueError, "campaign never receives"): - self.job([PY, "-m", "scripts.scraper.mame_hash_scraper"], name="campaign") + self.job([PY, "-m", "scripts.scraper.arcade.mame_hash_scraper"], name="campaign") def test_an_undeclared_step_gets_no_token(self): job = unattended_jobs.parse_jobs({"jobs": {"x": {"network": True, "steps": [ - [PY, "-m", "scripts.scraper.mame_hash_scraper"]]}}})["x"] + [PY, "-m", "scripts.scraper.arcade.mame_hash_scraper"]]}}})["x"] with unittest.mock.patch.object(unattended_jobs, "token_env", return_value={"GITHUB_TOKEN": "t1"}), \ unittest.mock.patch.dict(os.environ, {"GITHUB_TOKEN": "t1"}): self.assertNotIn("GITHUB_TOKEN", unattended_jobs.job_env(job, job.steps[0])) diff --git a/tests/test_check_freshness.py b/tests/test_check_freshness.py index 712e03884..df355fd0c 100644 --- a/tests/test_check_freshness.py +++ b/tests/test_check_freshness.py @@ -73,7 +73,8 @@ from model.romfolders import load_sources, sources_dir from model.safeparse import yaml_load from model.targets import platform_overrides from profiling.reports import ProfileReport, SkipKind, report_to_dict -from scripts.scraper import dat_fetch, game_dat_importer +from scripts.scraper.arcade import dat_fetch +from scripts.scraper.dats import game_dat_importer from tests.sources import SCRIPTS REPO_ROOT = Path(__file__).resolve().parents[1] @@ -969,19 +970,19 @@ class TheBuildbotIndexIsRead(unittest.TestCase): def test_new_and_dropped_assets_are_stale(self): from unittest import mock - from scraper import buildbot_system + from freshness import buildbot report = {"entries": [ {"zip": "New.zip", "status": "NEW", "key": None}, {"zip": "Old.zip", "status": "OK", "key": "old"}, ]} - with mock.patch.object(buildbot_system, "check", lambda registry: report): + with mock.patch.object(buildbot, "check", lambda registry: report): finding = _check_buildbot_system(REPO_ROOT / "platforms") self.assertEqual(finding.status, STALE) self.assertIn("new New.zip", finding.detail) - with mock.patch.object(buildbot_system, "check", lambda registry: {"error": "x", "entries": []}): + with mock.patch.object(buildbot, "check", lambda registry: {"error": "x", "entries": []}): self.assertEqual(_check_buildbot_system(REPO_ROOT / "platforms").status, UNKNOWN) - self.assertEqual([e["zip"] for e in buildbot_system.pending(report)], ["New.zip"]) + self.assertEqual([e["zip"] for e in buildbot.pending(report)], ["New.zip"]) diff --git a/tests/test_doc_pages_rules.py b/tests/test_doc_pages_rules.py index 21a508b2f..e86a6e057 100644 --- a/tests/test_doc_pages_rules.py +++ b/tests/test_doc_pages_rules.py @@ -465,12 +465,12 @@ class ArchitectureStatesTheArbitration(unittest.TestCase): self.assertNotIn("the profile takes precedence for pack generation", page) section = page[page.index("### When both layers claim one destination"):] section = section[:section.index("\n## ")] - self.assertIn("`slots.arbitrate()`", section) + self.assertIn("`packs.slots.arbitrate()`", section) # The pack, the manifest and verify decide through slot_choices, and # a test in test_slots forbids them to call arbitrate: the page names # the function they read, not only the one the report prints. - self.assertIn("`slots.slot_choices()`", section) - self.assertIn("`slots.pack_overrides()`", section) + self.assertIn("`packs.slots.slot_choices()`", section) + self.assertIn("`packs.slots.pack_overrides()`", section) self.assertNotIn("both decide through `slots.arbitrate()`", section) source = inspect.getsource(slots.arbitrate) # The three outcomes the section describes. diff --git a/tests/test_doc_pages_style.py b/tests/test_doc_pages_style.py index cf22f651d..c685408d9 100644 --- a/tests/test_doc_pages_style.py +++ b/tests/test_doc_pages_style.py @@ -205,7 +205,7 @@ class TheCatalogRowsStateFacts(unittest.TestCase): self.assertEqual(len(rows), 2) for word in ("stale", "blocks"): self.assertNotIn(word, " ".join(rows)) - scraper = (ROOT / "scripts" / "scraper" / "redump_dat_scraper.py").read_text(encoding="utf-8") + scraper = (ROOT / "scripts" / "scraper" / "dats" / "redump_dat_scraper.py").read_text(encoding="utf-8") self.assertIn("/bios/", scraper) self.assertIn("`/bios/`", rows[0]) diff --git a/tests/test_e2e_pack_sources.py b/tests/test_e2e_pack_sources.py index 2b5b1c747..fe4a7ed77 100644 --- a/tests/test_e2e_pack_sources.py +++ b/tests/test_e2e_pack_sources.py @@ -23,7 +23,7 @@ class TestE2EHashScrapers(E2EFixture): # --------------------------------------------------------------- def test_mame_parser_finds_bios_root_sets(self): - from scripts.scraper.mame_parser import find_bios_root_sets, parse_rom_block + from scripts.scraper.arcade.mame_parser import find_bios_root_sets, parse_rom_block source = """ ROM_START( neogeo ) @@ -45,7 +45,7 @@ GAME( 1980, pacman, 0, pacman, pacman, pacman_state, empty_init, ROT90, "Namco", self.assertEqual(roms[0]["crc32"], "9036d879") def test_fbneo_parser_finds_bios_sets(self): - from scripts.scraper.fbneo_parser import find_bios_sets, parse_rom_info + from scripts.scraper.arcade.fbneo_parser import find_bios_sets, parse_rom_info source = """ static struct BurnRomInfo neogeoRomDesc[] = { @@ -69,7 +69,7 @@ struct BurnDriver BurnDrvneogeo = { self.assertEqual(roms[0]["crc32"], "9036d879") def test_mame_merge_preserves_manual_fields(self): - from scripts.scraper._hash_merge import merge_mame_profile + from scripts.scraper.arcade._hash_merge import merge_mame_profile profile = { "emulator": "Test", @@ -119,7 +119,7 @@ struct BurnDriver BurnDrvneogeo = { self.assertEqual(result["core_version"], "0.286") def test_fbneo_merge_updates_individual_roms(self): - from scripts.scraper._hash_merge import merge_fbneo_profile + from scripts.scraper.arcade._hash_merge import merge_fbneo_profile profile = { "emulator": "FBNeo", diff --git a/tests/test_fbneo_parser.py b/tests/test_fbneo_parser.py index 44fc74830..829774fbe 100644 --- a/tests/test_fbneo_parser.py +++ b/tests/test_fbneo_parser.py @@ -8,7 +8,7 @@ import tempfile import unittest from pathlib import Path -from scripts.scraper.fbneo_parser import ( +from scripts.scraper.arcade.fbneo_parser import ( find_bios_sets, parse_fbneo_source_tree, parse_rom_info, diff --git a/tests/test_game_catalogs.py b/tests/test_game_catalogs.py index 55debd26d..0522d9086 100644 --- a/tests/test_game_catalogs.py +++ b/tests/test_game_catalogs.py @@ -12,7 +12,7 @@ import unittest from pathlib import Path from model.region import REGIONS -from scripts.scraper import game_dat_importer as importer +from scripts.scraper.dats import game_dat_importer as importer ROOT = Path(__file__).resolve().parent.parent FIXTURES = ROOT / "tests" / "fixtures" / "game_dats" @@ -25,7 +25,7 @@ except ImportError: # pragma: no cover - CI installs it def run_import(source: str, output: Path, *extra: str) -> subprocess.CompletedProcess: return subprocess.run( - [sys.executable, "-m", "scripts.scraper.game_dat_importer", "--source", source, + [sys.executable, "-m", "scripts.scraper.dats.game_dat_importer", "--source", source, "--pack", str(FIXTURES), "--output-dir", str(output), *extra], cwd=ROOT, capture_output=True, text=True, check=False, ) @@ -120,7 +120,7 @@ class FixtureImport(unittest.TestCase): def test_offline_without_cache_names_the_remedy(self) -> None: result = subprocess.run( - [sys.executable, "-m", "scripts.scraper.game_dat_importer", "--source", "redump", + [sys.executable, "-m", "scripts.scraper.dats.game_dat_importer", "--source", "redump", "--cache-dir", str(self.out / "empty"), "--output-dir", str(self.out)], cwd=ROOT, capture_output=True, text=True, check=False, ) @@ -132,7 +132,7 @@ class OneLogiqxReader(unittest.TestCase): """The catalog importer read only and kept nameless ROMs.""" def test_machine_entries_and_serials(self) -> None: - from scripts.scraper.logiqx_parser import parse_logiqx_games + from scripts.scraper.dats.logiqx_parser import parse_logiqx_games name, version, games = parse_logiqx_games( b'
D1
' diff --git a/tests/test_hash_merge.py b/tests/test_hash_merge.py index 55b20e853..5f640b641 100644 --- a/tests/test_hash_merge.py +++ b/tests/test_hash_merge.py @@ -12,14 +12,14 @@ from typing import Any import yaml -from scripts.scraper._hash_merge import ( +from scripts.scraper.arcade._hash_merge import ( _build_source_ref, compute_diff, load_profile, merge_fbneo_profile, merge_mame_profile, ) -from scripts.scraper._hash_write import write_fbneo_profile, write_mame_profile +from scripts.scraper.arcade._hash_write import write_fbneo_profile, write_mame_profile def _refresh_mame(path: Path, hashes: dict) -> None: @@ -255,7 +255,7 @@ class TestMameMerge(unittest.TestCase): The manager set loads "01", but written unquoted it re-parses as the integer 1 and the profile stops naming the file the driver opens. """ - from scripts.scraper._hash_write import _append_new_entries, format_contents + from scripts.scraper.arcade._hash_write import _append_new_entries, format_contents contents = [ {"name": "01", "description": "ROM bank 0-1", "size": 8192, @@ -414,9 +414,9 @@ class TheScraperClonesTheReleaseItLabels(unittest.TestCase): def test_clone_and_version_come_from_one_tag(self): from unittest import mock - from scripts.scraper import mame_hash_scraper as scraper + from scripts.scraper.arcade import mame_hash_scraper as scraper - from scripts.scraper import sparse_clone + from scripts.scraper.arcade import sparse_clone calls: list[list[str]] = [] @@ -443,7 +443,7 @@ class AReleaseProfileDescribesItsOwnRelease(unittest.TestCase): gives a set.""" def test_sets_pins_and_systems(self): - from scripts.scraper.mame_hash_scraper import release_profile + from scripts.scraper.arcade.mame_hash_scraper import release_profile bios_sets = { "neogeo": {"source_file": "src/mame/neogeo/neogeo.cpp", "source_line": 10, @@ -478,7 +478,7 @@ class AReleaseProfileDescribesItsOwnRelease(unittest.TestCase): def test_a_set_the_release_runs_without_is_not_required(self): """recel is undumped at 0.258: the current profile's true does not apply.""" - from scripts.scraper.mame_hash_scraper import release_profile + from scripts.scraper.arcade.mame_hash_scraper import release_profile bios_sets = { "recel": {"source_file": "src/mame/pinball/recel.cpp", "source_line": 505, @@ -501,7 +501,7 @@ class AReleaseProfileDescribesItsOwnRelease(unittest.TestCase): self.assertTrue(files["neogeo.zip"]["required"]) def test_a_release_profile_is_left_out_of_the_current_refresh(self): - from scripts.scraper.mame_hash_scraper import _find_mame_profiles + from scripts.scraper.arcade.mame_hash_scraper import _find_mame_profiles names = {path.name for path in _find_mame_profiles()} self.assertIn("mame.yml", names) @@ -509,7 +509,7 @@ class AReleaseProfileDescribesItsOwnRelease(unittest.TestCase): def test_a_pinned_build_of_the_mame_tree_is_left_out(self): """pSxMAME builds mamedev/mame at 0.133: refreshed, it would carry 0.289 refs.""" - from scripts.scraper.mame_hash_scraper import _find_mame_profiles + from scripts.scraper.arcade.mame_hash_scraper import _find_mame_profiles self.assertNotIn("psxmame.yml", {path.name for path in _find_mame_profiles()}) @@ -761,7 +761,7 @@ class AnUnreadableCloneStopsTheScrape(unittest.TestCase): import subprocess from unittest import mock - from scripts.scraper import sparse_clone + from scripts.scraper.arcade import sparse_clone dest = Path(tempfile.gettempdir()) / "retrobios-no-clone" failing = subprocess.CalledProcessError(128, ["git", "rev-parse", "HEAD"]) @@ -840,7 +840,8 @@ class OneCloneDirectoryPerRun(unittest.TestCase): def test_the_clone_directory_names_the_process(self): import os - from scripts.scraper import fbneo_hash_scraper, mame_hash_scraper + from scripts.scraper.arcade import fbneo_hash_scraper + from scripts.scraper.arcade import mame_hash_scraper for clone in (mame_hash_scraper._CLONE_DIR, fbneo_hash_scraper.CLONE_DIR): with self.subTest(clone=clone.name): @@ -854,7 +855,8 @@ class ABrokenProfileStopsTheRefresh(unittest.TestCase): def test_both_scrapers_name_it(self): from unittest import mock - from scripts.scraper import fbneo_hash_scraper, mame_hash_scraper + from scripts.scraper.arcade import fbneo_hash_scraper + from scripts.scraper.arcade import mame_hash_scraper with tempfile.TemporaryDirectory() as directory: Path(directory, "fbneo.yml").write_text("files: [\n - name: a\n") diff --git a/tests/test_launcher_evidence.py b/tests/test_launcher_evidence.py index 6df45f81a..66529fcda 100644 --- a/tests/test_launcher_evidence.py +++ b/tests/test_launcher_evidence.py @@ -29,8 +29,8 @@ from resolve.launchers import handed_directories from resolve.launcherplaces import launcher_places from profiling.reportinputs import check_build_refs from profiling.repos import shipped_build_holders -from scraper.retrobat_launchers import _choices_apart -from scraper.shell_launchers import LauncherPatternMissing, Script, config_placement +from scraper.launchers.retrobat import _choices_apart +from scraper.launchers.shell import LauncherPatternMissing, Script, config_placement from resolve.launcherrefs import config_ref, is_feature_ref REPO_ROOT = Path(__file__).resolve().parents[1] diff --git a/tests/test_launcher_layer.py b/tests/test_launcher_layer.py index e3a2cda47..03f887546 100644 --- a/tests/test_launcher_layer.py +++ b/tests/test_launcher_layer.py @@ -398,10 +398,9 @@ class LauncherLayerTest(unittest.TestCase): def test_every_extractor_spelling_of_the_bios_folder_is_known(self) -> None: from resolve.launcherplaces import BIOS_ROOT_TOKENS - from scraper import emudeck_launchers, retrodeck_launchers, retropie_reader + from scraper.launchers import emudeck, retrodeck, retropie_reader - for token in (emudeck_launchers.BIOS, retrodeck_launchers.BIOS, - retropie_reader.BIOSDIR): + for token in (emudeck.BIOS, retrodeck.BIOS, retropie_reader.BIOSDIR): self.assertIn(token, BIOS_ROOT_TOKENS) def test_no_place_is_filled_twice(self) -> None: diff --git a/tests/test_launcher_paths.py b/tests/test_launcher_paths.py index 0c71f0fb9..ec8e608c5 100644 --- a/tests/test_launcher_paths.py +++ b/tests/test_launcher_paths.py @@ -17,11 +17,11 @@ import unittest from pathlib import Path from resolve.launchers import handed_directories, standalone_bindings -from scraper import retrobat_generators -from scraper.retrobat_arguments import portable_users -from scraper.csharp_source import Source -from scraper.batocera_configgen import GENERATORS, IMPORTER, PATHS_MODULE, Configgen -from scraper.batocera_launchers import LauncherShapeError, patched_paths, working_directories +from scraper.launchers import retrobat_generators +from scraper.launchers.retrobat_arguments import portable_users +from scraper.launchers.csharp_source import Source +from scraper.launchers.batocera_configgen import GENERATORS, IMPORTER, PATHS_MODULE, Configgen +from scraper.launchers.batocera import LauncherShapeError, patched_paths, working_directories REPO_ROOT = Path(__file__).resolve().parent.parent @@ -298,7 +298,7 @@ class OnlyWhatABoardBuildsIsRun(unittest.TestCase): self.assertIn("suyu", bs.configgen_cores(self.DEFAULTS, self.ES, set())[0]) def test_the_extractor_reports_programs_run_from_its_own_bios_root(self): - from scraper.batocera_launchers import Launcher, extraction + from scraper.launchers.batocera import Launcher, extraction # A fork whose batoceraPaths puts the BIOS folder elsewhere: the # report follows the root its code gives, not Batocera's. diff --git a/tests/test_launchers_amberelec.py b/tests/test_launchers_amberelec.py index 05906c5b5..988573378 100644 --- a/tests/test_launchers_amberelec.py +++ b/tests/test_launchers_amberelec.py @@ -17,8 +17,8 @@ from pathlib import Path import yaml from model.launcherrecords import record_emulators -from scraper import amberelec_launchers as al -from scraper.configgen_launchers import LauncherShapeError +from scraper.launchers import amberelec as al +from scraper.launchers.configgen import LauncherShapeError REPO_ROOT = Path(__file__).resolve().parent.parent diff --git a/tests/test_launchers_batocera.py b/tests/test_launchers_batocera.py index 82693770e..1f82b9a03 100644 --- a/tests/test_launchers_batocera.py +++ b/tests/test_launchers_batocera.py @@ -18,16 +18,22 @@ from pathlib import Path import yaml from model.launcherrecords import record_emulators -from scraper.batocera_configgen import CONFIGGEN, GENERATORS, IMPORTER, PATHS_MODULE, Configgen -from scraper.batocera_launchers import ( +from scraper.launchers.batocera_configgen import ( + CONFIGGEN, + GENERATORS, + IMPORTER, + PATHS_MODULE, + Configgen, +) +from scraper.launchers.batocera import ( Launcher, LauncherShapeError, config_directories, extract_launchers, ) -from scraper.batocera_searches import duckstation, hatari -from scraper.batocera_config_writes import lexaloffle -from scraper.retropie_scripts import Launcher as PackageLauncher +from scraper.launchers.batocera_searches import duckstation, hatari +from scraper.launchers.batocera_config_writes import lexaloffle +from scraper.launchers.retropie_scripts import Launcher as PackageLauncher from tests.launcherssupport import placed REPO_ROOT = Path(__file__).resolve().parent.parent @@ -532,7 +538,7 @@ class MameSearchPaths(unittest.TestCase): """mameGenerator.py:129-142 at batocera-43.1: `-rompath` and `-samplepath`.""" def test_the_command_line_search_paths_are_recorded(self): - from scraper.batocera_launchers import search_paths + from scraper.launchers.batocera import search_paths cg = configgen({ MAME: placed({1: MAME_HEAD, 129: MAME_COMMAND, 142: MAME_SAMPLES, 378: MAME_BOOT}), @@ -620,7 +626,7 @@ class PlatformRecords(unittest.TestCase): def test_every_reference_is_in_configgen(self): # Or in a patch Batocera applies to an emulator's own path code. - from scraper.batocera_launchers import PATH_PATCHES + from scraper.launchers.batocera import PATH_PATCHES for record in self.config["launchers"]: self.assertTrue( diff --git a/tests/test_launchers_emudeck.py b/tests/test_launchers_emudeck.py index 1108503cc..3f957e7de 100644 --- a/tests/test_launchers_emudeck.py +++ b/tests/test_launchers_emudeck.py @@ -16,9 +16,9 @@ from pathlib import Path import yaml -from scraper import emudeck_launchers as el +from scraper.launchers import emudeck as el from model.sourcerevision import required_revision -from scraper.shell_launchers import LauncherPatternMissing, RepoTree, words +from scraper.launchers.shell import LauncherPatternMissing, RepoTree, words REPO_ROOT = Path(__file__).resolve().parent.parent diff --git a/tests/test_launchers_emuelec.py b/tests/test_launchers_emuelec.py index 98a9f6b5d..72ff3088f 100644 --- a/tests/test_launchers_emuelec.py +++ b/tests/test_launchers_emuelec.py @@ -17,11 +17,11 @@ from pathlib import Path import yaml -from scraper import emuelec_launchers as el -from scraper import emuelec_runs -from scraper.emuelec_runs import SX05RE, BIN, Runs, LIBRETRO, EMULATORS +from scraper.launchers import emuelec as el +from scraper.launchers import emuelec_runs +from scraper.launchers.emuelec_runs import SX05RE, BIN, Runs, LIBRETRO, EMULATORS from model.sourcerevision import required_revision -from scraper.shell_launchers import LauncherPatternMissing, RepoTree +from scraper.launchers.shell import LauncherPatternMissing, RepoTree REPO_ROOT = Path(__file__).resolve().parent.parent diff --git a/tests/test_launchers_knulli.py b/tests/test_launchers_knulli.py index 447083474..17fe3902d 100644 --- a/tests/test_launchers_knulli.py +++ b/tests/test_launchers_knulli.py @@ -17,11 +17,11 @@ from pathlib import Path import yaml from model.launcherrecords import record_emulators -from scraper import knulli_launchers as kl -from scraper.configgen_sites import bios_sites, GenericSites -from scraper.batocera_searches import hatari -from scraper.batocera_config_writes import melonds -from scraper.configgen_launchers import LauncherShapeError +from scraper.launchers import knulli as kl +from scraper.launchers.configgen_sites import bios_sites, GenericSites +from scraper.launchers.batocera_searches import hatari +from scraper.launchers.batocera_config_writes import melonds +from scraper.launchers.configgen import LauncherShapeError REPO_ROOT = Path(__file__).resolve().parent.parent diff --git a/tests/test_launchers_recalbox.py b/tests/test_launchers_recalbox.py index b21ef3296..ecb221eb3 100644 --- a/tests/test_launchers_recalbox.py +++ b/tests/test_launchers_recalbox.py @@ -18,7 +18,7 @@ import yaml from model.launcherrecords import emulator_names, record_emulators from scraper import recalbox_scraper -from scraper.recalbox_configgen import ( +from scraper.launchers.recalbox_configgen import ( ALL_CORES, AMIBERRY_CONFIG, AMIBERRY_GLOBAL, @@ -36,7 +36,7 @@ from scraper.recalbox_configgen import ( XEMU, XROAR, ) -from scraper.recalbox_launchers import ( +from scraper.launchers.recalbox import ( SOURCE_FILES, Launcher, LauncherShapeError, @@ -46,8 +46,8 @@ from scraper.recalbox_launchers import ( extract_launchers, system_directories, ) -from scraper.recalbox_emulators import amiberry, dolphin, mupen64plus, pcsx2, xemu, xroar -from scraper.recalbox_cascades import gsplus, hatari, hatari_libretro +from scraper.launchers.recalbox_emulators import amiberry, dolphin, mupen64plus, pcsx2, xemu, xroar +from scraper.launchers.recalbox_cascades import gsplus, hatari, hatari_libretro from tests.launchersrecalboxsupport import configgen, files, ref diff --git a/tests/test_launchers_retrobat_configs.py b/tests/test_launchers_retrobat_configs.py index 8af959537..53edf01f6 100644 --- a/tests/test_launchers_retrobat_configs.py +++ b/tests/test_launchers_retrobat_configs.py @@ -15,17 +15,14 @@ import tempfile import unittest from pathlib import Path -from scraper import retrobat_launchers as rl -from scraper import retrobat_generators -from scraper.retrobat_computers import hatari, openmsx, amiberry -from scraper.retrobat_config_files import ( - ares, - mesen, -) -from scraper.retrobat_generators import GENERATORS, GUARDED_WRITES, guarded_writes_in -from scraper.retrobat_playstation import duckstation, psx_cascades -from scraper.retrobat_render import _option_path_in -from scraper.csharp_source import LauncherPatternMissing, Source, render_concat +from scraper.launchers import retrobat as rl +from scraper.launchers import retrobat_generators +from scraper.launchers.retrobat_computers import hatari, openmsx, amiberry +from scraper.launchers.retrobat_config_files import ares, mesen +from scraper.launchers.retrobat_generators import GENERATORS, GUARDED_WRITES, guarded_writes_in +from scraper.launchers.retrobat_playstation import duckstation, psx_cascades +from scraper.launchers.retrobat_render import _option_path_in +from scraper.launchers.csharp_source import LauncherPatternMissing, Source, render_concat from model.sourcerevision import required_revision from tests.launcherssupport import _sources diff --git a/tests/test_launchers_retrobat_files.py b/tests/test_launchers_retrobat_files.py index c81a780f0..06552bee6 100644 --- a/tests/test_launchers_retrobat_files.py +++ b/tests/test_launchers_retrobat_files.py @@ -11,9 +11,9 @@ import tests import unittest -from scraper import retrobat_generators -from scraper.retrobat_arguments import pico8, xroar, mame -from scraper.retrobat_config_files import ( +from scraper.launchers import retrobat_generators +from scraper.launchers.retrobat_arguments import pico8, xroar, mame +from scraper.launchers.retrobat_config_files import ( bizhawk_gb, dolphin, blastem, @@ -21,11 +21,11 @@ from scraper.retrobat_config_files import ( melonds_dsi, desmume, ) -from scraper.retrobat_config_folders import eka2l1, tsugaru, dosbox_copies -from scraper.retrobat_generators import GENERATORS -from scraper.retrobat_render import render -from scraper.retrobat_xbox import CXBX_DATA_FOLDER, cxbx, xemu_saves -from scraper.csharp_source import LauncherPatternMissing, Source +from scraper.launchers.retrobat_config_folders import eka2l1, tsugaru, dosbox_copies +from scraper.launchers.retrobat_generators import GENERATORS +from scraper.launchers.retrobat_render import render +from scraper.launchers.retrobat_xbox import CXBX_DATA_FOLDER, cxbx, xemu_saves +from scraper.launchers.csharp_source import LauncherPatternMissing, Source from tests.launcherssupport import _sources diff --git a/tests/test_launchers_retrodeck.py b/tests/test_launchers_retrodeck.py index 9917b864c..d571a1c28 100644 --- a/tests/test_launchers_retrodeck.py +++ b/tests/test_launchers_retrodeck.py @@ -16,7 +16,7 @@ from pathlib import Path import yaml -from scraper import retrodeck_launchers as rd +from scraper.launchers import retrodeck as rd REPO_ROOT = Path(__file__).resolve().parent.parent diff --git a/tests/test_launchers_retropie.py b/tests/test_launchers_retropie.py index 732d6711d..9faba5c72 100644 --- a/tests/test_launchers_retropie.py +++ b/tests/test_launchers_retropie.py @@ -18,9 +18,9 @@ from pathlib import Path import yaml -from scraper import batocera_launchers -from scraper import retropie_launchers as rl -from scraper.retropie_scripts import Launcher, Scripts, LauncherPatternMissing +from scraper.launchers import batocera as batocera_launchers +from scraper.launchers import retropie as rl +from scraper.launchers.retropie_scripts import Launcher, Scripts, LauncherPatternMissing REPO_ROOT = Path(__file__).resolve().parent.parent @@ -301,7 +301,7 @@ class AdvanceMameSearchList(unittest.TestCase): ) def test_mame_does_not_read_a_colon_as_a_separator(self): - from scraper.retropie_reader import LIST_SEPARATORS + from scraper.launchers.retropie_reader import LIST_SEPARATORS self.assertNotIn("mame", LIST_SEPARATORS) self.assertEqual( diff --git a/tests/test_launchers_rocknix.py b/tests/test_launchers_rocknix.py index 09a73dbe3..b9df7c474 100644 --- a/tests/test_launchers_rocknix.py +++ b/tests/test_launchers_rocknix.py @@ -17,11 +17,11 @@ from pathlib import Path import yaml -from scraper import rocknix_launchers as rl -from scraper import rocknix_configs -from scraper.rocknix_configs import ROCKNIX, DEVICES, STANDALONE +from scraper.launchers import rocknix as rl +from scraper.launchers import rocknix_configs +from scraper.launchers.rocknix_configs import ROCKNIX, DEVICES, STANDALONE from model.sourcerevision import required_revision -from scraper.shell_launchers import LauncherPatternMissing, RepoTree +from scraper.launchers.shell import LauncherPatternMissing, RepoTree REPO_ROOT = Path(__file__).resolve().parent.parent diff --git a/tests/test_lines.py b/tests/test_lines.py index e5f4446a3..cde3df00c 100644 --- a/tests/test_lines.py +++ b/tests/test_lines.py @@ -29,8 +29,8 @@ class LinesOfOffsets(unittest.TestCase): class ParsersReportLines(unittest.TestCase): def test_mame_and_fbneo_sets_carry_their_line(self): - from scripts.scraper.fbneo_parser import find_bios_sets - from scripts.scraper.mame_parser import find_bios_root_sets + from scripts.scraper.arcade.fbneo_parser import find_bios_sets + from scripts.scraper.arcade.mame_parser import find_bios_root_sets mame = "\n\nGAME( 1990, neogeo, 0, ng, ng, ng_state, init, ROT0, \"SNK\", \"Neo\", MACHINE_IS_BIOS_ROOT )\n" self.assertEqual(find_bios_root_sets(mame, "neogeo.cpp")["neogeo"]["source_line"], 3) diff --git a/tests/test_listxml.py b/tests/test_listxml.py index 23ea8c440..19ab01863 100644 --- a/tests/test_listxml.py +++ b/tests/test_listxml.py @@ -10,8 +10,8 @@ import unittest import zipfile from pathlib import Path -from scripts.scraper import listxml -from scripts.scraper.listxml import attrs, iter_elements, open_listxml, rom_members +from scripts.scraper.dats import listxml +from scripts.scraper.dats.listxml import attrs, iter_elements, open_listxml, rom_members DOCUMENT = b""" diff --git a/tests/test_mame_devices.py b/tests/test_mame_devices.py index e5c31a9f9..6c3fec54e 100644 --- a/tests/test_mame_devices.py +++ b/tests/test_mame_devices.py @@ -17,11 +17,11 @@ import unittest from pathlib import Path from scripts.model.safeparse import yaml_load -from scripts.scraper._hash_write import DEVICE_SECTION, SOFTLIST_SECTION, write_mame_profile -from scripts.scraper._hash_merge import load_profile, mame_ref_role, merge_mame_profile -from scripts.scraper._mame_sections import merge_mame_devices, merge_mame_support -from scripts.scraper.listxml import open_listxml -from scripts.scraper.mame_devices import ( +from scripts.scraper.arcade._hash_write import DEVICE_SECTION, SOFTLIST_SECTION, write_mame_profile +from scripts.scraper.arcade._hash_merge import load_profile, mame_ref_role, merge_mame_profile +from scripts.scraper.arcade._mame_sections import merge_mame_devices, merge_mame_support +from scripts.scraper.dats.listxml import open_listxml +from scripts.scraper.arcade.mame_devices import ( ABSENT, AMBIGUOUS, NO_FILE, @@ -1001,7 +1001,7 @@ class TheRepositoryProfile(unittest.TestCase): class Cli(unittest.TestCase): def test_devices_needs_a_listxml(self): - from scripts.scraper.mame_hash_scraper import main + from scripts.scraper.arcade.mame_hash_scraper import main import sys from unittest import mock @@ -1019,7 +1019,7 @@ class TheDevicesFollowTheRelease(unittest.TestCase): import argparse from unittest import mock - from scripts.scraper import mame_hash_scraper as scraper + from scripts.scraper.arcade import mame_hash_scraper as scraper with tempfile.TemporaryDirectory() as directory: profile = Path(directory) / "mame.yml" @@ -1058,7 +1058,7 @@ class TheDevicesFollowTheRelease(unittest.TestCase): import argparse from unittest import mock - from scripts.scraper import mame_hash_scraper as scraper + from scripts.scraper.arcade import mame_hash_scraper as scraper with tempfile.TemporaryDirectory() as directory: profile = Path(directory) / "mame.yml" diff --git a/tests/test_mame_parser.py b/tests/test_mame_parser.py index feb8e2d26..313d3ae44 100644 --- a/tests/test_mame_parser.py +++ b/tests/test_mame_parser.py @@ -8,7 +8,7 @@ import os import tempfile import unittest -from scripts.scraper.mame_parser import ( +from scripts.scraper.arcade.mame_parser import ( find_bios_root_sets, parse_mame_source_tree, parse_rom_block, @@ -407,7 +407,7 @@ class TestCSourceLexer(unittest.TestCase): """One reader of C comments and macro calls for every driver scraper.""" def test_a_char_literal_quote_opens_no_string(self) -> None: - from scripts.scraper.clex import blank_comments + from scripts.scraper.arcade.clex import blank_comments text = "c = '\"'; /* ROM_START( fake ) */\nx" self.assertNotIn("ROM_START", blank_comments(text)) @@ -415,7 +415,7 @@ class TestCSourceLexer(unittest.TestCase): self.assertEqual(blank_comments("a/*x\ny*/b", keep_lines=False), "a b") def test_an_escaped_quote_does_not_end_the_call(self) -> None: - from scripts.scraper.clex import call_span + from scripts.scraper.arcade.clex import call_span text = 'GAME(1990, foo, "a\\"b)", 0) tail' self.assertEqual(call_span(text, 5), (["1990", "foo", '"a\\"b)"', "0"], 27)) diff --git a/tests/test_provenance.py b/tests/test_provenance.py index e6a77fc68..cd1d00613 100644 --- a/tests/test_provenance.py +++ b/tests/test_provenance.py @@ -18,9 +18,9 @@ from scripts.model.dumpcatalog import ( ) from scripts.sitegen.provenance import generate_provenance_page, wanted_dumps from scripts.acquire.provenance import build_report -from scripts.scraper.dat_pack_importer import _bios_entries, import_pack -from scripts.scraper.logiqx_parser import parse_logiqx, validate_logiqx_format -from scripts.scraper.redump_dat_scraper import discover_bios_datfiles, parse_redump_dat +from scripts.scraper.dats.dat_pack_importer import _bios_entries, import_pack +from scripts.scraper.dats.logiqx_parser import parse_logiqx, validate_logiqx_format +from scripts.scraper.dats.redump_dat_scraper import discover_bios_datfiles, parse_redump_dat LOGIQX_GAME_FIXTURE = """ diff --git a/tests/test_refresh_failures.py b/tests/test_refresh_failures.py index b3a14f1ff..a9b86f32b 100644 --- a/tests/test_refresh_failures.py +++ b/tests/test_refresh_failures.py @@ -23,7 +23,7 @@ import zipfile from pathlib import Path from unittest import mock -from scraper import buildbot_system +from freshness import buildbot from packs import datadirs REPO_ROOT = Path(__file__).resolve().parent.parent @@ -187,7 +187,7 @@ class RefreshFailuresAreFailures(unittest.TestCase): def test_a_failed_refresh_is_returned_and_exits_nonzero(self): report = {"entries": [{"status": "UPDATED", "key": "dolphin-sys"}, {"status": "OK", "key": "ppsspp-assets"}]} - self.assertEqual(buildbot_system.updated(report), ["dolphin-sys"]) + self.assertEqual(buildbot.updated(report), ["dolphin-sys"]) registry = {"dolphin-sys": {"local_cache": "data/dolphin-sys"}} with mock.patch.object(datadirs, "refresh_entry", return_value=None): self.assertEqual(datadirs.refresh_keys(registry, ["dolphin-sys"]), ["dolphin-sys"]) @@ -217,8 +217,8 @@ class RefreshFailuresAreFailures(unittest.TestCase): seen.append((key, entry)) return True - with mock.patch.object(buildbot_system, "fetch_index", return_value={"Else.zip"}), \ - mock.patch.object(buildbot_system, "get_remote_etag", return_value='"new"'), \ + with mock.patch.object(buildbot, "fetch_index", return_value={"Else.zip"}), \ + mock.patch.object(buildbot, "get_remote_etag", return_value='"new"'), \ mock.patch.object(datadirs, "refresh_entry", side_effect=refresh), \ mock.patch.object(sys, "argv", ["check_buildbot_system.py", "--update", "--registry", str(registry)]), \ diff --git a/tests/test_refresh_stale.py b/tests/test_refresh_stale.py index 335654418..58121787f 100644 --- a/tests/test_refresh_stale.py +++ b/tests/test_refresh_stale.py @@ -134,7 +134,7 @@ class Planning(unittest.TestCase): "batocera": "-m scripts.scraper.targets.batocera_targets_scraper" " -o platforms/targets/batocera.yml", "dolphin-sys": "scripts/refresh_data_dirs.py --key dolphin-sys --force", - "fbneo recipes": "-m scripts.scraper.romset_dat_importer" + "fbneo recipes": "-m scripts.scraper.arcade.romset_dat_importer" " --source fbneo --fetch", }, ) @@ -146,9 +146,9 @@ class Planning(unittest.TestCase): self.assertEqual( {j.subject: " ".join(j.command[1:]) for j in jobs}, { - "no-intro games": "-m scripts.scraper.game_dat_importer --source no-intro" + "no-intro games": "-m scripts.scraper.dats.game_dat_importer --source no-intro" " --fetch --refresh --floor", - "redump games": "-m scripts.scraper.game_dat_importer --source redump" + "redump games": "-m scripts.scraper.dats.game_dat_importer --source redump" " --fetch --refresh --floor", }, ) diff --git a/tests/test_romset_recipes.py b/tests/test_romset_recipes.py index 4e62e2e42..b9053cc50 100644 --- a/tests/test_romset_recipes.py +++ b/tests/test_romset_recipes.py @@ -24,7 +24,7 @@ from romrecipes.identify import ( reconstruct, write_reconstructions, ) -from scripts.scraper.romset_dat_importer import ( +from scripts.scraper.arcade.romset_dat_importer import ( catalog_targets, compact_entries, holds_target, @@ -32,7 +32,7 @@ from scripts.scraper.romset_dat_importer import ( merge_snapshot, recipe_entries, ) -from scripts.scraper.logiqx_parser import parse_logiqx +from scripts.scraper.dats.logiqx_parser import parse_logiqx from core.hashing import git_blob_sha from core.torrentzip import build_torrentzip, is_torrentzip @@ -421,7 +421,7 @@ class ListXmlRecipes(unittest.TestCase): def test_a_machine_larger_than_the_window_is_kept(self): """Each machine here spans several reads: the window grows until the element closes instead of cutting its start tag away.""" - from scripts.scraper import listxml + from scripts.scraper.dats import listxml expected = listxml_entries(self._opener(self._document()), "MAME 0.289", None) saved = listxml.LISTXML_CHUNK @@ -455,7 +455,7 @@ class ListXmlRecipes(unittest.TestCase): def test_a_set_kept_under_another_name_is_matched_by_members(self): """aga.zip holds exactly MAME's isa_aga: the entry carries the collection's name and keeps the upstream one in ``set``.""" - from scripts.scraper.romset_dat_importer import member_list + from scripts.scraper.arcade.romset_dat_importer import member_list child = [ {"name": "own.rom", "crc32": loopback.crc(ROM_B)}, @@ -474,7 +474,7 @@ class ListXmlRecipes(unittest.TestCase): ) def test_matching_by_members_keeps_the_named_sets(self): - from scripts.scraper.romset_dat_importer import member_list + from scripts.scraper.arcade.romset_dat_importer import member_list entries = listxml_entries( self._opener(self._document()), "MAME 0.289", {"parentset.zip"}, @@ -484,7 +484,7 @@ class ListXmlRecipes(unittest.TestCase): def test_one_entry_per_archive_its_own_set_first(self): """Thirty keyboard sets share one ROM: the set named like the archive wins.""" - from scripts.scraper.romset_dat_importer import one_set_per_archive + from scripts.scraper.arcade.romset_dat_importer import one_set_per_archive members = [{"name": "kbd.rom", "crc32": "12345678"}] entries = one_set_per_archive([ @@ -495,7 +495,7 @@ class ListXmlRecipes(unittest.TestCase): self.assertEqual([entry["set"] for entry in entries], ["a500kbd"]) def test_a_logiqx_set_is_matched_by_members_too(self): - from scripts.scraper.romset_dat_importer import member_list + from scripts.scraper.arcade.romset_dat_importer import member_list members = [ {"name": "01", "crc32": loopback.crc(ROM_A)}, @@ -512,7 +512,7 @@ class ListXmlRecipes(unittest.TestCase): def test_the_collection_names_and_member_lists(self): """A .variants/ copy stands for the name its tag is cut from.""" - from scripts.scraper.romset_dat_importer import collection_archives, member_list + from scripts.scraper.arcade.romset_dat_importer import collection_archives, member_list with tempfile.TemporaryDirectory() as temp: root = Path(temp) @@ -539,7 +539,8 @@ class ListXmlRecipes(unittest.TestCase): from argparse import Namespace from model.database import DatabaseUnreadable - from scripts.scraper import arcade_parent_importer, romset_dat_importer + from scripts.scraper.arcade import arcade_parent_importer + from scripts.scraper.arcade import romset_dat_importer args = Namespace(all=False, db=str(TMP_ROOT / "nosuch.json")) with self.assertRaises(DatabaseUnreadable): @@ -864,7 +865,7 @@ class AnOversizedDatIsNamed(unittest.TestCase): import io import zipfile - from scripts.scraper.listxml import iter_dat_documents + from scripts.scraper.dats.listxml import iter_dat_documents with tempfile.TemporaryDirectory() as directory: pack = Path(directory) / "pack.zip" @@ -880,7 +881,7 @@ class AnOversizedDatIsNamed(unittest.TestCase): folder, and dat_pack_importer refused a lone DAT file.""" import zipfile - from scripts.scraper.listxml import iter_dat_documents + from scripts.scraper.dats.listxml import iter_dat_documents with tempfile.TemporaryDirectory(dir=TMP_ROOT) as directory: root = Path(directory) @@ -912,8 +913,8 @@ class FbneoFetchReadsOneRevision(unittest.TestCase): CDN caches, and --fetch read the tip whatever was named.""" def setUp(self): - from scripts.scraper import dat_fetch - from scripts.scraper import romset_dat_importer as importer + from scripts.scraper.arcade import dat_fetch + from scripts.scraper.arcade import romset_dat_importer as importer self.dat_fetch = dat_fetch self.importer = importer diff --git a/tests/test_scraper_contract.py b/tests/test_scraper_contract.py index e22016949..accd527fc 100644 --- a/tests/test_scraper_contract.py +++ b/tests/test_scraper_contract.py @@ -1229,7 +1229,7 @@ class HashScraperRefusesAnEmptyRead(unittest.TestCase): "commit": "abc", "bios_sets": sets} def test_mame_raises_and_writes_no_cache(self): - from scraper import mame_hash_scraper as m + from scraper.arcade import mame_hash_scraper as m with tempfile.TemporaryDirectory() as tmp: cache = Path(tmp) / "mame-hashes.json" @@ -1242,7 +1242,7 @@ class HashScraperRefusesAnEmptyRead(unittest.TestCase): def test_fbneo_raises_and_writes_no_cache(self): - from scraper import fbneo_hash_scraper as f + from scraper.arcade import fbneo_hash_scraper as f with tempfile.TemporaryDirectory() as tmp: cache = Path(tmp) / "fbneo-hashes.json" @@ -1254,7 +1254,7 @@ class HashScraperRefusesAnEmptyRead(unittest.TestCase): self.assertFalse(cache.exists()) def test_an_empty_or_unreadable_cache_is_not_served(self): - from scraper.sparse_clone import fresh_cache + from scraper.arcade.sparse_clone import fresh_cache with tempfile.TemporaryDirectory() as tmp: cache = Path(tmp) / "hashes.json" diff --git a/tests/test_standalone_links.py b/tests/test_standalone_links.py index b2490991c..9b66cfc8d 100644 --- a/tests/test_standalone_links.py +++ b/tests/test_standalone_links.py @@ -492,9 +492,9 @@ class Scrapers(unittest.TestCase): """The records each platform's scraper writes for these directories.""" def test_rocknix_patched_data_directory(self) -> None: - from scraper import rocknix_launchers as rl - from scraper.rocknix_configs import STANDALONE - from scraper.shell_launchers import LauncherPatternMissing, RepoTree + from scraper.launchers import rocknix as rl + from scraper.launchers.rocknix_configs import STANDALONE + from scraper.launchers.shell import LauncherPatternMissing, RepoTree path = f"{STANDALONE}/flycast-sa/patches/000-conf-dir.patch" patch = textwrap.dedent("""\ @@ -518,9 +518,14 @@ class Scrapers(unittest.TestCase): rl.patched_directories(RepoTree.from_files({path: patch.replace("return", "x =")})) def test_batocera_environment_directory(self) -> None: - from scraper.batocera_configgen import GENERATORS, IMPORTER, PATHS_MODULE, Configgen - from scraper.batocera_launchers import environment_directories - from scraper.configgen_launchers import LauncherShapeError + from scraper.launchers.batocera_configgen import ( + GENERATORS, + IMPORTER, + PATHS_MODULE, + Configgen, + ) + from scraper.launchers.batocera import environment_directories + from scraper.launchers.configgen import LauncherShapeError paths = "from pathlib import Path\nBIOS = Path('/userdata/bios')\nCONFIGS = Path('/userdata/system/configs')\n" importer = "_GENERATOR_MAP = {}\n_LEGACY_GENERATOR_MAP = {}\n" @@ -551,9 +556,9 @@ class Scrapers(unittest.TestCase): environment_directories(Configgen(tree.__getitem__)) def test_retrobat_bios_path_setting(self) -> None: - from scraper import retrobat_generators - from scraper.retrobat_config_files import value_writes - from scraper.csharp_source import Source + from scraper.launchers import retrobat_generators + from scraper.launchers.retrobat_config_files import value_writes + from scraper.launchers.csharp_source import Source path = f"{retrobat_generators.GENERATORS}/Flycast.Generator.cs" text = textwrap.dedent("""\ diff --git a/tests/test_target_scrapers.py b/tests/test_target_scrapers.py index f9fb4796c..6ff2d5531 100644 --- a/tests/test_target_scrapers.py +++ b/tests/test_target_scrapers.py @@ -844,7 +844,7 @@ class EmuDeckScriptNamesHaveOneRule(unittest.TestCase): rename added to one copy only made --target filter that core out.""" def test_the_target_scraper_names_scripts_as_the_platform_does(self): - from scripts.scraper.emudeck_launchers import emulator_of_script + from scripts.scraper.launchers.emudeck import emulator_of_script listing = [ "emuDeckRMG.sh", @@ -899,7 +899,7 @@ class HashScrapersRefuseAnUnknownVersion(unittest.TestCase): and cached it for a day, while the pipeline step still read OK.""" def test_mame_raises(self): - from scripts.scraper import mame_hash_scraper + from scripts.scraper.arcade import mame_hash_scraper with mock.patch("urllib.request.urlopen", _refuse), \ self.assertRaises(RuntimeError): diff --git a/wiki/adding-a-platform.md b/wiki/adding-a-platform.md index f1101191d..c6e534490 100644 --- a/wiki/adding-a-platform.md +++ b/wiki/adding-a-platform.md @@ -33,13 +33,15 @@ Before starting, gather the following from the upstream project: ## Step 1: Create the scraper -Scrapers live in `scripts/scraper/` and are auto-discovered by the plugin system. -Any file matching `*_scraper.py` in that directory is loaded at import time via -`pkgutil.iter_modules`. No registration step is needed beyond placing the file. +A platform scraper is `scripts/scraper/_scraper.py`. Nothing scans the +directory: the registry's `scraper: ` field (Step 2) names the module, and +`platform_scraper` in `scripts/freshness/scrapers.py` turns it into the +`python -m scripts.scraper._scraper` command that `check_freshness.py` +and `refresh_stale.py` run. ### Module contract -The module must export two names: +The module defines two names: ```python PLATFORM_NAME = "myplatform" # matches the key in _registry.yml @@ -464,12 +466,12 @@ launchers: | `choices_from` | The feature or option file listing the values the option takes (es_features, a core `.opt`), never the record's evidence | | `source_ref` | `path:lines` in the repository and at the revision `source` pins, which the site links | -Batocera's generators are read with `ast`: `scripts/scraper/batocera_configgen.py` -opens the configgen tree and `scripts/scraper/configgen_sites.py` reads each BIOS +Batocera's generators are read with `ast`: `scripts/scraper/launchers/batocera_configgen.py` +opens the configgen tree and `scripts/scraper/launchers/configgen_sites.py` reads each BIOS path a generator names, both shared with KNULLI. RetroBat's C# generators are read as -text through `scripts/scraper/csharp_source.py`. +text through `scripts/scraper/launchers/csharp_source.py`. ROCKNIX and EmuDeck launch from shell scripts and configs shipped with each -package, so `scripts/scraper/shell_launchers.py` reads assignments, `for` +package, so `scripts/scraper/launchers/shell.py` reads assignments, `for` loops, `ln -s` commands and `key = value` lines. A ROCKNIX package can ship one config per device: the configs are grouped by the value read, and `device` appears only when there is more than one group. melonDS writes its @@ -580,6 +582,14 @@ python scripts/verify.py --platform myplatform python scripts/verify.py --platform myplatform --verbose ``` +A new platform or system needs its sharing cards, the PNG images a link to +its page shows. Draw them and commit the result: + +```bash +python scripts/make_og_cards.py --only platforms # a new platform +python scripts/make_og_cards.py --only systems # a new system +``` + ## Step 4: Add verification logic Check how the platform verifies BIOS files by reading its source code. @@ -606,8 +616,8 @@ Read the platform's source code to understand its exact verification behavior be An exporter writes the platform's own BIOS file back, updated with what the emulator code shows. Every registered platform has one, unless its registry entry says `native_list: none`: `tests/test_exporters_contract.py` fails otherwise. -Exporters live in `scripts/exporter/` and are found the same way as scrapers -(`*_exporter.py`). +Exporters live in `scripts/exporter/`, where `discover_exporters` finds each +one by its file name (`*_exporter.py`). ### Module contract @@ -692,8 +702,8 @@ something that no longer runs. Target scrapers determine which emulator cores are available on each hardware target (e.g. which RetroArch cores exist for Switch, RPi4, or x86_64). -They live in `scripts/scraper/targets/` and are auto-discovered by filename -(`*_targets_scraper.py`). +They live in `scripts/scraper/targets/`, where `discover_target_scrapers()` +finds each one by its file name (`*_targets_scraper.py`). ### Module contract @@ -833,6 +843,7 @@ Verification is not optional. A platform that passes `pipeline.py` today may bre - [ ] Entry added to `platforms/_registry.yml` - [ ] Guide added to `platforms/_guides.yml` - [ ] Platform YAML generated and verified +- [ ] Sharing cards drawn (`make_og_cards.py --only platforms`, `--only systems`) - [ ] `python scripts/pipeline.py --offline` passes - [ ] Exporter in `scripts/exporter/_exporter.py`, unless the registry says `native_list: none` - [ ] Target scraper in `scripts/scraper/targets/_targets_scraper.py` (if applicable) diff --git a/wiki/adding-a-scraper.md b/wiki/adding-a-scraper.md index a3c430ba9..a253d069c 100644 --- a/wiki/adding-a-scraper.md +++ b/wiki/adding-a-scraper.md @@ -17,26 +17,30 @@ every scraper extends. ## Scraper architecture -### Plugin discovery +### How a scraper is run -Scrapers are discovered automatically at import time. The `scripts/scraper/__init__.py` -module uses `pkgutil.iter_modules` to scan for files matching `*_scraper.py` in -the scraper directory. Each module must export: +A platform scraper is the module `scripts/scraper/_scraper.py`, where +`` is the value of the platform's `scraper:` field in +`platforms/_registry.yml` (`scraper: libretro` names `libretro_scraper.py`, +shared by RetroArch and Lakka). `platform_scraper` in +`scripts/freshness/scrapers.py` turns that field into the module that +`check_freshness.py` and `refresh_stale.py` run: -- `PLATFORM_NAME: str` - the platform identifier (matches `_registry.yml`) -- `Scraper: class` - a subclass of `BaseScraper` - -No registration code is needed. Drop a file, export the two names, and it works. - -```python -# scripts/scraper/__init__.py (simplified) -for finder, name, ispkg in pkgutil.iter_modules([package_dir]): - if not name.endswith("_scraper"): - continue - module = importlib.import_module(f".{name}", package=__package__) - # looks for PLATFORM_NAME and Scraper attributes +```bash +python -m scripts.scraper._scraper ``` +Nothing scans the directory: a file the registry does not name is never run. +The module defines a `Scraper` class extending `BaseScraper` and a `main()` +that hands it to `scraper_cli`. `PLATFORM_NAME` names the platform where the +module reads its own registry entry or pinned revision. + +The other subjects have a folder of their own under `scripts/scraper/`: +`targets/` (hardware targets), `romfolders/` (each setup's rom folders), +`launchers/` (what each platform's launch code reads), `arcade/` (MAME and +FBNeo hashes and romset recipes) and `dats/` (DAT readers and the dump +catalogs). + ### BaseScraper ABC `BaseScraper` (`scripts/scraper/base_scraper.py`) provides the foundation: @@ -258,8 +262,8 @@ A few rules keep that transcription honest: ## Creating a target scraper Target scrapers determine which emulator cores are available on each hardware -target. They live in `scripts/scraper/targets/` and follow the same auto-discovery -pattern (`*_targets_scraper.py`). +target. They live in `scripts/scraper/targets/`, where `discover_target_scrapers()` +finds each one by its file name (`*_targets_scraper.py`). ### BaseTargetScraper ABC @@ -364,8 +368,10 @@ Register the target scraper in `_registry.yml`: ## Parser modules -Shared parsers in `scripts/scraper/` handle formats used by multiple scrapers -or formats complex enough to warrant dedicated parsing logic. +Shared parsers handle formats used by multiple scrapers or formats complex +enough to warrant dedicated parsing logic. The DAT readers are in +`scripts/scraper/dats/`, the MAME and FBNeo source readers in +`scripts/scraper/arcade/`. ### dat_parser diff --git a/wiki/architecture.md b/wiki/architecture.md index de8d8c821..04ac850f0 100644 --- a/wiki/architecture.md +++ b/wiki/architecture.md @@ -48,6 +48,9 @@ scripts/ all tooling (Python and pyyaml, jsonschema for schema c games/ the games-on-card rules and the index the installer reads for them scraper/ upstream scrapers (libretro, batocera, recalbox...) scraper/targets/ hardware target scrapers (one *_targets_scraper.py per platform) + scraper/launchers/ what each platform's launch code reads and passes to a core + scraper/arcade/ MAME and FBNeo hash scrapers, romset recipe and arcade parent importers + scraper/dats/ DAT readers and the No-Intro, Redump and TOSEC catalog importers exporter/ native format exporters (batocera, recalbox, emudeck...), the truth diff sitegen/ the site and README generators: pages, navigation, data files probes/ real-condition runs: the campaign, the pack, region and standalone probes @@ -224,9 +227,9 @@ whoever asked for it: - A pack built with `--emulator` answers to that emulator, and takes its file. `scripts/slots.py` prints each contested destination and the reason for its -winner (`python scripts/slots.py --platform retrobat`), as `slots.arbitrate()` +winner (`python scripts/slots.py --platform retrobat`), as `packs.slots.arbitrate()` decides it. `generate_pack.py`, the install manifest and `verify.py` all read -`slots.slot_choices()` through `slots.pack_overrides()`, which applies the same +`packs.slots.slot_choices()` through `packs.slots.pack_overrides()`, which applies the same order, so the pack, the installer and the report agree. A platform YAML is regenerated by its scraper and never edited by hand: an diff --git a/wiki/tools.md b/wiki/tools.md index 221ee250e..d154e351e 100644 --- a/wiki/tools.md +++ b/wiki/tools.md @@ -400,7 +400,7 @@ and a core of the system opens sets its profile does not list. BizHawk and MiSTer resolve no core, so nothing is examined and nothing is listed. A destination the platform's own list declares twice, for two different -files, is written under `doubled` (`slots.find_collisions` finds it). One +files, is written under `doubled` (`resolve.collisions.find_collisions` finds it). One path holds one file, so one of the two checks fails on every install. When both are archives and one holds every member of the other, that one ships: a MAME core reads members, never the container, so the larger set @@ -793,8 +793,8 @@ committed. | `native/` | `generate_truth.py --platform `, `export_native.py --platform --refresh-cache`, then the export itself | | `targets/` | the target scraper | | `data/` | `refresh_data_dirs.py --key --force` | -| `catalogs/mame recipes`, `catalogs/fbneo recipes` | `scraper/romset_dat_importer.py --source --fetch` | -| `catalogs/no-intro games`, `catalogs/redump games` | `scraper/game_dat_importer.py --source --fetch --refresh --floor` | +| `catalogs/mame recipes`, `catalogs/fbneo recipes` | `scraper/arcade/romset_dat_importer.py --source --fetch` | +| `catalogs/no-intro games`, `catalogs/redump games` | `scraper/dats/game_dat_importer.py --source --fetch --refresh --floor` | | `ci/install.py pin` | `pin_installer.py` | Rows that need a decision are listed and never run: a buildbot core with no @@ -1414,7 +1414,7 @@ before a release (wiki/release-process.md). Its lines stay in | `validate_site.py` | Validate rendered metadata, heading order, image alternatives, JSON-LD, local resources, links and fragments, and the page size and search index budgets | | `indexnow.py` | List the pages a deploy changes, read against the `digests.json` the live site serves, as the IndexNow request the deploy posts once the new site is live. `--dist` names the built site, `--output` appends the request to a step output | | `romset_recipes.py` | Identify which emulator version an arcade archive matches, rebuild a pinned archive from ROMs already held, record a recipe for every archive the collection holds and build any of them from the members it holds (see [Archive recipes](#archive-recipes)) | -| `scraper/romset_dat_importer.py` | Fetch and import per-set recipes from MAME `-listxml` or FBNeo DATs into `recipes/`. `--fetch` alone takes the newest MAME release, and FBNeo DATs are refreshed by git blob sha. `--fetch ` reads FBNeo at that tag, branch or commit | +| `scraper/arcade/romset_dat_importer.py` | Fetch and import per-set recipes from MAME `-listxml` or FBNeo DATs into `recipes/`. `--fetch` alone takes the newest MAME release, and FBNeo DATs are refreshed by git blob sha. `--fetch ` reads FBNeo at that tag, branch or commit | | `core/torrentzip.py` | Build TorrentZip archives for MAME/FBNeo ROM sets (archive bytes depend only on contents, with stock zlib), streaming one member at a time | | `core/cryptoverify.py` | 3DS RSA signature and AES crypto verification | | `core/sect233r1.py` | Pure Python ECDSA verification on sect233r1 curve (3DS OTP cert) | @@ -1427,6 +1427,19 @@ before a release (wiki/release-process.md). Its lines stay in | `bios_integrity.py` | Rehash every file the database names, restore a confirmed bit flip of a committed file from HEAD (see above) | | `sync_release_assets.py` | Upload the `large-files` assets the release serves out of date, after a double SHA-1 check (see above) | | `migrate.py` | Migrate flat bios structure to Manufacturer/Console/ hierarchy | +| `build_port.py`, `build_pypi.py`, `generate_launcher_index.py` | The handheld launcher archives, the PyPI package and `install/launchers/index.json`: see [Changing the installer](installer.md#changing-the-installer) and [Cutting a release](release-process.md#cutting-a-release) | + +### Site assets + +Run by hand when what they draw changes. The site build reads what they +committed and never runs them. + +| Script | Writes | +|--------|--------| +| `make_og_cards.py` | The sharing cards (Open Graph PNG): one per section, per platform and per manufacturer's systems page (`--only platforms`, `--only systems`). Needs Playwright | +| `make_site_icons.py` | The site's logo and favicons, and the repository's logos, banners and social preview, all from the one chip mark. Needs Playwright for the PNG files | +| `fetch_site_images.py` | Local copies of the platform logos and system icons, normalised to one size, with a `sources.json` naming where each came from (`--only logos`). Needs Pillow | +| `site_diagrams.py` | Every site diagram as SVG under `--output-dir` (default `tmp/diagrams`), to look at one outside a page. The site build draws them itself | Further options, by script: @@ -1460,10 +1473,10 @@ Further options, by script: | `validate_pr.py` | `--changed` takes the BIOS files the branch changes, a folder named checks every file under it, `--place` copies each recognised file from outside `bios/` to its folder and declared name (or its `.variants/` slot), `--markdown`, `--json` | | `validate_site.py` | `--site-dir` (rendered site, default `website/dist`), `--base` (path the site is served under), `--max-errors N` | | `scraper/coreinfo_scraper.py` | `--compare-db database.json` lists the `.info` firmware the database lacks | -| `scraper/mame_hash_scraper.py` | `--release mameNNNN --profile FILE --source-commit SHA --core NAME --built-by PLATFORM` writes the profile of a MAME build a platform compiles. `--devices --listxml FILE` documents in `mame.yml` every device set with dumped ROMs that the release's `-listxml` names (`isdevice="yes"`), with `--dry-run` to preview | -| `scraper/romset_dat_importer.py` | `--cache-dir` (downloaded listxml and DATs) | -| `scraper/game_dat_importer.py` | `--source no-intro\|redump` (repeatable), `--pack FILE` imports a local ZIP, directory or DAT, `--refresh` asks the servers again, `--cache-dir`, `--output-dir`, `--dry-run` | -| `scraper/arcade_parent_importer.py` | `--profile NAME` (one core version), `--emulators-dir`, `--db` (BIOS roots checked against it by archive name), `--output-dir`, `--cache-dir`, `--offline`, `--dry-run` | +| `scraper/arcade/mame_hash_scraper.py` | `--release mameNNNN --profile FILE --source-commit SHA --core NAME --built-by PLATFORM` writes the profile of a MAME build a platform compiles. `--devices --listxml FILE` documents in `mame.yml` every device set with dumped ROMs that the release's `-listxml` names (`isdevice="yes"`), with `--dry-run` to preview | +| `scraper/arcade/romset_dat_importer.py` | `--cache-dir` (downloaded listxml and DATs) | +| `scraper/dats/game_dat_importer.py` | `--source no-intro\|redump` (repeatable), `--pack FILE` imports a local ZIP, directory or DAT, `--refresh` asks the servers again, `--cache-dir`, `--output-dir`, `--dry-run` | +| `scraper/arcade/arcade_parent_importer.py` | `--profile NAME` (one core version), `--emulators-dir`, `--db` (BIOS roots checked against it by archive name), `--output-dir`, `--cache-dir`, `--offline`, `--dry-run` | | `scraper/romfolders` | `--sources DIR` (default `platforms/romfolders/_sources`), `--output-dir`, `--dry-run` | | `game_rules.py` | `--regions`, `--extras`, `--headers` (files checked against the profiles and the header readers), `--emulators-dir`, `--json` | | `generate_games_index.py` | `--output-dir` (default `install/games`), `--check`, `--quiet` | @@ -1528,10 +1541,10 @@ publish theirs without a browser: MAME ships its `-listxml` as a release asset, FBNeo keeps its DATs in the repository. ```bash -python -m scripts.scraper.romset_dat_importer --source mame --fetch mame0289 -python -m scripts.scraper.romset_dat_importer --source mame --fetch mame0250 -python -m scripts.scraper.romset_dat_importer --source fbneo --fetch -python -m scripts.scraper.romset_dat_importer --source fbneo --fetch v1.0.0.02 +python -m scripts.scraper.arcade.romset_dat_importer --source mame --fetch mame0289 +python -m scripts.scraper.arcade.romset_dat_importer --source mame --fetch mame0250 +python -m scripts.scraper.arcade.romset_dat_importer --source fbneo --fetch +python -m scripts.scraper.arcade.romset_dat_importer --source fbneo --fetch v1.0.0.02 ``` FBNeo DATs are read at one commit: the revision named (tag, branch or commit, @@ -1650,8 +1663,9 @@ The rules for asset names, uploads and checks are on the Located in `scripts/scraper/`. Each platform scraper inherits `BaseScraper` and implements its two abstract methods, `fetch_requirements()` and -`validate_format()`. The MAME and FBNeo hash scrapers read a source tree and -stand alone. +`validate_format()`. The MAME and FBNeo hash scrapers, in `scraper/arcade/`, read +a source tree and stand alone. The launcher readers are in `scraper/launchers/` +and the DAT readers in `scraper/dats/`. | Scraper | Source | Format | |---------|--------|--------| @@ -1671,8 +1685,8 @@ stand alone. | `minui_scraper`, `nextui_scraper`, `myminui_scraper` | each pak's `launch.sh` (`EMU_EXE`, the tag from the pak folder), each device's `cores/makefile` (the repository a library is built from) and the minarch statement that sets `core.bios_dir` | Shell, Make, C | | `coreinfo_scraper` | .info files from libretro-core-info | INI-like | | `bizhawk_scraper` | FirmwareDatabase.cs | C# source | -| `mame_hash_scraper` | mamedev/mame source tree. `--release mameNNNN` writes the profile of one release a platform builds. `--devices --listxml FILE` adds the device ROM sets of the release's `-listxml` | C source (sparse clone), listxml | -| `fbneo_hash_scraper` | FBNeo source tree | C source (sparse clone) | +| `arcade/mame_hash_scraper` | mamedev/mame source tree. `--release mameNNNN` writes the profile of one release a platform builds. `--devices --listxml FILE` adds the device ROM sets of the release's `-listxml` | C source (sparse clone), listxml | +| `arcade/fbneo_hash_scraper` | FBNeo source tree | C source (sparse clone) | A machine that instantiates a device loads the device's ROMs from `.zip`, and a missing ROM that is neither optional nor @@ -1720,18 +1734,18 @@ downloads that release's `-listxml` into `.cache/dats/` and runs the device merge itself, so the BIOS root sets and the device sets name one release. ```bash -python -m scripts.scraper.mame_hash_scraper --devices --listxml .cache/dats/mame0289lx.zip --dry-run -python -m scripts.scraper.mame_hash_scraper --devices --listxml .cache/dats/mame0289lx.zip +python -m scripts.scraper.arcade.mame_hash_scraper --devices --listxml .cache/dats/mame0289lx.zip --dry-run +python -m scripts.scraper.arcade.mame_hash_scraper --devices --listxml .cache/dats/mame0289lx.zip ``` Internal modules: `base_scraper.py` (abstract base with `_fetch_raw()` caching, -the GitHub and text fetches, and the shared CLI), `dat_parser.py` (clrmamepro DAT format parser), -`logiqx_parser.py` (Logiqx XML DAT parser, used by the dump catalogs), -`mame_parser.py` (MAME C source BIOS root set parser), -`fbneo_parser.py` (FBNeo C source BIOS set parser), -`dat_fetch.py` (upstream MAME `-listxml` and FBNeo DATs, cached under `.cache/dats/`), -`_hash_merge.py` (fetched hashes merged into a profile), `_hash_write.py` (text-based YAML -patching that preserves formatting), `_mame_sections.py` (the generated MAME device and +the GitHub and text fetches, and the shared CLI), `dats/dat_parser.py` (clrmamepro DAT format parser), +`dats/logiqx_parser.py` (Logiqx XML DAT parser, used by the dump catalogs), +`arcade/mame_parser.py` (MAME C source BIOS root set parser), +`arcade/fbneo_parser.py` (FBNeo C source BIOS set parser), +`arcade/dat_fetch.py` (upstream MAME `-listxml` and FBNeo DATs, cached under `.cache/dats/`), +`arcade/_hash_merge.py` (fetched hashes merged into a profile), `arcade/_hash_write.py` (text-based YAML +patching that preserves formatting), `arcade/_mame_sections.py` (the generated MAME device and software list sections). Adding a scraper: inherit `BaseScraper`, implement `fetch_requirements()` and @@ -1746,10 +1760,10 @@ refreshed manually. `generate_db.py` joins them into `database.json`, and `provenance_report.py` reports the gaps. ```bash -python -m scripts.scraper.redump_dat_scraper --dry-run -python -m scripts.scraper.redump_dat_scraper --output provenance/redump.json -python -m scripts.scraper.dat_pack_importer --source no-intro --pack no-intro.zip -python -m scripts.scraper.dat_pack_importer --source tosec --pack TOSEC-v2025.zip +python -m scripts.scraper.dats.redump_dat_scraper --dry-run +python -m scripts.scraper.dats.redump_dat_scraper --output provenance/redump.json +python -m scripts.scraper.dats.dat_pack_importer --source no-intro --pack no-intro.zip +python -m scripts.scraper.dats.dat_pack_importer --source tosec --pack TOSEC-v2025.zip python scripts/provenance_report.py # coverage summary (pipeline step 1b) python scripts/provenance_report.py --missing # list acquisition targets python scripts/provenance_report.py --missing --derive # mark targets a held dump already contains @@ -1792,9 +1806,9 @@ from sources and published under `install/games/` by pipeline step 4e. python -m scripts.scraper.romfolders --list # setups and the format each is read in python -m scripts.scraper.romfolders --all # platforms/romfolders/.yml at the pins of _sources/ python -m scripts.scraper.romfolders --setup batocera --offline -python -m scripts.scraper.game_dat_importer --fetch --floor # games/catalogs/: No-Intro and Redump game DATs -python -m scripts.scraper.game_dat_importer --floor # same from .cache/game-dats/ only -python -m scripts.scraper.arcade_parent_importer --all # games/arcade/: game set to BIOS parent, per core +python -m scripts.scraper.dats.game_dat_importer --fetch --floor # games/catalogs/: No-Intro and Redump game DATs +python -m scripts.scraper.dats.game_dat_importer --floor # same from .cache/game-dats/ only +python -m scripts.scraper.arcade.arcade_parent_importer --all # games/arcade/: game set to BIOS parent, per core python scripts/game_rules.py # games/regions.yml and games/extras.yml against the profiles python scripts/generate_games_index.py # install/games/ (pipeline step 4e) python scripts/generate_games_index.py --check # exit 1 when a published file would change @@ -1804,10 +1818,10 @@ python scripts/generate_games_index.py --check # exit 1 when a publ |--------|-----------|-------| | `platforms/romfolders/_sources/.yml` | hand, each fact with its `source_ref` | pins, roms root, case rule, folders never scanned | | `platforms/romfolders/.yml` | `scraper/romfolders` | folders, extensions and default core as the OS writes them | -| `games/catalogs//.json` | `scraper/game_dat_importer.py` | crc32, size, sha1, region and title per game, disc serials | +| `games/catalogs//.json` | `scraper/dats/game_dat_importer.py` | crc32, size, sha1, region and title per game, disc serials | | `games/headers.yml` | hand, cited | header fields each core reads and the region each value means | | `games/regions.yml`, `games/extras.yml` | hand, cited | region routes, the cases that keep every region, per-game files | -| `games/arcade/.json` | `scraper/arcade_parent_importer.py` | BIOS parent and device sets of each game set, from the DAT the pin names or, for mame2000, mame2003 and mame2003-plus, from the driver code | +| `games/arcade/.json` | `scraper/arcade/arcade_parent_importer.py` | BIOS parent and device sets of each game set, from the DAT the pin names or, for mame2000, mame2003 and mame2003-plus, from the driver code | Folder names resolve to systems through `SYSTEM_ALIASES` and `norm_system_id` in `scripts/model/systems.py`, the one alias table, and core names to profiles through the