gh-139590: Stricter ruff rules for Tools/wasm (#139752)

This commit is contained in:
sobolevn
2025-10-09 01:13:27 +03:00
committed by GitHub
parent a2850a3a91
commit 678e0b818c
5 changed files with 14 additions and 17 deletions

View File

@@ -26,6 +26,10 @@ repos:
name: Run Ruff (lint) on Tools/peg_generator/ name: Run Ruff (lint) on Tools/peg_generator/
args: [--exit-non-zero-on-fix, --config=Tools/peg_generator/.ruff.toml] args: [--exit-non-zero-on-fix, --config=Tools/peg_generator/.ruff.toml]
files: ^Tools/peg_generator/ 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 - id: ruff-format
name: Run Ruff (format) on Doc/ name: Run Ruff (format) on Doc/
args: [--check] args: [--check]

View File

@@ -22,7 +22,4 @@ select = [
] ]
ignore = [ ignore = [
"E501", # Line too long "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`
] ]

View File

@@ -3,16 +3,16 @@
import argparse import argparse
import contextlib import contextlib
import functools import functools
import hashlib
import os import os
import shutil import shutil
import subprocess import subprocess
import sys import sys
import sysconfig import sysconfig
import hashlib
import tempfile import tempfile
from urllib.request import urlopen
from pathlib import Path from pathlib import Path
from textwrap import dedent from textwrap import dedent
from urllib.request import urlopen
try: try:
from os import process_cpu_count as cpu_count from os import process_cpu_count as cpu_count
@@ -33,9 +33,7 @@ HOST_DIR = HOST_BUILD_DIR / "python"
PREFIX_DIR = CROSS_BUILD_DIR / HOST_TRIPLE / "prefix" PREFIX_DIR = CROSS_BUILD_DIR / HOST_TRIPLE / "prefix"
LOCAL_SETUP = CHECKOUT / "Modules" / "Setup.local" LOCAL_SETUP = CHECKOUT / "Modules" / "Setup.local"
LOCAL_SETUP_MARKER = "# Generated by Tools/wasm/emscripten.py\n".encode( LOCAL_SETUP_MARKER = b"# Generated by Tools/wasm/emscripten.py\n"
"utf-8"
)
def updated_env(updates={}): def updated_env(updates={}):
@@ -432,6 +430,7 @@ def main():
make_build, make_build,
configure_host, configure_host,
make_host, make_host,
clean,
): ):
subcommand.add_argument( subcommand.add_argument(
"--quiet", "--quiet",

View File

@@ -15,7 +15,6 @@ import pathlib
import sys import sys
import sysconfig import sysconfig
import zipfile import zipfile
from typing import Dict
# source directory # source directory
SRCDIR = pathlib.Path(__file__).parents[3].absolute() SRCDIR = pathlib.Path(__file__).parents[3].absolute()
@@ -134,7 +133,7 @@ def create_stdlib_zip(
pzf.writepy(entry, filterfunc=filterfunc) 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 = {} modules = {}
# disabled by Modules/Setup.local ? # disabled by Modules/Setup.local ?
@@ -149,7 +148,7 @@ def detect_extension_modules(args: argparse.Namespace) -> Dict[str, bool]:
# disabled by configure? # disabled by configure?
with open(args.sysconfig_data) as f: with open(args.sysconfig_data) as f:
data = f.read() data = f.read()
loc: Dict[str, Dict[str, str]] = {} loc: dict[str, dict[str, str]] = {}
exec(data, globals(), loc) exec(data, globals(), loc)
for key, value in loc["build_time_vars"].items(): for key, value in loc["build_time_vars"].items():

View File

@@ -16,7 +16,6 @@ import sys
import sysconfig import sysconfig
import tempfile import tempfile
CHECKOUT = pathlib.Path(__file__).parent.parent.parent.parent CHECKOUT = pathlib.Path(__file__).parent.parent.parent.parent
assert (CHECKOUT / "configure").is_file(), ( assert (CHECKOUT / "configure").is_file(), (
"Please update the location of the file" "Please update the location of the file"
@@ -28,9 +27,9 @@ BUILD_DIR = CROSS_BUILD_DIR / sysconfig.get_config_var("BUILD_GNU_TYPE")
LOCAL_SETUP = CHECKOUT / "Modules" / "Setup.local" LOCAL_SETUP = CHECKOUT / "Modules" / "Setup.local"
LOCAL_SETUP_MARKER = ( LOCAL_SETUP_MARKER = (
"# Generated by Tools/wasm/wasi .\n" b"# Generated by Tools/wasm/wasi .\n"
"# Required to statically build extension modules." b"# Required to statically build extension modules."
).encode("utf-8") )
WASI_SDK_VERSION = 24 WASI_SDK_VERSION = 24
@@ -154,8 +153,7 @@ def build_python_is_pydebug():
test = "import sys, test.support; sys.exit(test.support.Py_DEBUG)" test = "import sys, test.support; sys.exit(test.support.Py_DEBUG)"
result = subprocess.run( result = subprocess.run(
[build_python_path(), "-c", test], [build_python_path(), "-c", test],
stdout=subprocess.PIPE, capture_output=True,
stderr=subprocess.PIPE,
) )
return bool(result.returncode) return bool(result.returncode)