]> git.ipfire.org Git - thirdparty/Python/cpython.git/commitdiff
Lint: Use Ruff to format ``Tools/build/check_warnings.py`` (#133317)
authorAdam Turner <9087854+AA-Turner@users.noreply.github.com>
Fri, 2 May 2025 20:26:32 +0000 (21:26 +0100)
committerGitHub <noreply@github.com>
Fri, 2 May 2025 20:26:32 +0000 (21:26 +0100)
.pre-commit-config.yaml
Tools/build/.ruff.toml
Tools/build/check_warnings.py

index 048cff1d32c7af15e5d420f7912ac623f25a5628..7ad829c94d50f37e22248bf5d2b1fe012700fd04 100644 (file)
@@ -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/
@@ -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/
index c084c06144adaf050f45f83f3c3c557f0bd1c97a..fa7689d45dbcb7d7989ea8bc00407bd79abd8d1f 100644 (file)
@@ -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
@@ -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'
-
 [lint.per-file-ignores]
 "{check_extension_modules,freeze_modules}.py" = [
     "UP031",  # Use format specifiers instead of percent format
index 7a8721087b6c66ff0d87f2baa6f3e7402ba98e5a..3f49d8e7f2ee4842ff83405523c709a99e867277 100644 (file)
@@ -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. "
@@ -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:
@@ -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:")