Skip to content

Commit 678e0b8

Browse files
authored
gh-139590: Stricter ruff rules for Tools/wasm (#139752)
1 parent a2850a3 commit 678e0b8

File tree

5 files changed

+14
-17
lines changed

5 files changed

+14
-17
lines changed

.pre-commit-config.yaml

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -26,6 +26,10 @@ repos:
2626
name: Run Ruff (lint) on Tools/peg_generator/
2727
args: [--exit-non-zero-on-fix, --config=Tools/peg_generator/.ruff.toml]
2828
files: ^Tools/peg_generator/
29+
- id: ruff-check
30+
name: Run Ruff (lint) on Tools/wasm/
31+
args: [--exit-non-zero-on-fix, --config=Tools/wasm/.ruff.toml]
32+
files: ^Tools/wasm/
2933
- id: ruff-format
3034
name: Run Ruff (format) on Doc/
3135
args: [--check]

Tools/wasm/.ruff.toml

Lines changed: 0 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -22,7 +22,4 @@ select = [
2222
]
2323
ignore = [
2424
"E501", # Line too long
25-
"F541", # f-string without any placeholders
26-
"PYI024", # Use `typing.NamedTuple` instead of `collections.namedtuple`
27-
"PYI025", # Use `from collections.abc import Set as AbstractSet`
2825
]

Tools/wasm/emscripten/__main__.py

Lines changed: 4 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -3,16 +3,16 @@
33
import argparse
44
import contextlib
55
import functools
6+
import hashlib
67
import os
78
import shutil
89
import subprocess
910
import sys
1011
import sysconfig
11-
import hashlib
1212
import tempfile
13-
from urllib.request import urlopen
1413
from pathlib import Path
1514
from textwrap import dedent
15+
from urllib.request import urlopen
1616

1717
try:
1818
from os import process_cpu_count as cpu_count
@@ -33,9 +33,7 @@
3333
PREFIX_DIR = CROSS_BUILD_DIR / HOST_TRIPLE / "prefix"
3434

3535
LOCAL_SETUP = CHECKOUT / "Modules" / "Setup.local"
36-
LOCAL_SETUP_MARKER = "# Generated by Tools/wasm/emscripten.py\n".encode(
37-
"utf-8"
38-
)
36+
LOCAL_SETUP_MARKER = b"# Generated by Tools/wasm/emscripten.py\n"
3937

4038

4139
def updated_env(updates={}):
@@ -432,6 +430,7 @@ def main():
432430
make_build,
433431
configure_host,
434432
make_host,
433+
clean,
435434
):
436435
subcommand.add_argument(
437436
"--quiet",

Tools/wasm/emscripten/wasm_assets.py

Lines changed: 2 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -15,7 +15,6 @@
1515
import sys
1616
import sysconfig
1717
import zipfile
18-
from typing import Dict
1918

2019
# source directory
2120
SRCDIR = pathlib.Path(__file__).parents[3].absolute()
@@ -134,7 +133,7 @@ def filterfunc(filename: str) -> bool:
134133
pzf.writepy(entry, filterfunc=filterfunc)
135134

136135

137-
def detect_extension_modules(args: argparse.Namespace) -> Dict[str, bool]:
136+
def detect_extension_modules(args: argparse.Namespace) -> dict[str, bool]:
138137
modules = {}
139138

140139
# disabled by Modules/Setup.local ?
@@ -149,7 +148,7 @@ def detect_extension_modules(args: argparse.Namespace) -> Dict[str, bool]:
149148
# disabled by configure?
150149
with open(args.sysconfig_data) as f:
151150
data = f.read()
152-
loc: Dict[str, Dict[str, str]] = {}
151+
loc: dict[str, dict[str, str]] = {}
153152
exec(data, globals(), loc)
154153

155154
for key, value in loc["build_time_vars"].items():

Tools/wasm/wasi/__main__.py

Lines changed: 4 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -16,7 +16,6 @@
1616
import sysconfig
1717
import tempfile
1818

19-
2019
CHECKOUT = pathlib.Path(__file__).parent.parent.parent.parent
2120
assert (CHECKOUT / "configure").is_file(), (
2221
"Please update the location of the file"
@@ -28,9 +27,9 @@
2827

2928
LOCAL_SETUP = CHECKOUT / "Modules" / "Setup.local"
3029
LOCAL_SETUP_MARKER = (
31-
"# Generated by Tools/wasm/wasi .\n"
32-
"# Required to statically build extension modules."
33-
).encode("utf-8")
30+
b"# Generated by Tools/wasm/wasi .\n"
31+
b"# Required to statically build extension modules."
32+
)
3433

3534
WASI_SDK_VERSION = 24
3635

@@ -154,8 +153,7 @@ def build_python_is_pydebug():
154153
test = "import sys, test.support; sys.exit(test.support.Py_DEBUG)"
155154
result = subprocess.run(
156155
[build_python_path(), "-c", test],
157-
stdout=subprocess.PIPE,
158-
stderr=subprocess.PIPE,
156+
capture_output=True,
159157
)
160158
return bool(result.returncode)
161159

0 commit comments

Comments
 (0)