From ecf225d0076918260d350e724e3a3b41f27929cd Mon Sep 17 00:00:00 2001 From: Abdessamad Derraz <3028866+Abdess@users.noreply.github.com> Date: Tue, 17 Nov 2026 16:44:35 +0100 Subject: [PATCH] refactor: read platform-only APIs without ignores --- install.ps1 | 2 +- install.py | 50 ++++++++++++++++++++---------- install.sh | 2 +- install/launchers/index.json | 16 +++++----- scripts/profile_sync.py | 60 ++++++++++++++++++------------------ 5 files changed, 74 insertions(+), 56 deletions(-) diff --git a/install.ps1 b/install.ps1 index 57609743d..5cb32b8b1 100644 --- a/install.ps1 +++ b/install.ps1 @@ -16,7 +16,7 @@ # and Invoke-WebRequest throws on a cut transfer before the hash is read: # the site's build rewrites this line there (scripts/sitebootstrap.py). $mismatchAdvice = "The download was most likely cut short: try again. Within minutes of an update of this project the two files can come from caches of different ages. Waiting five minutes settles that." - $defaultInstallSha256 = "cc9b659e56ddd209196f2ab9401ea1530c0d16d944922237dfa37d429b8e1c82" + $defaultInstallSha256 = "4a820bbfc7ed86b684a6fda8db0b19c3c021950b4ab3f1d9f861807afbf6ec7b" # The pin above refuses any changed byte: this cap only stops a body that # cannot be the installer (a sign-in portal's page) before it is hashed. $maximumInstallerBytes = 8MB diff --git a/install.py b/install.py index 61733d97b..73ef7c0fc 100644 --- a/install.py +++ b/install.py @@ -344,6 +344,14 @@ _UMASK = os.umask(0) os.umask(_UMASK) +def _kernel32() -> Any: + """kernel32 from ctypes.windll, which typeshed declares for win32 only. + AttributeError where the system has no windll.""" + import importlib + + return importlib.import_module("ctypes").windll.kernel32 + + def _enable_ansi() -> bool: """Whether escape sequences reach the terminal as colour and redraws. @@ -355,7 +363,7 @@ def _enable_ansi() -> bool: try: import ctypes - kernel32 = ctypes.windll.kernel32 # type: ignore[attr-defined] + kernel32 = _kernel32() handle = kernel32.GetStdHandle(-11) mode = ctypes.c_uint32() if not kernel32.GetConsoleMode(handle, ctypes.byref(mode)): @@ -11213,8 +11221,7 @@ def _drive_not_removable(mount: Path) -> bool: False where it says nothing.""" if os.name == "nt": try: - import ctypes - kind = ctypes.windll.kernel32.GetDriveTypeW(str(mount)) # type: ignore[attr-defined] + kind = _kernel32().GetDriveTypeW(str(mount)) except (AttributeError, OSError): return False return kind in _NOT_REMOVABLE_TYPES @@ -15183,7 +15190,7 @@ def fat32_drive(folder: Path) -> bool: import ctypes root = ctypes.create_unicode_buffer(261) kind = ctypes.create_unicode_buffer(261) - kernel = ctypes.windll.kernel32 # type: ignore[attr-defined] + kernel = _kernel32() if not kernel.GetVolumePathNameW(str(probe), root, 261): return False if not kernel.GetVolumeInformationW(root, None, 0, None, None, None, kind, 261): @@ -15369,14 +15376,19 @@ def plan_pack_parts(name: str, manifest_size: int, members: list[PackMember], count = len(parts) +# ZipInfo's level is private before Python 3.13 (compress_level there, the +# old name kept as its alias), so typeshed does not declare it. +_ZIPINFO_LEVEL = "_compresslevel" + + def _pack_info(name: str, compress: int = zipfile.ZIP_DEFLATED) -> zipfile.ZipInfo: """A member header that depends on its name alone.""" info = zipfile.ZipInfo(name, date_time=PACK_MEMBER_DATE) info.compress_type = compress # A ZipInfo given to writestr or open keeps its own level, the # archive's left unread: without it every member was deflated at 6. - info._compresslevel = ( # type: ignore[attr-defined] - PACK_COMPRESSLEVEL if compress == zipfile.ZIP_DEFLATED else None) + setattr(info, _ZIPINFO_LEVEL, + PACK_COMPRESSLEVEL if compress == zipfile.ZIP_DEFLATED else None) info.create_system = 3 info.external_attr = 0o100644 << 16 return info @@ -15408,7 +15420,7 @@ def _patch_marker(path: Path, marker: str, body: bytes) -> None: data, and the CRC-32 of the local and the central header.""" with zipfile.ZipFile(path) as archive: first = archive.infolist()[0] - central = int(archive.start_dir) # type: ignore[attr-defined] + central = int(archive.start_dir) if first.filename != marker or first.file_size != len(body) or first.header_offset: raise PackError(f"{path.name} does not start with its marker") crc = zlib.crc32(body).to_bytes(4, "little") @@ -30558,8 +30570,8 @@ class _EngineRun: if os.name == "nt" or not self.running(): return try: - os.killpg(self.proc.pid, signal.SIGSTOP if stopped # type: ignore[attr-defined] - else signal.SIGCONT) # type: ignore[attr-defined] + os.killpg(self.proc.pid, signal.SIGSTOP if stopped + else signal.SIGCONT) except ProcessLookupError: # It ended between the two calls: there is nothing to stop. return @@ -30572,7 +30584,9 @@ class _EngineRun: elif from_key: # The child shares the console: Ctrl-C read as a key reached no # one, so it is sent to the console, this process ignoring it. - os.kill(0, signal.CTRL_C_EVENT) # type: ignore[attr-defined] + # typeshed declares CTRL_C_EVENT for win32 only. + ctrl_c: int = vars(signal)["CTRL_C_EVENT"] + os.kill(0, ctrl_c) def stop(self, grace: float) -> None: """End the child, letting it write its summary for up to grace seconds.""" @@ -30836,14 +30850,18 @@ class _TuiTerminal: return self.decoder.feed(self.input.decode(data)) def _console_keys(self, timeout: float) -> list[TuiKey | TuiMouse]: - import msvcrt + import importlib + # typeshed declares msvcrt for win32 only: the module is read as the + # runtime holds it. + msvcrt = importlib.import_module("msvcrt") + kbhit: Callable[[], bool] = msvcrt.kbhit + getwch: Callable[[], str] = msvcrt.getwch end = time.monotonic() + timeout keys: list[TuiKey | TuiMouse] = [] while True: - while msvcrt.kbhit(): # type: ignore[attr-defined] - key = decode_windows_key(msvcrt.getwch(), # type: ignore[attr-defined] - msvcrt.getwch) # type: ignore[attr-defined] + while kbhit(): + key = decode_windows_key(getwch(), getwch) if key is not None: keys.append(key) if keys or time.monotonic() >= end: @@ -31038,9 +31056,9 @@ def tui_suspend(runs: list[_EngineRun], whole: bool) -> None: if whole: # SIGSTOP and not SIGTSTP: a group no shell watches over (the # installer started on a terminal of its own) discards SIGTSTP. - os.killpg(os.getpgrp(), signal.SIGSTOP) # type: ignore[attr-defined] + os.killpg(os.getpgrp(), signal.SIGSTOP) else: - os.kill(os.getpid(), signal.SIGSTOP) # type: ignore[attr-defined] + os.kill(os.getpid(), signal.SIGSTOP) for run in runs: run.pause(False) diff --git a/install.sh b/install.sh index b7cd1e74b..7b7870726 100755 --- a/install.sh +++ b/install.sh @@ -23,7 +23,7 @@ DEFAULT_INSTALL_URL="https://raw.githubusercontent.com/Abdess/retrobios/main/ins # curl or wget stop on a cut transfer before the hash is read: the site's # build rewrites this line there (scripts/sitebootstrap.py). MISMATCH_ADVICE="The download was most likely cut short: try again. Within minutes of an update of this project the two files can come from caches of different ages. Waiting five minutes settles that." -DEFAULT_INSTALL_SHA256="cc9b659e56ddd209196f2ab9401ea1530c0d16d944922237dfa37d429b8e1c82" +DEFAULT_INSTALL_SHA256="4a820bbfc7ed86b684a6fda8db0b19c3c021950b4ab3f1d9f861807afbf6ec7b" # The pin above refuses any changed byte: this cap only stops a body that # cannot be the installer (a sign-in portal's page) before it is hashed. MAX_INSTALLER_BYTES=8388608 diff --git a/install/launchers/index.json b/install/launchers/index.json index aaaba87a6..784ac6a72 100644 --- a/install/launchers/index.json +++ b/install/launchers/index.json @@ -27,8 +27,8 @@ { "dest": "roms/ports/retrobios/install.py", "repo_path": "install.py", - "size": 1439914, - "sha256": "cc9b659e56ddd209196f2ab9401ea1530c0d16d944922237dfa37d429b8e1c82", + "size": 1440188, + "sha256": "4a820bbfc7ed86b684a6fda8db0b19c3c021950b4ab3f1d9f861807afbf6ec7b", "executable": false }, { @@ -71,8 +71,8 @@ "muos": { "archive": { "dest": "ARCHIVE/RetroBIOS.muxapp", - "size": 1493539, - "sha256": "f23c4a056cd9cb85f2ae653a4bbeea329c877be3b6ed69d3212bda7800ec23b3" + "size": 1493813, + "sha256": "95c30064eb47a7cc5d463f68b04479bab1bc6bc26d9d2f7bfbb54ea131490c22" }, "members": [ { @@ -92,8 +92,8 @@ { "name": "RetroBIOS/install.py", "repo_path": "install.py", - "size": 1439914, - "sha256": "cc9b659e56ddd209196f2ab9401ea1530c0d16d944922237dfa37d429b8e1c82", + "size": 1440188, + "sha256": "4a820bbfc7ed86b684a6fda8db0b19c3c021950b4ab3f1d9f861807afbf6ec7b", "executable": false }, { @@ -166,8 +166,8 @@ { "dest": ".config/modules/retrobios/install.py", "repo_path": "install.py", - "size": 1439914, - "sha256": "cc9b659e56ddd209196f2ab9401ea1530c0d16d944922237dfa37d429b8e1c82", + "size": 1440188, + "sha256": "4a820bbfc7ed86b684a6fda8db0b19c3c021950b4ab3f1d9f861807afbf6ec7b", "executable": false }, { diff --git a/scripts/profile_sync.py b/scripts/profile_sync.py index 49991c349..30d7114fb 100644 --- a/scripts/profile_sync.py +++ b/scripts/profile_sync.py @@ -45,36 +45,36 @@ from common import ( system_index, ) from hashing import parse_hash_list -from sourceref import ( # noqa: F401 (re-exported for callers and tests) # noqa: F401 (the prose grammar, re-exported) - _ANNOTATION_RE, - _BARE_RANGE_RE, - _LOCATED_RE, - _PROJECT_WORD_RE, - _PROSE_LIST_DELIMITERS, - _REF_RE, - _SPLIT_RE, - _BINARY_SUFFIXES, - _HEX_ADDRESS_RE, - PROSE_CITE_RE, - PROSE_CONT_RE, - PROSE_CONT_SPACED_RE, - PROSE_EXTENSIONLESS, - PROSE_LINKING_WORDS, - PROSE_LIST_ITEM_RE, - PROSE_WRAPPED_RANGE_RE, - REPO_ROLES, - RefPart, - _prose_external, - _prose_runs, - _trim_prose, - is_binary_citation, - parse_source_ref, - ref_prose_text, - ref_role, - resolve_project_word, - source_ref_values, - split_outside_parentheses, - split_source_ref, +from sourceref import ( # re-exported for callers and tests + _ANNOTATION_RE as _ANNOTATION_RE, + _BARE_RANGE_RE as _BARE_RANGE_RE, + _LOCATED_RE as _LOCATED_RE, + _PROJECT_WORD_RE as _PROJECT_WORD_RE, + _PROSE_LIST_DELIMITERS as _PROSE_LIST_DELIMITERS, + _REF_RE as _REF_RE, + _SPLIT_RE as _SPLIT_RE, + _BINARY_SUFFIXES as _BINARY_SUFFIXES, + _HEX_ADDRESS_RE as _HEX_ADDRESS_RE, + PROSE_CITE_RE as PROSE_CITE_RE, + PROSE_CONT_RE as PROSE_CONT_RE, + PROSE_CONT_SPACED_RE as PROSE_CONT_SPACED_RE, + PROSE_EXTENSIONLESS as PROSE_EXTENSIONLESS, + PROSE_LINKING_WORDS as PROSE_LINKING_WORDS, + PROSE_LIST_ITEM_RE as PROSE_LIST_ITEM_RE, + PROSE_WRAPPED_RANGE_RE as PROSE_WRAPPED_RANGE_RE, + REPO_ROLES as REPO_ROLES, + RefPart as RefPart, + _prose_external as _prose_external, + _prose_runs as _prose_runs, + _trim_prose as _trim_prose, + is_binary_citation as is_binary_citation, + parse_source_ref as parse_source_ref, + ref_prose_text as ref_prose_text, + ref_role as ref_role, + resolve_project_word as resolve_project_word, + source_ref_values as source_ref_values, + split_outside_parentheses as split_outside_parentheses, + split_source_ref as split_source_ref, ) from upstream import CompareResult, find_renamed