From 48d88da16820cd8e7c64a42b26140993d2938cbe Mon Sep 17 00:00:00 2001 From: Abdessamad Derraz <3028866+Abdess@users.noreply.github.com> Date: Sat, 21 Nov 2026 15:34:27 +0100 Subject: [PATCH] refactor: move six command run modes to packages generate_db, generate_games_index, download, romset_recipes, validate_pr and list_platforms keep only main and build_parser: the database build goes to collection.run, the games index run to games.run, the pack info and its no-pack message to release.packinfo, the capture and build runs to romrecipes.runs, the file selection to resolve.reviewfiles. Tests reach the moved code through those packages. --- scripts/collection/run.py | 79 +++++++++++++++++++++++++++++++++ scripts/download.py | 32 +------------ scripts/games/run.py | 38 ++++++++++++++++ scripts/generate_db.py | 74 ++---------------------------- scripts/generate_games_index.py | 34 ++------------ scripts/list_platforms.py | 7 +-- scripts/release/packinfo.py | 39 ++++++++++++++++ scripts/resolve/reviewfiles.py | 22 +++++++++ scripts/romrecipes/runs.py | 55 +++++++++++++++++++++++ scripts/romset_recipes.py | 50 ++------------------- scripts/validate_pr.py | 26 +---------- tests/sources.py | 7 +-- tests/test_doc_pages.py | 4 +- tests/test_download.py | 14 +----- tests/test_games_index.py | 3 +- tests/test_site_bootstrap.py | 2 +- 16 files changed, 257 insertions(+), 229 deletions(-) create mode 100644 scripts/collection/run.py create mode 100644 scripts/games/run.py create mode 100644 scripts/release/packinfo.py create mode 100644 scripts/romrecipes/runs.py diff --git a/scripts/collection/run.py b/scripts/collection/run.py new file mode 100644 index 000000000..5e36e8b88 --- /dev/null +++ b/scripts/collection/run.py @@ -0,0 +1,79 @@ +"""One database.json build: scan bios/, join aliases and provenance, write the record.""" + +from __future__ import annotations + +import argparse +import sys +from pathlib import Path + +from collection.aliases import UnreadableSource, add_declared_aliases +from collection.declared import declarations +from collection.hashcache import CACHE_FILE, load_cache, save_cache +from collection.indexes import database_indexes +from collection.record import database_record, record_retired, write_database +from collection.releaseassets import preserve_large_file_entries +from collection.scan import scan_bios_dir +from model import retired +from model.dumpcatalog import annotate_provenance, load_provenance_snapshots + + +def generate(args: argparse.Namespace) -> int: + """Scan bios/ and write the database, 1 when a declared source cannot be read.""" + bios_dir = Path(args.bios_dir) + + # A forced run rehashes every file but keeps the previous digests to + # check the new ones against. + cache = load_cache(CACHE_FILE) + + print(f"Scanning {bios_dir}/ ...") + files, aliases, new_cache = scan_bios_dir(bios_dir, cache, args.force) + + if not files: + print("Warning: No BIOS files found", file=sys.stderr) + + # Preserve entries for large files stored as release assets (.gitignore) + preserved = preserve_large_file_entries(files, args.output) + if preserved: + print(f" Preserved {preserved} large file entries from existing database") + + shadowed: list[tuple[str, set[str], list[str]]] = [] + try: + add_declared_aliases(files, aliases, shadowed) + except UnreadableSource as exc: + for source in exc.sources: + print(f"Error: cannot read {source}", file=sys.stderr) + print(f"Error: {args.output} not written", file=sys.stderr) + return 1 + + snapshots = load_provenance_snapshots(args.provenance_dir) + provenance_counts = annotate_provenance(files, snapshots) + + indexes = database_indexes( + files, aliases, shadowed, declarations(Path("platforms"), Path("emulators")) + ) + database = database_record(files, indexes, args.bios_dir) + total_size = database["total_size"] + + output = Path(args.output) + left = record_retired(output, database) + if left: + print(f" Left the collection: {left} files, recorded in " + f"{retired.retired_path(output)}") + + written = write_database(args.output, database) + + save_cache(CACHE_FILE, new_cache) + + alias_count = sum(len(v) for v in aliases.values()) + name_count = len(indexes["by_name"]) + status = "Generated" if written else "Unchanged" + print(f"{status} {args.output}: {len(files)} files, {total_size:,} bytes total") + print(f" Name index: {name_count} names ({alias_count} aliases)") + if provenance_counts: + matched = sum(1 for e in files.values() if "provenance" in e) + per_source = ", ".join( + f"{source} {count}" for source, count in sorted(provenance_counts.items()) + ) + print(f" Provenance: {matched} files catalog-matched ({per_source})") + return 0 + diff --git a/scripts/download.py b/scripts/download.py index 88299a99c..3953745fa 100644 --- a/scripts/download.py +++ b/scripts/download.py @@ -27,37 +27,12 @@ import urllib.error from pathlib import Path sys.path.insert(0, os.path.dirname(__file__)) -from core.sizes import size_text -from core.text import count_text from core.upstream import UpstreamError from core.ziptools import safe_extract_zip from release.latest import get_latest_release from release.packfetch import fetch_checksums, fetch_pack, make_staging from release.packgroups import find_pack, list_platforms - -# A release publishes packs for the setups most people download. The others -# are served file by file by the installer. -NO_PACK_HINT = ( - "A setup without a pack is served by the installer:\n" - " curl -fsSL https://abdess.github.io/retrobios/i | sh -s -- --platform " -) - - -def show_info(platform: str, release: dict) -> None: - """Show pack information for a platform.""" - pack = find_pack(release, platform) - if not pack: - print(f"Platform '{platform}' not found in release.") - print("Available:", ", ".join(list_platforms(release))) - print(NO_PACK_HINT) - sys.exit(1) - - print(f" Platform: {pack.platform}") - print(f" File: {pack.name}") - print(f" Parts: {count_text(len(pack.parts), 'part')}") - print(f" Size: {pack.size:,} bytes ({size_text(pack.size)})") - for part in pack.parts: - print(f" {part['name']} ({part.get('size', 0):,} bytes)") +from release.packinfo import exit_without_pack, show_info def main() -> None: @@ -121,10 +96,7 @@ To check files already in place, use: python install.py --check pack = find_pack(release, args.platform) if not pack: - print(f"Platform '{args.platform}' not found in release.") - print("Available:", ", ".join(list_platforms(release))) - print(NO_PACK_HINT) - sys.exit(1) + exit_without_pack(args.platform, release) dest = Path(os.path.expanduser(args.dest)) dest.mkdir(parents=True, exist_ok=True) diff --git a/scripts/games/run.py b/scripts/games/run.py new file mode 100644 index 000000000..060a6a432 --- /dev/null +++ b/scripts/games/run.py @@ -0,0 +1,38 @@ +"""One games index run: render, hold the coverage floor, then write or check install/games/.""" + +from __future__ import annotations + +import argparse +import sys + +from games.changes import describe_change +from games.coverage import floor_failures, print_coverage +from games.publish import pending, write +from games.render import render + + +def index(args: argparse.Namespace) -> int: + """Render the index, then write it, or with --check name what would change.""" + files, coverage = render(args.output_dir) + if not (args.quiet or args.check): + print_coverage(coverage, files) + failures = floor_failures(coverage) + for failure in failures: + print(f"FLOOR {failure}", file=sys.stderr) + changed, stale = pending(files, args.output_dir) + if args.check: + for path in changed: + print(f"STALE {path}", file=sys.stderr) + current = path.read_text(encoding="utf-8") if path.exists() else None + for line in describe_change(current, files[path]): + print(f" {line}", file=sys.stderr) + for path in stale: + print(f"STALE {path}", file=sys.stderr) + print(" no longer generated", file=sys.stderr) + if changed or stale: + print("Run python scripts/generate_games_index.py to write them.", file=sys.stderr) + return 1 if changed or stale or failures else 0 + write(files, changed, stale) + print(f"{len(changed)} written, {len(stale)} removed") + return 1 if failures else 0 + diff --git a/scripts/generate_db.py b/scripts/generate_db.py index 2ec761447..374e413b2 100644 --- a/scripts/generate_db.py +++ b/scripts/generate_db.py @@ -13,21 +13,13 @@ from __future__ import annotations import argparse import os import sys -from pathlib import Path sys.path.insert(0, os.path.dirname(__file__)) from core.cli import add_repo_inputs, require_directory -from model.dumpcatalog import annotate_provenance, DEFAULT_PROVENANCE_DIR, load_provenance_snapshots +from model.dumpcatalog import DEFAULT_PROVENANCE_DIR from core.artifacts import repository_output_lock from model.safeparse import require_yaml -from model import retired -from collection.aliases import UnreadableSource, add_declared_aliases -from collection.declared import declarations -from collection.hashcache import CACHE_FILE, load_cache, save_cache -from collection.indexes import database_indexes -from collection.record import database_record, record_retired, write_database -from collection.releaseassets import preserve_large_file_entries -from collection.scan import scan_bios_dir +from collection.run import generate # Platform and profile aliases are read from YAML: without pyyaml the # database lost every one of them and the run still exited 0. @@ -51,67 +43,7 @@ def main() -> int: args = parser.parse_args() require_directory(args.bios_dir) with repository_output_lock(args.output): - return _generate(args) - - -def _generate(args: argparse.Namespace) -> int: - bios_dir = Path(args.bios_dir) - - # A forced run rehashes every file but keeps the previous digests to - # check the new ones against. - cache = load_cache(CACHE_FILE) - - print(f"Scanning {bios_dir}/ ...") - files, aliases, new_cache = scan_bios_dir(bios_dir, cache, args.force) - - if not files: - print("Warning: No BIOS files found", file=sys.stderr) - - # Preserve entries for large files stored as release assets (.gitignore) - preserved = preserve_large_file_entries(files, args.output) - if preserved: - print(f" Preserved {preserved} large file entries from existing database") - - shadowed: list[tuple[str, set[str], list[str]]] = [] - try: - add_declared_aliases(files, aliases, shadowed) - except UnreadableSource as exc: - for source in exc.sources: - print(f"Error: cannot read {source}", file=sys.stderr) - print(f"Error: {args.output} not written", file=sys.stderr) - return 1 - - snapshots = load_provenance_snapshots(args.provenance_dir) - provenance_counts = annotate_provenance(files, snapshots) - - indexes = database_indexes( - files, aliases, shadowed, declarations(Path("platforms"), Path("emulators")) - ) - database = database_record(files, indexes, args.bios_dir) - total_size = database["total_size"] - - output = Path(args.output) - left = record_retired(output, database) - if left: - print(f" Left the collection: {left} files, recorded in " - f"{retired.retired_path(output)}") - - written = write_database(args.output, database) - - save_cache(CACHE_FILE, new_cache) - - alias_count = sum(len(v) for v in aliases.values()) - name_count = len(indexes["by_name"]) - status = "Generated" if written else "Unchanged" - print(f"{status} {args.output}: {len(files)} files, {total_size:,} bytes total") - print(f" Name index: {name_count} names ({alias_count} aliases)") - if provenance_counts: - matched = sum(1 for e in files.values() if "provenance" in e) - per_source = ", ".join( - f"{source} {count}" for source, count in sorted(provenance_counts.items()) - ) - print(f" Provenance: {matched} files catalog-matched ({per_source})") - return 0 + return generate(args) if __name__ == "__main__": diff --git a/scripts/generate_games_index.py b/scripts/generate_games_index.py index 23c885825..bb3babd6b 100644 --- a/scripts/generate_games_index.py +++ b/scripts/generate_games_index.py @@ -38,11 +38,8 @@ sys.path.insert(0, str(Path(__file__).resolve().parent.parent)) from core.artifacts import repository_output_lock from core.cli import run_cli -from games.changes import describe_change -from games.coverage import floor_failures, print_coverage from games.inputs import OUTPUT -from games.publish import pending, write -from games.render import render +from games.run import index def main() -> int: @@ -54,34 +51,9 @@ def main() -> int: parser.add_argument("--quiet", action="store_true", help="print only failures") args = parser.parse_args() if args.check: - return _index(args) + return index(args) with repository_output_lock(str(args.output_dir)): - return _index(args) - - -def _index(args: argparse.Namespace) -> int: - files, coverage = render(args.output_dir) - if not (args.quiet or args.check): - print_coverage(coverage, files) - failures = floor_failures(coverage) - for failure in failures: - print(f"FLOOR {failure}", file=sys.stderr) - changed, stale = pending(files, args.output_dir) - if args.check: - for path in changed: - print(f"STALE {path}", file=sys.stderr) - current = path.read_text(encoding="utf-8") if path.exists() else None - for line in describe_change(current, files[path]): - print(f" {line}", file=sys.stderr) - for path in stale: - print(f"STALE {path}", file=sys.stderr) - print(" no longer generated", file=sys.stderr) - if changed or stale: - print("Run python scripts/generate_games_index.py to write them.", file=sys.stderr) - return 1 if changed or stale or failures else 0 - write(files, changed, stale) - print(f"{len(changed)} written, {len(stale)} removed") - return 1 if failures else 0 + return index(args) if __name__ == "__main__": diff --git a/scripts/list_platforms.py b/scripts/list_platforms.py index 5465a35b4..b7af1e4df 100644 --- a/scripts/list_platforms.py +++ b/scripts/list_platforms.py @@ -18,11 +18,6 @@ from core.paths import PLATFORMS_DIR from model.registry import list_registered_platforms -def list_platforms() -> list[str]: - """Every registered platform.""" - return list_registered_platforms(PLATFORMS_DIR) - - def main() -> None: parser = argparse.ArgumentParser(allow_abbrev=False, description="List available platforms") args = parser.parse_args() @@ -30,7 +25,7 @@ def main() -> None: work_from_repo_root(args, parser, []) - platforms = list_platforms() + platforms = list_registered_platforms(PLATFORMS_DIR) if not platforms: print("No platform configs found", file=sys.stderr) diff --git a/scripts/release/packinfo.py b/scripts/release/packinfo.py new file mode 100644 index 000000000..dfe05d7c5 --- /dev/null +++ b/scripts/release/packinfo.py @@ -0,0 +1,39 @@ +"""What download.py prints about one platform's pack, or about its absence from a release.""" + +from __future__ import annotations + +import sys +from typing import NoReturn + +from core.sizes import size_text +from core.text import count_text +from release.packgroups import find_pack, list_platforms + +# A release publishes packs for the setups most people download. The others +# are served file by file by the installer. +NO_PACK_HINT = ( + "A setup without a pack is served by the installer:\n" + " curl -fsSL https://abdess.github.io/retrobios/i | sh -s -- --platform " +) + + +def exit_without_pack(platform: str, release: dict) -> NoReturn: + """Name the packs the release holds and point to the installer, exit 1.""" + print(f"Platform '{platform}' not found in release.") + print("Available:", ", ".join(list_platforms(release))) + print(NO_PACK_HINT) + sys.exit(1) + + +def show_info(platform: str, release: dict) -> None: + """Show pack information for a platform.""" + pack = find_pack(release, platform) + if not pack: + exit_without_pack(platform, release) + + print(f" Platform: {pack.platform}") + print(f" File: {pack.name}") + print(f" Parts: {count_text(len(pack.parts), 'part')}") + print(f" Size: {pack.size:,} bytes ({size_text(pack.size)})") + for part in pack.parts: + print(f" {part['name']} ({part.get('size', 0):,} bytes)") diff --git a/scripts/resolve/reviewfiles.py b/scripts/resolve/reviewfiles.py index 5a0bc4343..e5099f68a 100644 --- a/scripts/resolve/reviewfiles.py +++ b/scripts/resolve/reviewfiles.py @@ -11,6 +11,8 @@ from typing import TYPE_CHECKING from core.gitclone import compare_base, git_lines if TYPE_CHECKING: + import argparse + from resolve.review import ValidationResult @@ -65,6 +67,26 @@ def expand_folders(paths: list[str]) -> list[str]: return out +def files_to_validate(args: argparse.Namespace, parser: argparse.ArgumentParser) -> list[str]: + """The files named on the command line, or the changed ones.""" + if args.changed and args.files: + # Named files were dropped for the git diff, and the run reported + # "No changed BIOS files detected" about files it never looked at. + parser.error("--changed reads the git diff: name files or pass --changed, not both") + if not args.changed: + if not args.files: + parser.error("No files specified. Use --changed or provide file paths.") + return expand_folders(args.files) + try: + files = get_changed_files() + except (RuntimeError, OSError) as exc: + print(f"Error: {exc}", file=sys.stderr) + sys.exit(2) + if not files and not args.json: + print("No changed BIOS files detected") + return files + + def place(results: list[ValidationResult]) -> list[str]: """Copy each placeable file to its destination, never over a file. diff --git a/scripts/romrecipes/runs.py b/scripts/romrecipes/runs.py new file mode 100644 index 000000000..e4ea96704 --- /dev/null +++ b/scripts/romrecipes/runs.py @@ -0,0 +1,55 @@ +"""The --capture and --build runs of romset_recipes.py: their checks, output and exit codes.""" + +from __future__ import annotations + +import argparse +import sys +from pathlib import Path + +from core.torrentzip import zlib_ng_version +from romrecipes.build import AtomIndex, BuildTally, build_records, build_targets +from romrecipes.capture import ZlibNgError, capture_ledger +from romrecipes.ledger import load_ledger +from romrecipes.text import print_build_result, print_build_totals, print_capture + + +def run_capture(args: argparse.Namespace, db: dict) -> int: + """Write recipes/archives.json for every archive the database lists.""" + try: + run = capture_ledger( + Path(args.archives), db, args.emulators_dir, args.dat_recipes, args.platforms_dir, + ) + except ZlibNgError as exc: + print(f"ERROR: {exc}", file=sys.stderr) + return 2 + print_capture(run, args.archives) + return 1 if run.failed else 0 + + +def run_build(args: argparse.Namespace, db: dict) -> int: + """Build one archive, or all of them, from the members the collection holds.""" + if not args.output_dir: + print("ERROR: --build and --build-all need --output-dir", file=sys.stderr) + return 2 + ledger = load_ledger(Path(args.archives)) + records = build_targets(ledger, None if args.build_all else args.build) + if not records and not args.build_all: + print(f"ERROR: no archive recipe named {args.build}", file=sys.stderr) + return 2 + ng = zlib_ng_version() + if ng: + print( + f" zlib-ng {ng} in use: TorrentZip bytes are stock zlib's output, so no " + "build is claimed exact here; exact recipes are checked by their members" + ) + root = Path(args.bios_dir).resolve().parent + atoms = AtomIndex.from_collection(ledger, db, root) + tally = BuildTally() + for result in build_records(records, atoms, Path(args.output_dir), root, args.discard): + tally.add(result) + print_build_result(result) + print_build_totals(tally, len(records)) + if tally.counts["failed"]: + print("ERROR: a build did not match its recipe and was not kept", file=sys.stderr) + return 1 + return 1 if tally.counts["impossible"] else 0 diff --git a/scripts/romset_recipes.py b/scripts/romset_recipes.py index 51ab55a4f..0427bb304 100644 --- a/scripts/romset_recipes.py +++ b/scripts/romset_recipes.py @@ -51,55 +51,11 @@ from pathlib import Path sys.path.insert(0, str(Path(__file__).resolve().parent)) from core.cli import add_repo_inputs, require_directory -from core.torrentzip import zlib_ng_version from model.database import load_database -from romrecipes.build import AtomIndex, BuildTally, build_records, build_targets -from romrecipes.capture import ZlibNgError, capture_ledger -from romrecipes.ledger import ARCHIVES_FILE, load_ledger +from romrecipes.ledger import ARCHIVES_FILE +from romrecipes.runs import run_build, run_capture from romrecipes.survey import survey, survey_modes -from romrecipes.text import print_build_result, print_build_totals, print_capture, print_survey - - -def run_capture(args: argparse.Namespace, db: dict) -> int: - """Write recipes/archives.json for every archive the database lists.""" - try: - run = capture_ledger( - Path(args.archives), db, args.emulators_dir, args.dat_recipes, args.platforms_dir, - ) - except ZlibNgError as exc: - print(f"ERROR: {exc}", file=sys.stderr) - return 2 - print_capture(run, args.archives) - return 1 if run.failed else 0 - - -def run_build(args: argparse.Namespace, db: dict) -> int: - """Build one archive, or all of them, from the members the collection holds.""" - if not args.output_dir: - print("ERROR: --build and --build-all need --output-dir", file=sys.stderr) - return 2 - ledger = load_ledger(Path(args.archives)) - records = build_targets(ledger, None if args.build_all else args.build) - if not records and not args.build_all: - print(f"ERROR: no archive recipe named {args.build}", file=sys.stderr) - return 2 - ng = zlib_ng_version() - if ng: - print( - f" zlib-ng {ng} in use: TorrentZip bytes are stock zlib's output, so no " - "build is claimed exact here; exact recipes are checked by their members" - ) - root = Path(args.bios_dir).resolve().parent - atoms = AtomIndex.from_collection(ledger, db, root) - tally = BuildTally() - for result in build_records(records, atoms, Path(args.output_dir), root, args.discard): - tally.add(result) - print_build_result(result) - print_build_totals(tally, len(records)) - if tally.counts["failed"]: - print("ERROR: a build did not match its recipe and was not kept", file=sys.stderr) - return 1 - return 1 if tally.counts["impossible"] else 0 +from romrecipes.text import print_survey def build_parser() -> argparse.ArgumentParser: diff --git a/scripts/validate_pr.py b/scripts/validate_pr.py index ac140aa19..70957571e 100644 --- a/scripts/validate_pr.py +++ b/scripts/validate_pr.py @@ -27,32 +27,10 @@ sys.path.insert(0, os.path.dirname(__file__)) from model.database import load_optional_database from core.cli import add_repo_inputs, require_directory from resolve.review import load_platform_hashes, load_profile_hashes, validate_file -from resolve.reviewfiles import expand_folders, get_changed_files, place +from resolve.reviewfiles import files_to_validate, place from resolve.reviewreport import json_rows, markdown_report, text_lines -def _files_to_validate( - args: argparse.Namespace, parser: argparse.ArgumentParser -) -> list: - """The files named on the command line, or the changed ones.""" - if args.changed and args.files: - # Named files were dropped for the git diff, and the run reported - # "No changed BIOS files detected" about files it never looked at. - parser.error("--changed reads the git diff: name files or pass --changed, not both") - if not args.changed: - if not args.files: - parser.error("No files specified. Use --changed or provide file paths.") - return expand_folders(args.files) - try: - files = get_changed_files() - except (RuntimeError, OSError) as exc: - print(f"Error: {exc}", file=sys.stderr) - sys.exit(2) - if not files and not args.json: - print("No changed BIOS files detected") - return files - - def main() -> None: parser = argparse.ArgumentParser(allow_abbrev=False, description="Validate BIOS file contributions") parser.add_argument("files", nargs="*", help="Files to validate") @@ -85,7 +63,7 @@ def main() -> None: args.files = [os.path.abspath(f) for f in args.files] work_from_repo_root(args, parser, ["db", "platforms_dir", "emulators_dir"]) - files = _files_to_validate(args, parser) + files = files_to_validate(args, parser) if not files: if args.json: print("[]") diff --git a/tests/sources.py b/tests/sources.py index 76bfac057..354ee1d34 100644 --- a/tests/sources.py +++ b/tests/sources.py @@ -82,7 +82,7 @@ COMMANDS = { "romrecipes/romsets.py", "romrecipes/pool.py", "romrecipes/pins.py", "romrecipes/identify.py", "romrecipes/ledger.py", "romrecipes/members.py", "romrecipes/capture.py", "romrecipes/build.py", "romrecipes/survey.py", - "romrecipes/text.py", + "romrecipes/text.py", "romrecipes/runs.py", ), "provenance_report.py": ("acquire/provenance.py",), "auto_fetch.py": ("acquire/fetch.py",), @@ -116,7 +116,7 @@ COMMANDS = { "generate_db.py": ( "collection/scan.py", "collection/hashcache.py", "collection/releaseassets.py", "collection/declared.py", "collection/aliases.py", "collection/indexes.py", - "collection/record.py", + "collection/record.py", "collection/run.py", ), "bios_integrity.py": ("collection/integrity.py", "collection/gitrestore.py"), "game_rules.py": ( @@ -126,10 +126,11 @@ COMMANDS = { "generate_games_index.py": ( "games/inputs.py", "games/profileindex.py", "games/fallback.py", "games/folders.py", "games/setups.py", "games/systems.py", "games/arcadesets.py", "games/render.py", - "games/coverage.py", "games/changes.py", "games/publish.py", + "games/coverage.py", "games/changes.py", "games/publish.py", "games/run.py", ), "download.py": ( "release/latest.py", "release/packgroups.py", "release/transfer.py", "release/packfetch.py", + "release/packinfo.py", ), "cleanup_disk.py": ("devtools/diskcleanup.py",), "migrate.py": ("devtools/biosclassify.py", "devtools/biosmigrate.py"), diff --git a/tests/test_doc_pages.py b/tests/test_doc_pages.py index d4f0ba9f0..484832ee2 100644 --- a/tests/test_doc_pages.py +++ b/tests/test_doc_pages.py @@ -1980,14 +1980,12 @@ class NoTextClaimsAScheduledScrape(unittest.TestCase): `schedule:`.""" def test_no_text_ties_the_registry_to_automation(self): - import list_platforms - texts = { "adding-a-platform.md": (WIKI / "adding-a-platform.md").read_text(encoding="utf-8"), "generate_readme": script_source("generate_readme.py"), "generate_site": script_source("generate_site.py"), "generate_pack": script_source("generate_pack.py"), - "list_platforms": inspect.getsource(list_platforms), + "list_platforms": script_source("list_platforms.py"), "_guides.yml": (ROOT / "platforms" / "_guides.yml").read_text(encoding="utf-8"), } for name, text in texts.items(): diff --git a/tests/test_download.py b/tests/test_download.py index f2fea5313..8a53724cf 100644 --- a/tests/test_download.py +++ b/tests/test_download.py @@ -17,13 +17,11 @@ import contextlib import functools import hashlib import http.server -import importlib.util import io import json import os import shutil import subprocess -import sys import tempfile import threading import time @@ -33,17 +31,9 @@ from pathlib import Path from unittest import mock from packs import parts as packs_parts -from release import packfetch, packgroups, transfer +from release import packfetch, packgroups, packinfo, transfer REPO_ROOT = Path(__file__).resolve().parent.parent -_spec = importlib.util.spec_from_file_location( - "download", REPO_ROOT / "scripts" / "download.py" -) -download = importlib.util.module_from_spec(_spec) -# Registered before execution: a dataclass resolves its annotations through -# sys.modules and cannot be built from a module that is not there yet. -sys.modules["download"] = download -_spec.loader.exec_module(download) SHELL = REPO_ROOT / "scripts" / "download.sh" @@ -80,7 +70,7 @@ class TestPackGrouping(unittest.TestCase): """--info printed "not found" and exited 0.""" release = _release(["EmuDeck_2.3.8_BIOS_Pack.zip"]) with contextlib.redirect_stdout(io.StringIO()) as out, self.assertRaises(SystemExit) as caught: - download.show_info("emudek", release) + packinfo.show_info("emudek", release) self.assertEqual(caught.exception.code, 1) self.assertIn("EmuDeck", out.getvalue()) diff --git a/tests/test_games_index.py b/tests/test_games_index.py index 661f05d79..a32fae3e0 100644 --- a/tests/test_games_index.py +++ b/tests/test_games_index.py @@ -18,6 +18,7 @@ from pathlib import Path import generate_games_index as gi import games.fallback as fallback +import games.run as games_run import games.setups as setup_docs from games.changes import describe_change from games.coverage import FLOORS, floor_failures @@ -213,7 +214,7 @@ class CheckSaysWhatDiffers(unittest.TestCase): coverage: dict = {"setups": {}, "systems": {}, "arcade": []} stdout, stderr = io.StringIO(), io.StringIO() argv = ["generate_games_index.py", "--check", "--output-dir", tmp] - with mock.patch.object(gi, "render", return_value=(files, coverage)), \ + with mock.patch.object(games_run, "render", return_value=(files, coverage)), \ mock.patch.object(sys, "argv", argv), \ contextlib.redirect_stdout(stdout), contextlib.redirect_stderr(stderr): code = gi.main() diff --git a/tests/test_site_bootstrap.py b/tests/test_site_bootstrap.py index 37c34fe92..b7d3f59e4 100644 --- a/tests/test_site_bootstrap.py +++ b/tests/test_site_bootstrap.py @@ -175,7 +175,7 @@ class DocumentedCommands(unittest.TestCase): "wiki/tools.md": [install_command("sh"), install_command("powershell")], "website/src/components/FilePicker.astro": [f"'curl -fsSL {INSTALL_SH} | sh -s --'"], "scripts/download.sh": [f"curl -fsSL {INSTALL_SH} | sh -s -- --platform "], - "scripts/download.py": [f"curl -fsSL {INSTALL_SH} | sh -s -- --platform "], + "scripts/release/packinfo.py": [f"curl -fsSL {INSTALL_SH} | sh -s -- --platform "], } for rel, commands in sources.items(): text = (REPO_ROOT / rel).read_text(encoding="utf-8")