From 4cd48034a821d6e077f510abd536614601b86300 Mon Sep 17 00:00:00 2001 From: Hugo van Kemenade Date: Tue, 27 Jun 2023 16:17:32 +0300 Subject: [PATCH 01/16] Check for redefined names in CI --- .pre-commit-config.yaml | 7 +++++++ .ruff.toml | 20 ++++++++++++++++++++ 2 files changed, 27 insertions(+) create mode 100644 .ruff.toml diff --git a/.pre-commit-config.yaml b/.pre-commit-config.yaml index 451cbe8bc84820..1d83c9414d1081 100644 --- a/.pre-commit-config.yaml +++ b/.pre-commit-config.yaml @@ -1,4 +1,11 @@ repos: + - repo: https://github.com/astral-sh/ruff-pre-commit + rev: v0.0.287 + hooks: + - id: ruff + args: [--fix, --exit-non-zero-on-fix] + files: ^Lib/test/ + - repo: https://github.com/pre-commit/pre-commit-hooks rev: v4.4.0 hooks: diff --git a/.ruff.toml b/.ruff.toml new file mode 100644 index 00000000000000..82b407dbe275e6 --- /dev/null +++ b/.ruff.toml @@ -0,0 +1,20 @@ +select = [ + "F811", +] +extend-exclude = [ + # Failed to lint + "Lib/test/badsyntax_pep3120.py", + "Lib/test/encoded_modules/module_iso_8859_1.py", + "Lib/test/encoded_modules/module_koi8_r.py", + # Failed to parse + "Lib/test/mod_generics_cache.py", + "Lib/test/badsyntax_3131.py", + "Lib/test/support/socket_helper.py", + "Lib/test/test_builtin.py", + "Lib/test/test_fstring.py", + "Lib/test/test_funcattrs.py", + "Lib/test/test_functools.py", + "Lib/test/test_type_aliases.py", + "Lib/test/test_type_params.py", + "Lib/test/test_typing.py", +] From a37828c3fe17852c597df913f7c0dff29b12f136 Mon Sep 17 00:00:00 2001 From: Hugo van Kemenade Date: Fri, 8 Sep 2023 13:28:49 +0300 Subject: [PATCH 02/16] Temporarily exclude files with: F811 Redefinition of unused name --- .ruff.toml | 17 +++++++++++++++++ 1 file changed, 17 insertions(+) diff --git a/.ruff.toml b/.ruff.toml index 82b407dbe275e6..bd1b14614958ff 100644 --- a/.ruff.toml +++ b/.ruff.toml @@ -17,4 +17,21 @@ extend-exclude = [ "Lib/test/test_type_aliases.py", "Lib/test/test_type_params.py", "Lib/test/test_typing.py", + # TODO Fix: F811 Redefinition of unused name + "Lib/test/test__opcode.py", + "Lib/test/test_buffer.py", + "Lib/test/test_ctypes/test_arrays.py", + "Lib/test/test_ctypes/test_functions.py", + "Lib/test/test_dataclasses/__init__.py", + "Lib/test/test_descr.py", + "Lib/test/test_enum.py", + "Lib/test/test_genericclass.py", + "Lib/test/test_grammar.py", + "Lib/test/test_import/__init__.py", + "Lib/test/test_keywordonlyarg.py", + "Lib/test/test_pkg.py", + "Lib/test/test_subclassinit.py", + "Lib/test/test_unittest/testmock/testpatch.py", + "Lib/test/test_yield_from.py", + "Lib/test/time_hashlib.py", ] From 0dcdd08c5ff076ecec45c5b4b8dbba931f8ca81a Mon Sep 17 00:00:00 2001 From: Hugo van Kemenade Date: Sat, 9 Sep 2023 11:55:05 +0300 Subject: [PATCH 03/16] Move Ruff config file to relevant subdirectory to localise rules --- .ruff.toml | 37 ------------------------------------- Lib/test/.ruff.toml | 37 +++++++++++++++++++++++++++++++++++++ 2 files changed, 37 insertions(+), 37 deletions(-) delete mode 100644 .ruff.toml create mode 100644 Lib/test/.ruff.toml diff --git a/.ruff.toml b/.ruff.toml deleted file mode 100644 index bd1b14614958ff..00000000000000 --- a/.ruff.toml +++ /dev/null @@ -1,37 +0,0 @@ -select = [ - "F811", -] -extend-exclude = [ - # Failed to lint - "Lib/test/badsyntax_pep3120.py", - "Lib/test/encoded_modules/module_iso_8859_1.py", - "Lib/test/encoded_modules/module_koi8_r.py", - # Failed to parse - "Lib/test/mod_generics_cache.py", - "Lib/test/badsyntax_3131.py", - "Lib/test/support/socket_helper.py", - "Lib/test/test_builtin.py", - "Lib/test/test_fstring.py", - "Lib/test/test_funcattrs.py", - "Lib/test/test_functools.py", - "Lib/test/test_type_aliases.py", - "Lib/test/test_type_params.py", - "Lib/test/test_typing.py", - # TODO Fix: F811 Redefinition of unused name - "Lib/test/test__opcode.py", - "Lib/test/test_buffer.py", - "Lib/test/test_ctypes/test_arrays.py", - "Lib/test/test_ctypes/test_functions.py", - "Lib/test/test_dataclasses/__init__.py", - "Lib/test/test_descr.py", - "Lib/test/test_enum.py", - "Lib/test/test_genericclass.py", - "Lib/test/test_grammar.py", - "Lib/test/test_import/__init__.py", - "Lib/test/test_keywordonlyarg.py", - "Lib/test/test_pkg.py", - "Lib/test/test_subclassinit.py", - "Lib/test/test_unittest/testmock/testpatch.py", - "Lib/test/test_yield_from.py", - "Lib/test/time_hashlib.py", -] diff --git a/Lib/test/.ruff.toml b/Lib/test/.ruff.toml new file mode 100644 index 00000000000000..1a381d84de6239 --- /dev/null +++ b/Lib/test/.ruff.toml @@ -0,0 +1,37 @@ +select = [ + "F811", +] +extend-exclude = [ + # Failed to lint + "badsyntax_pep3120.py", + "encoded_modules/module_iso_8859_1.py", + "encoded_modules/module_koi8_r.py", + # Failed to parse + "mod_generics_cache.py", + "badsyntax_3131.py", + "support/socket_helper.py", + "test_builtin.py", + "test_fstring.py", + "test_funcattrs.py", + "test_functools.py", + "test_type_aliases.py", + "test_type_params.py", + "test_typing.py", + # TODO Fix: F811 Redefinition of unused name + "test__opcode.py", + "test_buffer.py", + "test_ctypes/test_arrays.py", + "test_ctypes/test_functions.py", + "test_dataclasses/__init__.py", + "test_descr.py", + "test_enum.py", + "test_genericclass.py", + "test_grammar.py", + "test_import/__init__.py", + "test_keywordonlyarg.py", + "test_pkg.py", + "test_subclassinit.py", + "test_unittest/testmock/testpatch.py", + "test_yield_from.py", + "time_hashlib.py", +] From d14c002cd216945e4d2b36cd332edfdb8f914501 Mon Sep 17 00:00:00 2001 From: Hugo van Kemenade Date: Sat, 9 Sep 2023 06:22:14 -0600 Subject: [PATCH 04/16] Comment the rule Co-authored-by: Alex Waygood --- Lib/test/.ruff.toml | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/Lib/test/.ruff.toml b/Lib/test/.ruff.toml index 1a381d84de6239..fc5933c4561bfc 100644 --- a/Lib/test/.ruff.toml +++ b/Lib/test/.ruff.toml @@ -1,5 +1,5 @@ select = [ - "F811", + "F811", # Redefinition of unused variable (useful for finding test methods with the same name) ] extend-exclude = [ # Failed to lint From cb8237cc40e82df1fb832caf6aaef66752c46b3c Mon Sep 17 00:00:00 2001 From: Hugo van Kemenade Date: Sat, 9 Sep 2023 15:27:18 +0300 Subject: [PATCH 05/16] Move autofix setting from pre-commit to Ruff config --- .pre-commit-config.yaml | 2 +- Lib/test/.ruff.toml | 1 + 2 files changed, 2 insertions(+), 1 deletion(-) diff --git a/.pre-commit-config.yaml b/.pre-commit-config.yaml index 1d83c9414d1081..3cc332ab34d4a2 100644 --- a/.pre-commit-config.yaml +++ b/.pre-commit-config.yaml @@ -3,7 +3,7 @@ repos: rev: v0.0.287 hooks: - id: ruff - args: [--fix, --exit-non-zero-on-fix] + args: [--exit-non-zero-on-fix] files: ^Lib/test/ - repo: https://github.com/pre-commit/pre-commit-hooks diff --git a/Lib/test/.ruff.toml b/Lib/test/.ruff.toml index fc5933c4561bfc..72dd6deb5b11ce 100644 --- a/Lib/test/.ruff.toml +++ b/Lib/test/.ruff.toml @@ -1,3 +1,4 @@ +fix = true select = [ "F811", # Redefinition of unused variable (useful for finding test methods with the same name) ] From 1bdae72a698a274c836821626e5952f77c518b39 Mon Sep 17 00:00:00 2001 From: Hugo van Kemenade Date: Sun, 10 Sep 2023 13:53:34 +0300 Subject: [PATCH 06/16] Show diff and add annotations --- .pre-commit-config.yaml | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/.pre-commit-config.yaml b/.pre-commit-config.yaml index 3cc332ab34d4a2..1c5c31552da236 100644 --- a/.pre-commit-config.yaml +++ b/.pre-commit-config.yaml @@ -3,7 +3,7 @@ repos: rev: v0.0.287 hooks: - id: ruff - args: [--exit-non-zero-on-fix] + args: [--exit-non-zero-on-fix, --diff, --format=github] files: ^Lib/test/ - repo: https://github.com/pre-commit/pre-commit-hooks From 83904af6f2dbdfddf6c63fd9d55cf8e95d689dd8 Mon Sep 17 00:00:00 2001 From: Hugo van Kemenade Date: Sun, 10 Sep 2023 13:57:35 +0300 Subject: [PATCH 07/16] Re-order args --- .pre-commit-config.yaml | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/.pre-commit-config.yaml b/.pre-commit-config.yaml index 1c5c31552da236..9743069ad5f97c 100644 --- a/.pre-commit-config.yaml +++ b/.pre-commit-config.yaml @@ -3,7 +3,7 @@ repos: rev: v0.0.287 hooks: - id: ruff - args: [--exit-non-zero-on-fix, --diff, --format=github] + args: [--diff, --exit-non-zero-on-fix, --format=github] files: ^Lib/test/ - repo: https://github.com/pre-commit/pre-commit-hooks From 8fd293ad835eeaea0763876f687931333dd4939d Mon Sep 17 00:00:00 2001 From: Hugo van Kemenade Date: Sun, 10 Sep 2023 14:03:31 +0300 Subject: [PATCH 08/16] Remove --diff --- .pre-commit-config.yaml | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/.pre-commit-config.yaml b/.pre-commit-config.yaml index 9743069ad5f97c..90f92c5edbbba6 100644 --- a/.pre-commit-config.yaml +++ b/.pre-commit-config.yaml @@ -3,7 +3,7 @@ repos: rev: v0.0.287 hooks: - id: ruff - args: [--diff, --exit-non-zero-on-fix, --format=github] + args: [--exit-non-zero-on-fix, --format=github] files: ^Lib/test/ - repo: https://github.com/pre-commit/pre-commit-hooks From 66e11726be99f46c815084579e019df1a518b4ee Mon Sep 17 00:00:00 2001 From: Hugo van Kemenade Date: Sun, 10 Sep 2023 14:56:54 +0300 Subject: [PATCH 09/16] Update config --- .github/CODEOWNERS | 1 + .github/workflows/build.yml | 2 +- .github/workflows/lint.yml | 3 +++ .pre-commit-config.yaml | 3 ++- 4 files changed, 7 insertions(+), 2 deletions(-) diff --git a/.github/CODEOWNERS b/.github/CODEOWNERS index 81c580eb778625..cd35cba5b5c56d 100644 --- a/.github/CODEOWNERS +++ b/.github/CODEOWNERS @@ -9,6 +9,7 @@ # pre-commit .pre-commit-config.yaml @hugovk @AlexWaygood +.ruff.toml @hugovk @AlexWaygood # Build system configure* @erlend-aasland @corona10 diff --git a/.github/workflows/build.yml b/.github/workflows/build.yml index 668ae499f06f17..cbe5c841a433cf 100644 --- a/.github/workflows/build.yml +++ b/.github/workflows/build.yml @@ -63,7 +63,7 @@ jobs: # into the PR branch anyway. # # https://github.com/python/core-workflow/issues/373 - git diff --name-only origin/$GITHUB_BASE_REF.. | grep -qvE '(\.rst$|^Doc|^Misc)' && echo "run_tests=true" >> $GITHUB_OUTPUT || true + git diff --name-only origin/$GITHUB_BASE_REF.. | grep -qvE '(\.rst$|^Doc|^Misc|^\.pre-commit-config\.yaml$|\.ruff\.toml$)' && echo "run_tests=true" >> $GITHUB_OUTPUT || true fi # Check if we should run hypothesis tests diff --git a/.github/workflows/lint.yml b/.github/workflows/lint.yml index 27b04ba1d412e3..cd9657284bdce2 100644 --- a/.github/workflows/lint.yml +++ b/.github/workflows/lint.yml @@ -5,6 +5,9 @@ on: [push, pull_request, workflow_dispatch] permissions: contents: read +env: + RUFF_FORMAT: github + concurrency: group: ${{ github.workflow }}-${{ github.head_ref || github.run_id }} cancel-in-progress: true diff --git a/.pre-commit-config.yaml b/.pre-commit-config.yaml index 90f92c5edbbba6..5476b80ed119d5 100644 --- a/.pre-commit-config.yaml +++ b/.pre-commit-config.yaml @@ -3,12 +3,13 @@ repos: rev: v0.0.287 hooks: - id: ruff - args: [--exit-non-zero-on-fix, --format=github] + args: [--exit-non-zero-on-fix] files: ^Lib/test/ - repo: https://github.com/pre-commit/pre-commit-hooks rev: v4.4.0 hooks: + - id: check-toml - id: check-yaml - id: end-of-file-fixer types: [python] From 9b1b43a66ca64592b2e7b91501f5a1d8369dff4a Mon Sep 17 00:00:00 2001 From: Hugo van Kemenade Date: Sun, 10 Sep 2023 15:00:46 +0300 Subject: [PATCH 10/16] Don't validate intentionally invalid TOML --- .pre-commit-config.yaml | 1 + 1 file changed, 1 insertion(+) diff --git a/.pre-commit-config.yaml b/.pre-commit-config.yaml index 5476b80ed119d5..172d95afa572e4 100644 --- a/.pre-commit-config.yaml +++ b/.pre-commit-config.yaml @@ -10,6 +10,7 @@ repos: rev: v4.4.0 hooks: - id: check-toml + exclude: ^Lib/test/test_tomllib/data/invalid/ - id: check-yaml - id: end-of-file-fixer types: [python] From 3839aea0491e39f31eb247b2639e1e8da7393ad4 Mon Sep 17 00:00:00 2001 From: Hugo van Kemenade Date: Sun, 10 Sep 2023 15:06:18 +0300 Subject: [PATCH 11/16] Let tomllib look after its own test files --- .pre-commit-config.yaml | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/.pre-commit-config.yaml b/.pre-commit-config.yaml index 172d95afa572e4..4eed61956a4c4b 100644 --- a/.pre-commit-config.yaml +++ b/.pre-commit-config.yaml @@ -10,7 +10,7 @@ repos: rev: v4.4.0 hooks: - id: check-toml - exclude: ^Lib/test/test_tomllib/data/invalid/ + exclude: ^Lib/test/test_tomllib/ - id: check-yaml - id: end-of-file-fixer types: [python] From 0bf3e3ead4f7051cb80f4705daba2fe805b59c05 Mon Sep 17 00:00:00 2001 From: Hugo van Kemenade Date: Sun, 10 Sep 2023 06:27:58 -0600 Subject: [PATCH 12/16] Clarify job scope Co-authored-by: Alex Waygood --- .pre-commit-config.yaml | 1 + 1 file changed, 1 insertion(+) diff --git a/.pre-commit-config.yaml b/.pre-commit-config.yaml index 4eed61956a4c4b..27543f6ca3cc64 100644 --- a/.pre-commit-config.yaml +++ b/.pre-commit-config.yaml @@ -3,6 +3,7 @@ repos: rev: v0.0.287 hooks: - id: ruff + name: Run Ruff on Lib/test/ args: [--exit-non-zero-on-fix] files: ^Lib/test/ From 932f2c1198459d77d71971bb1eb3b916b04c455c Mon Sep 17 00:00:00 2001 From: Hugo van Kemenade Date: Mon, 11 Sep 2023 11:47:29 +0300 Subject: [PATCH 13/16] Add colour to test logs for readability Co-authored-by: Adam Turner <9087854+AA-Turner@users.noreply.github.com> --- .github/workflows/lint.yml | 1 + 1 file changed, 1 insertion(+) diff --git a/.github/workflows/lint.yml b/.github/workflows/lint.yml index cd9657284bdce2..89f65816b6969d 100644 --- a/.github/workflows/lint.yml +++ b/.github/workflows/lint.yml @@ -6,6 +6,7 @@ permissions: contents: read env: + FORCE_COLOR: 1 RUFF_FORMAT: github concurrency: From 0889959a6ac7cb47c3712e5841626e7a45506597 Mon Sep 17 00:00:00 2001 From: Hugo van Kemenade Date: Tue, 12 Sep 2023 10:53:37 +0300 Subject: [PATCH 14/16] Bump Ruff --- .pre-commit-config.yaml | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/.pre-commit-config.yaml b/.pre-commit-config.yaml index 27543f6ca3cc64..19f6a03745d2d0 100644 --- a/.pre-commit-config.yaml +++ b/.pre-commit-config.yaml @@ -1,6 +1,6 @@ repos: - repo: https://github.com/astral-sh/ruff-pre-commit - rev: v0.0.287 + rev: v0.0.288 hooks: - id: ruff name: Run Ruff on Lib/test/ From 6ba396d1200a771e178ac408398bf0aba8e80b03 Mon Sep 17 00:00:00 2001 From: Hugo van Kemenade Date: Tue, 12 Sep 2023 10:56:49 +0300 Subject: [PATCH 15/16] Remove some exclusions which now parse --- Lib/test/.ruff.toml | 9 ++------- 1 file changed, 2 insertions(+), 7 deletions(-) diff --git a/Lib/test/.ruff.toml b/Lib/test/.ruff.toml index 72dd6deb5b11ce..5a847a008b2df6 100644 --- a/Lib/test/.ruff.toml +++ b/Lib/test/.ruff.toml @@ -8,16 +8,9 @@ extend-exclude = [ "encoded_modules/module_iso_8859_1.py", "encoded_modules/module_koi8_r.py", # Failed to parse - "mod_generics_cache.py", "badsyntax_3131.py", "support/socket_helper.py", - "test_builtin.py", "test_fstring.py", - "test_funcattrs.py", - "test_functools.py", - "test_type_aliases.py", - "test_type_params.py", - "test_typing.py", # TODO Fix: F811 Redefinition of unused name "test__opcode.py", "test_buffer.py", @@ -26,12 +19,14 @@ extend-exclude = [ "test_dataclasses/__init__.py", "test_descr.py", "test_enum.py", + "test_functools.py", "test_genericclass.py", "test_grammar.py", "test_import/__init__.py", "test_keywordonlyarg.py", "test_pkg.py", "test_subclassinit.py", + "test_typing.py", "test_unittest/testmock/testpatch.py", "test_yield_from.py", "time_hashlib.py", From d9dff8dd2cba2b15d9f61d12209ad18b9fd810d0 Mon Sep 17 00:00:00 2001 From: Hugo van Kemenade Date: Tue, 12 Sep 2023 16:43:18 +0300 Subject: [PATCH 16/16] Temporarily exclude test_monitoring.py pending fix --- Lib/test/.ruff.toml | 2 ++ 1 file changed, 2 insertions(+) diff --git a/Lib/test/.ruff.toml b/Lib/test/.ruff.toml index 5a847a008b2df6..a9a4a013dabec9 100644 --- a/Lib/test/.ruff.toml +++ b/Lib/test/.ruff.toml @@ -30,4 +30,6 @@ extend-exclude = [ "test_unittest/testmock/testpatch.py", "test_yield_from.py", "time_hashlib.py", + # Pending https://github.com/python/cpython/pull/109139 + "test_monitoring.py", ]