From 27d63e613b5ed598fb59eff72f2cd60944babc8c Mon Sep 17 00:00:00 2001 From: Hugo van Kemenade Date: Tue, 12 Sep 2023 09:28:20 -0600 Subject: [PATCH 1/3] gh-60283: Check for redefined test names in CI (#109161) Co-authored-by: Alex Waygood Co-authored-by: Adam Turner <9087854+AA-Turner@users.noreply.github.com> (cherry picked from commit 3cb9a8edca6e3fa0f0045b03a9a6444cf8f7affe) --- .github/CODEOWNERS | 1 + .github/workflows/build.yml | 2 +- .github/workflows/lint.yml | 4 ++++ .pre-commit-config.yaml | 10 ++++++++++ Lib/test/.ruff.toml | 35 +++++++++++++++++++++++++++++++++++ 5 files changed, 51 insertions(+), 1 deletion(-) create mode 100644 Lib/test/.ruff.toml diff --git a/.github/CODEOWNERS b/.github/CODEOWNERS index 99d701daa1d49a..1b156c829cd9aa 100644 --- a/.github/CODEOWNERS +++ b/.github/CODEOWNERS @@ -9,6 +9,7 @@ # pre-commit .pre-commit-config.yaml @hugovk @AlexWaygood +.ruff.toml @hugovk @AlexWaygood # asyncio **/*asyncio* @1st1 @asvetlov diff --git a/.github/workflows/build.yml b/.github/workflows/build.yml index 30d2a973a31d3d..4baa65cf948d2d 100644 --- a/.github/workflows/build.yml +++ b/.github/workflows/build.yml @@ -62,7 +62,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 git diff --name-only origin/$GITHUB_BASE_REF.. | grep -qE '(ssl|hashlib|hmac|^.github)' && echo "run_ssl_tests=true" >> $GITHUB_OUTPUT || true fi - name: Compute hash for config cache key diff --git a/.github/workflows/lint.yml b/.github/workflows/lint.yml index 27b04ba1d412e3..89f65816b6969d 100644 --- a/.github/workflows/lint.yml +++ b/.github/workflows/lint.yml @@ -5,6 +5,10 @@ on: [push, pull_request, workflow_dispatch] permissions: contents: read +env: + FORCE_COLOR: 1 + 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 889bd8502a10ea..980b616559ff32 100644 --- a/.pre-commit-config.yaml +++ b/.pre-commit-config.yaml @@ -1,7 +1,17 @@ repos: + - repo: https://github.com/astral-sh/ruff-pre-commit + rev: v0.0.288 + hooks: + - id: ruff + name: Run Ruff on Lib/test/ + 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 + exclude: ^Lib/test/test_tomllib/ - id: check-yaml - id: trailing-whitespace types_or: [c, python, rst] diff --git a/Lib/test/.ruff.toml b/Lib/test/.ruff.toml new file mode 100644 index 00000000000000..a9a4a013dabec9 --- /dev/null +++ b/Lib/test/.ruff.toml @@ -0,0 +1,35 @@ +fix = true +select = [ + "F811", # Redefinition of unused variable (useful for finding test methods with the same name) +] +extend-exclude = [ + # Failed to lint + "badsyntax_pep3120.py", + "encoded_modules/module_iso_8859_1.py", + "encoded_modules/module_koi8_r.py", + # Failed to parse + "badsyntax_3131.py", + "support/socket_helper.py", + "test_fstring.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_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", + # Pending https://github.com/python/cpython/pull/109139 + "test_monitoring.py", +] From 6bbcdfc596341fd61e4bb3b7aab6087201a12e2e Mon Sep 17 00:00:00 2001 From: Hugo van Kemenade Date: Wed, 13 Sep 2023 08:55:14 +0300 Subject: [PATCH 2/3] Update exclude list for 3.11 --- Lib/test/.ruff.toml | 19 +++---------------- 1 file changed, 3 insertions(+), 16 deletions(-) diff --git a/Lib/test/.ruff.toml b/Lib/test/.ruff.toml index a9a4a013dabec9..94ac21628628e3 100644 --- a/Lib/test/.ruff.toml +++ b/Lib/test/.ruff.toml @@ -3,20 +3,9 @@ select = [ "F811", # Redefinition of unused variable (useful for finding test methods with the same name) ] extend-exclude = [ - # Failed to lint - "badsyntax_pep3120.py", - "encoded_modules/module_iso_8859_1.py", - "encoded_modules/module_koi8_r.py", - # Failed to parse - "badsyntax_3131.py", - "support/socket_helper.py", - "test_fstring.py", - # TODO Fix: F811 Redefinition of unused name - "test__opcode.py", +# # TODO Fix: F811 Redefinition of unused name "test_buffer.py", - "test_ctypes/test_arrays.py", - "test_ctypes/test_functions.py", - "test_dataclasses/__init__.py", + "test_dataclasses.py", "test_descr.py", "test_enum.py", "test_functools.py", @@ -26,10 +15,8 @@ extend-exclude = [ "test_keywordonlyarg.py", "test_pkg.py", "test_subclassinit.py", + "test_tokenize.py", "test_typing.py", - "test_unittest/testmock/testpatch.py", "test_yield_from.py", "time_hashlib.py", - # Pending https://github.com/python/cpython/pull/109139 - "test_monitoring.py", ] From 9ee16cc53d3a152bf28732f5b8ae2686d8b10e9a Mon Sep 17 00:00:00 2001 From: Hugo van Kemenade Date: Wed, 13 Sep 2023 11:47:56 +0300 Subject: [PATCH 3/3] Explicitly exclude files which failed to lint/parse --- Lib/test/.ruff.toml | 10 +++++++++- 1 file changed, 9 insertions(+), 1 deletion(-) diff --git a/Lib/test/.ruff.toml b/Lib/test/.ruff.toml index 94ac21628628e3..24f3f8c65dcf5f 100644 --- a/Lib/test/.ruff.toml +++ b/Lib/test/.ruff.toml @@ -3,7 +3,15 @@ select = [ "F811", # Redefinition of unused variable (useful for finding test methods with the same name) ] extend-exclude = [ -# # TODO Fix: F811 Redefinition of unused name + # Failed to lint + "badsyntax_pep3120.py", + "encoded_modules/module_iso_8859_1.py", + "encoded_modules/module_koi8_r.py", + "test_source_encoding.py", + # Failed to parse + "badsyntax_3131.py", + "test_fstring.py", + # TODO Fix: F811 Redefinition of unused name "test_buffer.py", "test_dataclasses.py", "test_descr.py",