From 9be99d31d60b9be02925d840a352259edfabd413 Mon Sep 17 00:00:00 2001 From: Adam Turner <9087854+AA-Turner@users.noreply.github.com> Date: Thu, 1 May 2025 09:28:44 +0100 Subject: [PATCH 1/2] Lint: Create a project-wide ``.ruff.toml`` settings file (#133124) Co-authored-by: Alex Waygood (cherry picked from commit fe3c7e10d95235e3d7bea9273d61a968cdc83d86) --- .ruff.toml | 12 ++++++++++++ Doc/.ruff.toml | 5 ++--- Lib/test/.ruff.toml | 4 +++- Tools/build/.ruff.toml | 1 + Tools/clinic/.ruff.toml | 3 +-- 5 files changed, 19 insertions(+), 6 deletions(-) create mode 100644 .ruff.toml create mode 100644 Tools/build/.ruff.toml diff --git a/.ruff.toml b/.ruff.toml new file mode 100644 index 00000000000000..1c015fa88415bc --- /dev/null +++ b/.ruff.toml @@ -0,0 +1,12 @@ +# Default settings for Ruff in CPython + +# PYTHON_FOR_REGEN +target-version = "py310" + +# PEP 8 +line-length = 79 + +# Enable automatic fixes by default. +# To override this, use ``fix = false`` in a subdirectory's config file +# or ``--no-fix`` on the command line. +fix = true diff --git a/Doc/.ruff.toml b/Doc/.ruff.toml index 111ce03b91df38..3e676e13c3f41a 100644 --- a/Doc/.ruff.toml +++ b/Doc/.ruff.toml @@ -1,7 +1,6 @@ +extend = "../.ruff.toml" # Inherit the project-wide settings + target-version = "py312" # Align with the version in oldest_supported_sphinx -fix = true -output-format = "full" -line-length = 79 extend-exclude = [ "includes/*", # Temporary exclusions: diff --git a/Lib/test/.ruff.toml b/Lib/test/.ruff.toml index 218eefe5255706..f800dc03dce62f 100644 --- a/Lib/test/.ruff.toml +++ b/Lib/test/.ruff.toml @@ -1,5 +1,7 @@ -fix = true +extend = "../../.ruff.toml" # Inherit the project-wide settings + target-version = "py312" + extend-exclude = [ # Excluded (run with the other AC files in its own separate ruff job in pre-commit) "test_clinic.py", diff --git a/Tools/build/.ruff.toml b/Tools/build/.ruff.toml new file mode 100644 index 00000000000000..72324a09daf3b8 --- /dev/null +++ b/Tools/build/.ruff.toml @@ -0,0 +1 @@ +extend = "../../.ruff.toml" # Inherit the project-wide settings diff --git a/Tools/clinic/.ruff.toml b/Tools/clinic/.ruff.toml index c019572d0cb186..5033887df0c1cd 100644 --- a/Tools/clinic/.ruff.toml +++ b/Tools/clinic/.ruff.toml @@ -1,5 +1,4 @@ -target-version = "py310" -fix = true +extend = "../../.ruff.toml" # Inherit the project-wide settings [lint] select = [ From cc0bbffc44dd76b1ab819143a34e18024cb00d1f Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?=F0=9F=87=BA=F0=9F=87=A6=20Sviatoslav=20Sydorenko=20=28?= =?UTF-8?q?=D0=A1=D0=B2=D1=8F=D1=82=D0=BE=D1=81=D0=BB=D0=B0=D0=B2=20=D0=A1?= =?UTF-8?q?=D0=B8=D0=B4=D0=BE=D1=80=D0=B5=D0=BD=D0=BA=D0=BE=29?= Date: Fri, 15 Aug 2025 19:53:25 +0200 Subject: [PATCH 2/2] Set up additional linting for build scripts Co-authored-by: Hugo van Kemenade <1324225+hugovk@users.noreply.github.com> --- Tools/build/.ruff.toml | 40 ++++++++++++++++++++++++++++++++++++++++ 1 file changed, 40 insertions(+) diff --git a/Tools/build/.ruff.toml b/Tools/build/.ruff.toml index 72324a09daf3b8..dcbf2936290f12 100644 --- a/Tools/build/.ruff.toml +++ b/Tools/build/.ruff.toml @@ -1 +1,41 @@ extend = "../../.ruff.toml" # Inherit the project-wide settings + +[per-file-target-version] +"deepfreeze.py" = "py311" # requires `code.co_exceptiontable` +"stable_abi.py" = "py311" # requires 'tomllib' + +[format] +preview = true +docstring-code-format = true + +[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 +] +ignore = [ + "E501", # Line too long + "F541", # f-string without any placeholders + "PYI024", # Use `typing.NamedTuple` instead of `collections.namedtuple` + "PYI025", # Use `from collections.abc import Set as AbstractSet` + "UP038", # Use `X | Y` in `isinstance` call instead of `(X, Y)` +] + +[lint.per-file-ignores] +"{check_extension_modules,freeze_modules}.py" = [ + "UP031", # Use format specifiers instead of percent format +] +"generate_{re_casefix,sre_constants,token}.py" = [ + "UP031", # Use format specifiers instead of percent format +]