Skip to content

Lint: Use Ruff to format Tools/build/check_warnings.py #133317

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Merged
merged 1 commit into from
May 2, 2025
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
10 changes: 5 additions & 5 deletions .pre-commit-config.yaml
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
repos:
- repo: https://github.com/astral-sh/ruff-pre-commit
rev: v0.11.6
rev: v0.11.8
hooks:
- id: ruff
name: Run Ruff (lint) on Doc/
Expand All @@ -22,14 +22,14 @@ repos:
name: Run Ruff (format) on Doc/
args: [--check]
files: ^Doc/
- id: ruff-format
name: Run Ruff (format) on Tools/build/check_warnings.py
args: [--check, --config=Tools/build/.ruff.toml]
files: ^Tools/build/check_warnings.py

- repo: https://github.com/psf/black-pre-commit-mirror
rev: 25.1.0
hooks:
- id: black
name: Run Black on Tools/build/check_warnings.py
files: ^Tools/build/check_warnings.py
args: [--line-length=79]
- id: black
name: Run Black on Tools/jit/
files: ^Tools/jit/
Expand Down
12 changes: 8 additions & 4 deletions Tools/build/.ruff.toml
Original file line number Diff line number Diff line change
@@ -1,5 +1,13 @@
extend = "../../.ruff.toml" # Inherit the project-wide settings

[per-file-target-version]
"deepfreeze.py" = "py310"
"stable_abi.py" = "py311" # requires 'tomllib'

[format]
preview = true
docstring-code-format = true

[lint]
select = [
"C4", # flake8-comprehensions
Expand All @@ -24,10 +32,6 @@ ignore = [
"UP038", # Use `X | Y` in `isinstance` call instead of `(X, Y)`
]

[per-file-target-version]
"deepfreeze.py" = "py310"
"stable_abi.py" = "py311" # requires 'tomllib'
Comment on lines -27 to -29
Copy link
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Moved to the top of the file as currently this is in-between the lint table and a lint subtable


[lint.per-file-ignores]
"{check_extension_modules,freeze_modules}.py" = [
"UP031", # Use format specifiers instead of percent format
Expand Down
31 changes: 12 additions & 19 deletions Tools/build/check_warnings.py
Original file line number Diff line number Diff line change
Expand Up @@ -83,17 +83,13 @@ def extract_warnings_from_compiler_output(
for i, line in enumerate(compiler_output.splitlines(), start=1):
if match := compiled_regex.match(line):
try:
compiler_warnings.append(
{
"file": match.group("file").removeprefix(path_prefix),
"line": match.group("line"),
"column": match.group("column"),
"message": match.group("message"),
"option": match.group("option")
.lstrip("[")
.rstrip("]"),
}
)
compiler_warnings.append({
"file": match.group("file").removeprefix(path_prefix),
"line": match.group("line"),
"column": match.group("column"),
"message": match.group("message"),
"option": match.group("option").lstrip("[").rstrip("]"),
})
except AttributeError:
print(
f"Error parsing compiler output. "
Expand Down Expand Up @@ -151,7 +147,6 @@ def get_unexpected_warnings(
"""
unexpected_warnings = {}
for file in files_with_warnings.keys():

rule = is_file_ignored(file, ignore_rules)

if rule:
Expand Down Expand Up @@ -201,13 +196,11 @@ def get_unexpected_improvements(
if rule.file_path not in files_with_warnings.keys():
unexpected_improvements.append((rule.file_path, rule.count, 0))
elif len(files_with_warnings[rule.file_path]) < rule.count:
unexpected_improvements.append(
(
rule.file_path,
rule.count,
len(files_with_warnings[rule.file_path]),
)
)
unexpected_improvements.append((
rule.file_path,
rule.count,
len(files_with_warnings[rule.file_path]),
))

if unexpected_improvements:
print("Unexpected improvements:")
Expand Down
Loading