From 20b8dfaf3f25f0258ab71c99b38145f615e5ff93 Mon Sep 17 00:00:00 2001 From: sobolevn Date: Wed, 8 Oct 2025 10:34:58 +0300 Subject: [PATCH 1/3] gh-139590: Stricter `ruff` rules for `Tools/wasm` --- Tools/wasm/.ruff.toml | 6 ------ 1 file changed, 6 deletions(-) diff --git a/Tools/wasm/.ruff.toml b/Tools/wasm/.ruff.toml index aabcf8dc4f502e..f5d74fdb6afe87 100644 --- a/Tools/wasm/.ruff.toml +++ b/Tools/wasm/.ruff.toml @@ -20,9 +20,3 @@ select = [ "W", # pycodestyle "YTT", # flake8-2020 ] -ignore = [ - "E501", # Line too long - "F541", # f-string without any placeholders - "PYI024", # Use `typing.NamedTuple` instead of `collections.namedtuple` - "PYI025", # Use `from collections.abc import Set as AbstractSet` -] From f85cd3148243b8717600c599f4fb98120ba01d12 Mon Sep 17 00:00:00 2001 From: sobolevn Date: Wed, 8 Oct 2025 12:43:00 +0300 Subject: [PATCH 2/3] Also enable `ruff check` --- .pre-commit-config.yaml | 4 ++++ Tools/wasm/.ruff.toml | 3 +++ Tools/wasm/emscripten/__main__.py | 9 ++++----- Tools/wasm/emscripten/wasm_assets.py | 5 ++--- Tools/wasm/wasi/__main__.py | 10 ++++------ 5 files changed, 17 insertions(+), 14 deletions(-) diff --git a/.pre-commit-config.yaml b/.pre-commit-config.yaml index 0e00ffb3bd2d66..55c659844682ac 100644 --- a/.pre-commit-config.yaml +++ b/.pre-commit-config.yaml @@ -34,6 +34,10 @@ repos: name: Run Ruff (format) on Tools/build/check_warnings.py args: [--check, --config=Tools/build/.ruff.toml] files: ^Tools/build/check_warnings.py + - id: ruff-check + name: Run Ruff (lint) on Tools/wasm/ + args: [--exit-non-zero-on-fix, --config=Tools/wasm/.ruff.toml] + files: ^Tools/wasm/ - id: ruff-format name: Run Ruff (format) on Tools/wasm/ args: [--check, --config=Tools/wasm/.ruff.toml] diff --git a/Tools/wasm/.ruff.toml b/Tools/wasm/.ruff.toml index f5d74fdb6afe87..3d8e59fa3f22c4 100644 --- a/Tools/wasm/.ruff.toml +++ b/Tools/wasm/.ruff.toml @@ -20,3 +20,6 @@ select = [ "W", # pycodestyle "YTT", # flake8-2020 ] +ignore = [ + "E501", # Line too long +] diff --git a/Tools/wasm/emscripten/__main__.py b/Tools/wasm/emscripten/__main__.py index fdf3142c0a3b1a..c88e9edba6d230 100644 --- a/Tools/wasm/emscripten/__main__.py +++ b/Tools/wasm/emscripten/__main__.py @@ -3,16 +3,16 @@ import argparse import contextlib import functools +import hashlib import os import shutil import subprocess import sys import sysconfig -import hashlib import tempfile -from urllib.request import urlopen from pathlib import Path from textwrap import dedent +from urllib.request import urlopen try: from os import process_cpu_count as cpu_count @@ -33,9 +33,7 @@ PREFIX_DIR = CROSS_BUILD_DIR / HOST_TRIPLE / "prefix" LOCAL_SETUP = CHECKOUT / "Modules" / "Setup.local" -LOCAL_SETUP_MARKER = "# Generated by Tools/wasm/emscripten.py\n".encode( - "utf-8" -) +LOCAL_SETUP_MARKER = b"# Generated by Tools/wasm/emscripten.py\n" def updated_env(updates={}): @@ -432,6 +430,7 @@ def main(): make_build, configure_host, make_host, + clean, ): subcommand.add_argument( "--quiet", diff --git a/Tools/wasm/emscripten/wasm_assets.py b/Tools/wasm/emscripten/wasm_assets.py index 90f318f319a9f1..384790872353b2 100755 --- a/Tools/wasm/emscripten/wasm_assets.py +++ b/Tools/wasm/emscripten/wasm_assets.py @@ -15,7 +15,6 @@ import sys import sysconfig import zipfile -from typing import Dict # source directory SRCDIR = pathlib.Path(__file__).parents[3].absolute() @@ -134,7 +133,7 @@ def filterfunc(filename: str) -> bool: pzf.writepy(entry, filterfunc=filterfunc) -def detect_extension_modules(args: argparse.Namespace) -> Dict[str, bool]: +def detect_extension_modules(args: argparse.Namespace) -> dict[str, bool]: modules = {} # disabled by Modules/Setup.local ? @@ -149,7 +148,7 @@ def detect_extension_modules(args: argparse.Namespace) -> Dict[str, bool]: # disabled by configure? with open(args.sysconfig_data) as f: data = f.read() - loc: Dict[str, Dict[str, str]] = {} + loc: dict[str, dict[str, str]] = {} exec(data, globals(), loc) for key, value in loc["build_time_vars"].items(): diff --git a/Tools/wasm/wasi/__main__.py b/Tools/wasm/wasi/__main__.py index a0658cb351a86f..b2f643ddbfc213 100644 --- a/Tools/wasm/wasi/__main__.py +++ b/Tools/wasm/wasi/__main__.py @@ -16,7 +16,6 @@ import sysconfig import tempfile - CHECKOUT = pathlib.Path(__file__).parent.parent.parent.parent assert (CHECKOUT / "configure").is_file(), ( "Please update the location of the file" @@ -28,9 +27,9 @@ LOCAL_SETUP = CHECKOUT / "Modules" / "Setup.local" LOCAL_SETUP_MARKER = ( - "# Generated by Tools/wasm/wasi .\n" - "# Required to statically build extension modules." -).encode("utf-8") + b"# Generated by Tools/wasm/wasi .\n" + b"# Required to statically build extension modules." +) WASI_SDK_VERSION = 24 @@ -154,8 +153,7 @@ def build_python_is_pydebug(): test = "import sys, test.support; sys.exit(test.support.Py_DEBUG)" result = subprocess.run( [build_python_path(), "-c", test], - stdout=subprocess.PIPE, - stderr=subprocess.PIPE, + capture_output=True, ) return bool(result.returncode) From 458a45b2ef6aab15bae929d75b292627b2bc0498 Mon Sep 17 00:00:00 2001 From: sobolevn Date: Wed, 8 Oct 2025 14:05:24 +0300 Subject: [PATCH 3/3] Update .pre-commit-config.yaml --- .pre-commit-config.yaml | 8 ++++---- 1 file changed, 4 insertions(+), 4 deletions(-) diff --git a/.pre-commit-config.yaml b/.pre-commit-config.yaml index 55c659844682ac..b0311f052798ad 100644 --- a/.pre-commit-config.yaml +++ b/.pre-commit-config.yaml @@ -26,6 +26,10 @@ repos: name: Run Ruff (lint) on Tools/peg_generator/ args: [--exit-non-zero-on-fix, --config=Tools/peg_generator/.ruff.toml] files: ^Tools/peg_generator/ + - id: ruff-check + name: Run Ruff (lint) on Tools/wasm/ + args: [--exit-non-zero-on-fix, --config=Tools/wasm/.ruff.toml] + files: ^Tools/wasm/ - id: ruff-format name: Run Ruff (format) on Doc/ args: [--check] @@ -34,10 +38,6 @@ repos: name: Run Ruff (format) on Tools/build/check_warnings.py args: [--check, --config=Tools/build/.ruff.toml] files: ^Tools/build/check_warnings.py - - id: ruff-check - name: Run Ruff (lint) on Tools/wasm/ - args: [--exit-non-zero-on-fix, --config=Tools/wasm/.ruff.toml] - files: ^Tools/wasm/ - id: ruff-format name: Run Ruff (format) on Tools/wasm/ args: [--check, --config=Tools/wasm/.ruff.toml]