summaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
-rw-r--r--.pre-commit-config.yaml9
-rw-r--r--Tools/build/.ruff.toml20
-rw-r--r--Tools/build/check_warnings.py20
3 files changed, 42 insertions, 7 deletions
diff --git a/.pre-commit-config.yaml b/.pre-commit-config.yaml
index 4cdb754..891934b 100644
--- a/.pre-commit-config.yaml
+++ b/.pre-commit-config.yaml
@@ -11,6 +11,10 @@ repos:
args: [--exit-non-zero-on-fix]
files: ^Lib/test/
- id: ruff
+ name: Run Ruff (lint) on Tools/build/check_warnings.py
+ args: [--exit-non-zero-on-fix, --config=Tools/build/.ruff.toml]
+ files: ^Tools/build/check_warnings.py
+ - id: ruff
name: Run Ruff (lint) on Argument Clinic
args: [--exit-non-zero-on-fix, --config=Tools/clinic/.ruff.toml]
files: ^Tools/clinic/|Lib/test/test_clinic.py
@@ -23,6 +27,11 @@ repos:
rev: 24.8.0
hooks:
- id: black
+ name: Run Black on Tools/build/check_warnings.py
+ files: ^Tools/build/check_warnings.py
+ language_version: python3.12
+ args: [--line-length=79]
+ - id: black
name: Run Black on Tools/jit/
files: ^Tools/jit/
language_version: python3.12
diff --git a/Tools/build/.ruff.toml b/Tools/build/.ruff.toml
new file mode 100644
index 0000000..53bfe18
--- /dev/null
+++ b/Tools/build/.ruff.toml
@@ -0,0 +1,20 @@
+target-version = "py310"
+fix = true
+line-length = 79
+
+[lint]
+select = [
+ "C4", # flake8-comprehensions
+ "E", # pycodestyle
+ "F", # pyflakes
+ "I", # isort
+ "ISC", # flake8-implicit-str-concat
+ "LOG", # flake8-logging
+ "PGH", # pygrep-hooks
+ "PT", # flake8-pytest-style
+ "PYI", # flake8-pyi
+ "RUF100", # Ban unused `# noqa` comments
+ "UP", # pyupgrade
+ "W", # pycodestyle
+ "YTT", # flake8-2020
+]
diff --git a/Tools/build/check_warnings.py b/Tools/build/check_warnings.py
index 7210cc8..7a87210 100644
--- a/Tools/build/check_warnings.py
+++ b/Tools/build/check_warnings.py
@@ -4,9 +4,9 @@ exist only in files that are expected to have warnings.
"""
import argparse
-from collections import defaultdict
import re
import sys
+from collections import defaultdict
from pathlib import Path
from typing import NamedTuple
@@ -38,7 +38,8 @@ def parse_warning_ignore_file(file_path: str) -> set[IgnoreRule]:
# Directories must have a wildcard count
if is_directory and count != "*":
print(
- f"Error parsing ignore file: {file_path} at line: {i}"
+ f"Error parsing ignore file: {file_path} "
+ f"at line: {i}"
)
print(
f"Directory {file_name} must have count set to *"
@@ -93,9 +94,10 @@ def extract_warnings_from_compiler_output(
.rstrip("]"),
}
)
- except:
+ except AttributeError:
print(
- f"Error parsing compiler output. Unable to extract warning on line {i}:\n{line}"
+ f"Error parsing compiler output. "
+ f"Unable to extract warning on line {i}:\n{line}"
)
sys.exit(1)
@@ -125,8 +127,9 @@ def get_warnings_by_file(warnings: list[dict]) -> dict[str, list[dict]]:
def is_file_ignored(
file_path: str, ignore_rules: set[IgnoreRule]
) -> IgnoreRule | None:
- """
- Returns the IgnoreRule object for the file path if there is a related rule for it
+ """Return the IgnoreRule object for the file path.
+
+ Return ``None`` if there is no related rule for that path.
"""
for rule in ignore_rules:
if rule.is_directory:
@@ -191,7 +194,10 @@ def get_unexpected_improvements(
"""
unexpected_improvements = []
for rule in ignore_rules:
- if not rule.ignore_all and rule.file_path not in files_with_warnings.keys():
+ if (
+ not rule.ignore_all
+ and rule.file_path not in files_with_warnings.keys()
+ ):
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: