diff --git a/scripts/auto_fetch.py b/scripts/auto_fetch.py index 2b3d25f2b..9f21c26a7 100644 --- a/scripts/auto_fetch.py +++ b/scripts/auto_fetch.py @@ -243,6 +243,7 @@ def step2_scan_branches(entry: dict) -> bytes | None: ["git", "ls-tree", "-r", "--name-only", ref], capture_output=True, text=True, + check=False, ) for filepath in result.stdout.strip().split("\n"): diff --git a/scripts/check_buildbot_system.py b/scripts/check_buildbot_system.py index d630bafbc..c6bada126 100644 --- a/scripts/check_buildbot_system.py +++ b/scripts/check_buildbot_system.py @@ -102,10 +102,7 @@ def check(registry_path: str = DEFAULT_REGISTRY) -> dict: buildbot_set = set(index_zips) tracked_set = set(tracked.keys()) - results: list[dict] = [] - - for z in sorted(buildbot_set - tracked_set): - results.append({"zip": z, "status": "NEW", "key": None}) + results: list[dict] = [{"zip": z, "status": "NEW", "key": None} for z in sorted(buildbot_set - tracked_set)] for z in sorted(tracked_set - buildbot_set): key, _ = tracked[z] diff --git a/scripts/check_freshness.py b/scripts/check_freshness.py index dd44d4cc7..3048a7755 100644 --- a/scripts/check_freshness.py +++ b/scripts/check_freshness.py @@ -40,7 +40,7 @@ import subprocess import sys import tempfile import urllib.request -from collections.abc import Iterator +from collections.abc import Container, Iterator from concurrent.futures import ThreadPoolExecutor from dataclasses import asdict, dataclass, field from datetime import datetime, timezone @@ -585,7 +585,7 @@ def _platform_overrides(overrides: dict, platform: str) -> dict: def unresolved_target_cores( - targets: dict, index: dict[str, str], overrides: dict + targets: dict, index: Container[str], overrides: dict ) -> dict[str, list[str]]: """Core names a target ends up with that no profile claims. @@ -618,7 +618,7 @@ def check_targets( ) -> list[Finding]: targets_dir = platforms_dir / "targets" overrides_path = targets_dir / "_overrides.yml" - overrides = {} + overrides: dict = {} if overrides_path.is_file(): with overrides_path.open(encoding="utf-8") as fh: overrides = yaml_load(fh) or {} @@ -1380,7 +1380,7 @@ def specifier_allows(spec: str, version: str) -> bool: for clause in filter(None, (c.strip() for c in spec.split(","))): match = _SPEC_CLAUSE.fullmatch(clause) test = _SPEC_TESTS.get(match.group(1)) if match else None - if test is None or not test(target, _version_tuple(match.group(2))): + if match is None or test is None or not test(target, _version_tuple(match.group(2))): return False return True diff --git a/scripts/check_platform_folder.py b/scripts/check_platform_folder.py index e26fba238..ce13028c6 100644 --- a/scripts/check_platform_folder.py +++ b/scripts/check_platform_folder.py @@ -23,14 +23,14 @@ def accepts(entry: dict, path: Path, mode: str) -> bool: with zipfile.ZipFile(path) as archive: names = {name.casefold(): name for name in archive.namelist()} member = names.get(entry["zipped_file"].casefold()) - return bool(member) and hashlib.new(digest, archive.read(member)).hexdigest() in values + return member is not None and hashlib.new(digest, archive.read(member)).hexdigest() in values actual = hashlib.new(digest, path.read_bytes()).hexdigest() if entry.get("zip_digest") != "composite" and actual in values: return True # whole digests, as batocera-systems:1088 compares them if digest == DIGESTS["md5"] and path.suffix.lower() == ".zip": # Recalbox: members in name order with zipfile.ZipFile(path) as archive: - names = sorted(name for name in archive.namelist() if not name.endswith("/")) - return hashlib.md5(b"".join(map(archive.read, names))).hexdigest() in values + members = sorted(name for name in archive.namelist() if not name.endswith("/")) + return hashlib.md5(b"".join(map(archive.read, members))).hexdigest() in values except (OSError, zipfile.BadZipFile): return False return False @@ -60,7 +60,7 @@ if __name__ == "__main__": except urllib.request.HTTPError as error: # a 404: no platform has that name with urllib.request.urlopen(API.replace("platforms/", "catalog.json")) as response: known = sorted(i["url"][10:-5] for i in json.load(response)["items"] if i["url"].startswith("manifests/")) - sys.exit(f"unknown platform: {sys.argv[1]}. Known: {', '.join(known)}" if error.code == 404 else error) + sys.exit(f"unknown platform: {sys.argv[1]}. Known: {', '.join(known)}" if error.code == 404 else str(error)) except OSError as error: # no such folder, or no network (URLError) sys.exit(f"error: {error}") for verdict in ("ok", "wrong", "missing"): diff --git a/scripts/check_release_assets.py b/scripts/check_release_assets.py index 069bf1ef3..e130f4a89 100644 --- a/scripts/check_release_assets.py +++ b/scripts/check_release_assets.py @@ -90,10 +90,11 @@ def compare( served = next( (name for name in _spellings(names[path]) if name in assets), None ) - published = assets[served] if served else None - if published is None: + if not served: findings.append(AssetFinding("missing", path, size, None)) - elif published != size: + continue + published = assets[served] + if published != size: findings.append(AssetFinding("size", path, size, published)) else: ours = (expected_digests or {}).get(path) diff --git a/scripts/cleanup_disk.py b/scripts/cleanup_disk.py index 1e13da6b4..e2afcce13 100644 --- a/scripts/cleanup_disk.py +++ b/scripts/cleanup_disk.py @@ -29,6 +29,7 @@ Usage: from __future__ import annotations import argparse +import contextlib import os import re import shutil @@ -81,10 +82,8 @@ def busy_paths() -> set[str]: if not pid.name.isdigit(): continue links = [pid / "cwd"] - try: + with contextlib.suppress(OSError): links += list((pid / "fd").iterdir()) - except OSError: - pass for link in links: try: found.add(os.readlink(link)) diff --git a/scripts/game_rules.py b/scripts/game_rules.py index 5cee18b39..12014f947 100644 --- a/scripts/game_rules.py +++ b/scripts/game_rules.py @@ -186,10 +186,10 @@ class Checker: self._files(where, entry["profile"], profile, entry.get("files") or []) header = (entry.get("trigger") or {}).get("header") if header and self.readers is not None: - self._header(where, header) + self._header(where, header, self.readers) - def _header(self, where: str, header: dict) -> None: - reader = self.readers.get(header["reader"]) + def _header(self, where: str, header: dict, readers: dict[str, dict]) -> None: + reader = readers.get(header["reader"]) if reader is None: self.errors.append(f"{where}: games/headers.yml has no reader {header['reader']}") return diff --git a/scripts/measurement_records.py b/scripts/measurement_records.py index a4dc7c802..26435f80c 100644 --- a/scripts/measurement_records.py +++ b/scripts/measurement_records.py @@ -156,9 +156,8 @@ def check_line(record: dict) -> list[str]: problems.append(f"{rid}: id does not hash the first-layout record ({digest})") elif record_id(record) != rid: problems.append(f"{rid}: id does not hash the record ({record_id(record)})") - for key in ("emulator", "subject"): - if not SLUG_PATTERN.match(str(record.get(key, ""))): - problems.append(f"{rid}: {key} {record.get(key)!r} is not a lowercase slug") + problems.extend(f"{rid}: {key} {record.get(key)!r} is not a lowercase slug" + for key in ("emulator", "subject") if not SLUG_PATTERN.match(str(record.get(key, "")))) return problems @@ -227,7 +226,7 @@ def read_records(root: Path) -> list[Stored]: continue if emulator in CAMPAIGN_FILES: continue - seen: set[str] = set() + seen: set[str | None] = set() try: records = parse_lines(files[path].read_text(encoding="utf-8"), path) except RecordError as exc: diff --git a/scripts/pr_checks.py b/scripts/pr_checks.py index 5855469a3..6114c5513 100644 --- a/scripts/pr_checks.py +++ b/scripts/pr_checks.py @@ -82,9 +82,9 @@ def shown(step: Step) -> str: def execute(step: Step) -> int: env = {**os.environ, **step.env} if not step.then: - return subprocess.run(argv(step.command), cwd=ROOT, env=env).returncode - first = subprocess.run(argv(step.command), cwd=ROOT, env=env, stdout=subprocess.PIPE) - return subprocess.run(argv(step.then), cwd=ROOT, env=env, input=first.stdout).returncode + return subprocess.run(argv(step.command), cwd=ROOT, env=env, check=False).returncode + first = subprocess.run(argv(step.command), cwd=ROOT, env=env, stdout=subprocess.PIPE, check=False) + return subprocess.run(argv(step.then), cwd=ROOT, env=env, input=first.stdout, check=False).returncode def run(steps: tuple[Step, ...] = STEPS) -> int: diff --git a/scripts/region_check.py b/scripts/region_check.py index b33bbf77e..a9ee7c49c 100644 --- a/scripts/region_check.py +++ b/scripts/region_check.py @@ -91,8 +91,7 @@ def plan_variants(entries: Iterable[dict], region: str, local: Callable[[dict], Path | None]) -> dict[str, dict[str, Path]]: """The staged files of `full`, `own` and `others`, dest -> file. An entry the collection does not hold is left out of every variant.""" - held = [(entry, local(entry)) for entry in entries] - held = [(entry, path) for entry, path in held if path] + held = [(entry, path) for entry in entries if (path := local(entry))] full = {entry_dest(e): p for e, p in held} own = {entry_dest(e): p for e, p in held if region in regions_of(e)} others = {entry_dest(e): p for e, p in held if region not in regions_of(e)} diff --git a/scripts/sect233r1.py b/scripts/sect233r1.py index 258077641..4e6f7127e 100644 --- a/scripts/sect233r1.py +++ b/scripts/sect233r1.py @@ -162,7 +162,7 @@ def _ec_mul(k: int, p: tuple[int, int] | None) -> tuple[int, int] | None: return _INF result = _INF - addend = p + addend: tuple[int, int] | None = p while k: if k & 1: result = _ec_add(result, addend)