chore: lint scripts and tests with ruff

pyproject.toml now carries the ruff rule set: pyflakes, the B rules,
simplify, perf, pyupgrade, complexity and size limits. This commit
applies the fixes that change no behavior and the small defects the
first run named:

- tests/test_install.py used argparse without importing it
- three loops rebound the outer `profile` with each layout
  (packextras, slots, verify); the loop variable is now `layout`
- profile_sync loops shadowed dataclasses.field
- generate_readme and packextras computed values nothing read
- stale noqa markers for rules the project does not enforce

Complexity, size and the remaining findings are handled next.
This commit is contained in:
Abdessamad Derraz committed 2026-11-17 07:07:48 +01:00
1 parent 9d8dcb1634
commit 4eacb6ff39
186 files changed
+1001 -1058

No files matched your search

+3 -3
View File
@@ -104,7 +104,7 @@ def configs_root(cg: Configgen) -> dict[str, str]:
starts an emulator from (shadPS4's configs/shadps4), with the lines that
build it and BIOS.
"""
import posixpath # noqa: PLC0415
import posixpath
src = cg.source(f"{cg.generators.rsplit('/', 1)[0]}/batoceraPaths.py")
if "CONFIGS" not in cg.paths:
@@ -1128,9 +1128,9 @@ def search_paths(cg: Configgen) -> list[Launcher]:
"""Every /userdata/bios path a generator's command line names, read as
KNULLI's generic reader reads its fork of the same generator."""
try:
from .knulli_launchers import GenericSites, bios_sites # noqa: PLC0415
from .knulli_launchers import GenericSites, bios_sites
except ImportError:
from knulli_launchers import GenericSites, bios_sites # type: ignore[no-redef] # noqa: PLC0415
from knulli_launchers import GenericSites, bios_sites # type: ignore[no-redef]
# A boot disk image the command line names (the Macintosh's
# /userdata/bios/<boot_disk>.img) is a file, no search path.
return [
+1 -3
View File
@@ -188,9 +188,7 @@ def _calls(scope: ast.AST, attr: str | None = None, name: str | None = None) ->
if not isinstance(node, ast.Call):
continue
func = node.func
if attr is not None and isinstance(func, ast.Attribute) and func.attr == attr:
found.append(node)
elif name is not None and isinstance(func, ast.Name) and func.id == name:
if attr is not None and isinstance(func, ast.Attribute) and func.attr == attr or name is not None and isinstance(func, ast.Name) and func.id == name:
found.append(node)
return sorted(found, key=lambda call: (call.lineno, call.col_offset))
+1 -3
View File
@@ -335,9 +335,7 @@ def main() -> None:
found = 0
missing = []
for r in reqs:
if r.name in db["indexes"]["by_name"]:
found += 1
elif r.md5 and r.md5 in db["indexes"]["by_md5"]:
if r.name in db["indexes"]["by_name"] or r.md5 and r.md5 in db["indexes"]["by_md5"]:
found += 1
else:
missing.append(r)
+3 -3
View File
@@ -335,19 +335,19 @@ class Scraper(BaseScraper):
bios_col = ""
for key in row:
if key and "bios" in key.lower():
bios_col = self._clean_markdown((row[key] or ""))
bios_col = self._clean_markdown(row[key] or "")
break
if not bios_col or bios_col.lower() in ("not required", ""):
continue
folder_col = ""
for key in row:
if key and "folder" in key.lower():
folder_col = self._clean_markdown((row[key] or ""))
folder_col = self._clean_markdown(row[key] or "")
break
system_col = ""
for key in row:
if key and "system" in key.lower():
system_col = self._clean_markdown((row[key] or ""))
system_col = self._clean_markdown(row[key] or "")
break
slug = None
for part in re.split(r"[`\s/]+", folder_col):
-1
View File
@@ -26,7 +26,6 @@ from __future__ import annotations
import argparse
import gzip
import io
import json
import re
import sys
+2 -2
View File
@@ -94,9 +94,9 @@ class Scraper(BaseScraper):
def submodule_revision(self) -> str:
"""The batocera.linux commit KNULLI's batocera submodule pins at the tag."""
import json # noqa: PLC0415
import json
from .base_scraper import github_headers # noqa: PLC0415
from .base_scraper import github_headers
url = _SUBMODULE.format(path=BATOCERA_SUBMODULE, ref=self.tag)
req = urllib.request.Request(url, headers=github_headers())
+1 -1
View File
@@ -572,7 +572,7 @@ def hatari_libretro(sources: dict[str, Source]) -> list[Record]:
guard = src.find(r'if \(core != "hatarib"\)', "hatarib guard")
method = src.enclosing(guard.start())
tos_img = src.find(
rf'string (\w+) = Path\.Combine\((\w+), "([^"]+)"\);', "hatarib tos.img path",
r'string (\w+) = Path\.Combine\((\w+), "([^"]+)"\);', "hatarib tos.img path",
method[0], method[1],
)
own = src.find(
+1 -1
View File
@@ -310,7 +310,7 @@ class Scraper(BaseScraper):
def _fetch_remote_manifests(self) -> list[tuple[str, dict]]:
"""Fetch component manifests via GitHub API."""
from common import github_token # noqa: PLC0415
from common import github_token
token = github_token()
headers = {"User-Agent": "retrobios-scraper/1.0"}
+1 -1
View File
@@ -483,7 +483,7 @@ LIST_SEPARATORS = {"advmame": ":", "advmame-0.94": ":", "advmame-1.4": ":"}
DEFAULT_LIST_SEPARATOR = ";"
def _search_list_in_roms(event: "Event", separator: str = DEFAULT_LIST_SEPARATOR) -> bool:
def _search_list_in_roms(event: Event, separator: str = DEFAULT_LIST_SEPARATOR) -> bool:
"""An iniSet whose value is a list of folders below the roms root.
One folder alone is where a program writes (cfg_directory, nvram_directory
+2 -2
View File
@@ -14,8 +14,8 @@ from pathlib import Path
import yaml
from . import Fetcher, SourceError, load_sources, scrape_setup
from upstream import UpstreamError # noqa: E402 (the package puts scripts/ on sys.path)
from artifacts import write_text_atomic # noqa: E402
from upstream import UpstreamError
from artifacts import write_text_atomic
from ..base_scraper import _PlatformDumper
DEFAULT_DIR = Path("platforms") / "romfolders"
+2 -2
View File
@@ -57,8 +57,8 @@ class BaseTargetScraper(ABC):
"""Write target data to YAML file."""
try:
import yaml
except ImportError:
raise ImportError("PyYAML required: pip install pyyaml")
except ImportError as exc:
raise ImportError("PyYAML required: pip install pyyaml") from exc
from common import write_text_atomic
write_text_atomic(
@@ -68,7 +68,7 @@ _MODULE_FLAGS_RE = re.compile(r'rp_module_flags\s*=\s*["\']([^"\']*)["\']')
def _fetch(url: str, accept: str = "text/plain") -> str:
headers = {"User-Agent": "retrobios-scraper/1.0", "Accept": accept}
from common import github_token # noqa: PLC0415
from common import github_token
token = github_token()
if token and "api.github.com" in url:
@@ -214,7 +214,7 @@ class Scraper(BaseTargetScraper):
return fetch_bytes(f"{RAW_BASE.format(tag=self.tag)}/{path}").decode("utf-8")
def _devices(self) -> list[str]:
import json # noqa: PLC0415
import json
listing = json.loads(fetch_bytes(
f"{GITHUB_API}/{DEVICES_DIR}?ref={self.tag}", headers=github_headers()