Skip to content

Commit 49ea8a0

Browse files
authored
Lint: Use Ruff to format Tools/build/check_warnings.py (python#133317)
1 parent fac41f5 commit 49ea8a0

File tree

3 files changed

+25
-28
lines changed

3 files changed

+25
-28
lines changed

.pre-commit-config.yaml

+5-5
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,6 @@
11
repos:
22
- repo: https://github.com/astral-sh/ruff-pre-commit
3-
rev: v0.11.6
3+
rev: v0.11.8
44
hooks:
55
- id: ruff
66
name: Run Ruff (lint) on Doc/
@@ -22,14 +22,14 @@ repos:
2222
name: Run Ruff (format) on Doc/
2323
args: [--check]
2424
files: ^Doc/
25+
- id: ruff-format
26+
name: Run Ruff (format) on Tools/build/check_warnings.py
27+
args: [--check, --config=Tools/build/.ruff.toml]
28+
files: ^Tools/build/check_warnings.py
2529

2630
- repo: https://github.com/psf/black-pre-commit-mirror
2731
rev: 25.1.0
2832
hooks:
29-
- id: black
30-
name: Run Black on Tools/build/check_warnings.py
31-
files: ^Tools/build/check_warnings.py
32-
args: [--line-length=79]
3333
- id: black
3434
name: Run Black on Tools/jit/
3535
files: ^Tools/jit/

Tools/build/.ruff.toml

+8-4
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,13 @@
11
extend = "../../.ruff.toml" # Inherit the project-wide settings
22

3+
[per-file-target-version]
4+
"deepfreeze.py" = "py310"
5+
"stable_abi.py" = "py311" # requires 'tomllib'
6+
7+
[format]
8+
preview = true
9+
docstring-code-format = true
10+
311
[lint]
412
select = [
513
"C4", # flake8-comprehensions
@@ -24,10 +32,6 @@ ignore = [
2432
"UP038", # Use `X | Y` in `isinstance` call instead of `(X, Y)`
2533
]
2634

27-
[per-file-target-version]
28-
"deepfreeze.py" = "py310"
29-
"stable_abi.py" = "py311" # requires 'tomllib'
30-
3135
[lint.per-file-ignores]
3236
"{check_extension_modules,freeze_modules}.py" = [
3337
"UP031", # Use format specifiers instead of percent format

Tools/build/check_warnings.py

+12-19
Original file line numberDiff line numberDiff line change
@@ -83,17 +83,13 @@ def extract_warnings_from_compiler_output(
8383
for i, line in enumerate(compiler_output.splitlines(), start=1):
8484
if match := compiled_regex.match(line):
8585
try:
86-
compiler_warnings.append(
87-
{
88-
"file": match.group("file").removeprefix(path_prefix),
89-
"line": match.group("line"),
90-
"column": match.group("column"),
91-
"message": match.group("message"),
92-
"option": match.group("option")
93-
.lstrip("[")
94-
.rstrip("]"),
95-
}
96-
)
86+
compiler_warnings.append({
87+
"file": match.group("file").removeprefix(path_prefix),
88+
"line": match.group("line"),
89+
"column": match.group("column"),
90+
"message": match.group("message"),
91+
"option": match.group("option").lstrip("[").rstrip("]"),
92+
})
9793
except AttributeError:
9894
print(
9995
f"Error parsing compiler output. "
@@ -151,7 +147,6 @@ def get_unexpected_warnings(
151147
"""
152148
unexpected_warnings = {}
153149
for file in files_with_warnings.keys():
154-
155150
rule = is_file_ignored(file, ignore_rules)
156151

157152
if rule:
@@ -201,13 +196,11 @@ def get_unexpected_improvements(
201196
if rule.file_path not in files_with_warnings.keys():
202197
unexpected_improvements.append((rule.file_path, rule.count, 0))
203198
elif len(files_with_warnings[rule.file_path]) < rule.count:
204-
unexpected_improvements.append(
205-
(
206-
rule.file_path,
207-
rule.count,
208-
len(files_with_warnings[rule.file_path]),
209-
)
210-
)
199+
unexpected_improvements.append((
200+
rule.file_path,
201+
rule.count,
202+
len(files_with_warnings[rule.file_path]),
203+
))
211204

212205
if unexpected_improvements:
213206
print("Unexpected improvements:")

0 commit comments

Comments
 (0)