Skip to content

Commit 0b80d6a

Browse files
Use ruff format instead
1 parent d8dab97 commit 0b80d6a

File tree

3 files changed

+84
-19
lines changed

3 files changed

+84
-19
lines changed

.pre-commit-config.yaml

Lines changed: 4 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -34,16 +34,17 @@ repos:
3434
name: Run Ruff (format) on Tools/build/check_warnings.py
3535
args: [--check, --config=Tools/build/.ruff.toml]
3636
files: ^Tools/build/check_warnings.py
37+
- id: ruff-format
38+
name: Run Ruff (format) on Tools/wasm/wasi/
39+
args: [--check, --config=Tools/wasm/wasi/.ruff.toml]
40+
files: ^Tools/wasm/wasi/
3741

3842
- repo: https://github.com/psf/black-pre-commit-mirror
3943
rev: 25.9.0
4044
hooks:
4145
- id: black
4246
name: Run Black on Tools/jit/
4347
files: ^Tools/jit/
44-
- id: black
45-
name: Run Black on Tools/wasm/wasi/
46-
files: ^Tools/wasm/wasi/
4748

4849
- repo: https://github.com/Lucas-C/pre-commit-hooks
4950
rev: v1.5.5

Tools/wasm/wasi/.ruff.toml

Lines changed: 40 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,40 @@
1+
extend = "../../../.ruff.toml" # Inherit the project-wide settings
2+
3+
[per-file-target-version]
4+
"deepfreeze.py" = "py311" # requires `code.co_exceptiontable`
5+
"stable_abi.py" = "py311" # requires 'tomllib'
6+
7+
[format]
8+
preview = true
9+
docstring-code-format = true
10+
11+
[lint]
12+
select = [
13+
"C4", # flake8-comprehensions
14+
"E", # pycodestyle
15+
"F", # pyflakes
16+
"I", # isort
17+
"ISC", # flake8-implicit-str-concat
18+
"LOG", # flake8-logging
19+
"PGH", # pygrep-hooks
20+
"PT", # flake8-pytest-style
21+
"PYI", # flake8-pyi
22+
"RUF100", # Ban unused `# noqa` comments
23+
"UP", # pyupgrade
24+
"W", # pycodestyle
25+
"YTT", # flake8-2020
26+
]
27+
ignore = [
28+
"E501", # Line too long
29+
"F541", # f-string without any placeholders
30+
"PYI024", # Use `typing.NamedTuple` instead of `collections.namedtuple`
31+
"PYI025", # Use `from collections.abc import Set as AbstractSet`
32+
]
33+
34+
[lint.per-file-ignores]
35+
"{check_extension_modules,freeze_modules}.py" = [
36+
"UP031", # Use format specifiers instead of percent format
37+
]
38+
"generate_{re_casefix,sre_constants,token}.py" = [
39+
"UP031", # Use format specifiers instead of percent format
40+
]

Tools/wasm/wasi/__main__.py

Lines changed: 40 additions & 16 deletions
Original file line numberDiff line numberDiff line change
@@ -18,7 +18,9 @@
1818

1919

2020
CHECKOUT = pathlib.Path(__file__).parent.parent.parent.parent
21-
assert (CHECKOUT / "configure").is_file(), "Please update the location of the file"
21+
assert (CHECKOUT / "configure").is_file(), (
22+
"Please update the location of the file"
23+
)
2224

2325
CROSS_BUILD_DIR = CHECKOUT / "cross-build"
2426
# Build platform can also be found via `config.guess`.
@@ -45,7 +47,9 @@ def updated_env(updates={}):
4547
# https://reproducible-builds.org/docs/source-date-epoch/
4648
git_epoch_cmd = ["git", "log", "-1", "--pretty=%ct"]
4749
try:
48-
epoch = subprocess.check_output(git_epoch_cmd, encoding="utf-8").strip()
50+
epoch = subprocess.check_output(
51+
git_epoch_cmd, encoding="utf-8"
52+
).strip()
4953
env_defaults["SOURCE_DATE_EPOCH"] = epoch
5054
except subprocess.CalledProcessError:
5155
pass # Might be building from a tarball.
@@ -84,7 +88,11 @@ def wrapper(context):
8488
terminal_width = int(tput_output.strip())
8589
print("⎯" * terminal_width)
8690
print("📁", working_dir)
87-
if clean_ok and getattr(context, "clean", False) and working_dir.exists():
91+
if (
92+
clean_ok
93+
and getattr(context, "clean", False)
94+
and working_dir.exists()
95+
):
8896
print("🚮 Deleting directory (--clean)...")
8997
shutil.rmtree(working_dir)
9098

@@ -134,7 +142,9 @@ def build_python_path():
134142
if not binary.is_file():
135143
binary = binary.with_suffix(".exe")
136144
if not binary.is_file():
137-
raise FileNotFoundError("Unable to find `python(.exe)` in " f"{BUILD_DIR}")
145+
raise FileNotFoundError(
146+
f"Unable to find `python(.exe)` in {BUILD_DIR}"
147+
)
138148

139149
return binary
140150

@@ -178,7 +188,8 @@ def make_build_python(context, working_dir):
178188
cmd = [
179189
binary,
180190
"-c",
181-
"import sys; print(f'{sys.version_info.major}.{sys.version_info.minor}')",
191+
"import sys; "
192+
"print(f'{sys.version_info.major}.{sys.version_info.minor}')",
182193
]
183194
version = subprocess.check_output(cmd, encoding="utf-8").strip()
184195

@@ -239,9 +250,10 @@ def wasi_sdk_env(context):
239250
env["WASI_SDK_PATH"] = os.fsdecode(wasi_sdk_path)
240251
env["WASI_SYSROOT"] = os.fsdecode(sysroot)
241252

242-
env["PATH"] = os.pathsep.join(
243-
[os.fsdecode(wasi_sdk_path / "bin"), os.environ["PATH"]]
244-
)
253+
env["PATH"] = os.pathsep.join([
254+
os.fsdecode(wasi_sdk_path / "bin"),
255+
os.environ["PATH"],
256+
])
245257

246258
return env
247259

@@ -265,12 +277,14 @@ def configure_wasi_python(context, working_dir):
265277

266278
python_build_dir = BUILD_DIR / "build"
267279
lib_dirs = list(python_build_dir.glob("lib.*"))
268-
assert (
269-
len(lib_dirs) == 1
270-
), f"Expected a single lib.* directory in {python_build_dir}"
280+
assert len(lib_dirs) == 1, (
281+
f"Expected a single lib.* directory in {python_build_dir}"
282+
)
271283
lib_dir = os.fsdecode(lib_dirs[0])
272284
python_version = lib_dir.rpartition("-")[-1]
273-
sysconfig_data_dir = f"{wasi_build_dir}/build/lib.wasi-wasm32-{python_version}"
285+
sysconfig_data_dir = (
286+
f"{wasi_build_dir}/build/lib.wasi-wasm32-{python_version}"
287+
)
274288

275289
# Use PYTHONPATH to include sysconfig data which must be anchored to the
276290
# WASI guest's `/` directory.
@@ -326,7 +340,9 @@ def configure_wasi_python(context, working_dir):
326340
def make_wasi_python(context, working_dir):
327341
"""Run `make` for the WASI/host build."""
328342
call(
329-
["make", "--jobs", str(cpu_count()), "all"], env=updated_env(), context=context
343+
["make", "--jobs", str(cpu_count()), "all"],
344+
env=updated_env(),
345+
context=context,
330346
)
331347

332348
exec_script = working_dir / "python.sh"
@@ -394,11 +410,19 @@ def main():
394410
"are inferred from the build "
395411
"Python)",
396412
)
397-
make_host = subcommands.add_parser("make-host", help="Run `make` for the host/WASI")
413+
make_host = subcommands.add_parser(
414+
"make-host", help="Run `make` for the host/WASI"
415+
)
398416
subcommands.add_parser(
399417
"clean", help="Delete files and directories created by this script"
400418
)
401-
for subcommand in build, configure_build, make_build, configure_host, make_host:
419+
for subcommand in (
420+
build,
421+
configure_build,
422+
make_build,
423+
configure_host,
424+
make_host,
425+
):
402426
subcommand.add_argument(
403427
"--quiet",
404428
action="store_true",
@@ -410,7 +434,7 @@ def main():
410434
"--logdir",
411435
type=pathlib.Path,
412436
default=default_logdir,
413-
help="Directory to store log files; " f"defaults to {default_logdir}",
437+
help=f"Directory to store log files; defaults to {default_logdir}",
414438
)
415439
for subcommand in configure_build, configure_host:
416440
subcommand.add_argument(

0 commit comments

Comments
 (0)