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..24f3f8c65dcf5f --- /dev/null +++ b/Lib/test/.ruff.toml @@ -0,0 +1,30 @@ +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", + "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", + "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_tokenize.py", + "test_typing.py", + "test_yield_from.py", + "time_hashlib.py", +]