From 0f2226896373c17d69d7ea7487c90a05f5dd3370 Mon Sep 17 00:00:00 2001 From: Adam Turner <9087854+AA-Turner@users.noreply.github.com> Date: Sat, 9 Sep 2023 17:33:52 +0100 Subject: [PATCH] Lint: Add Ruff (#3429) --- .github/CODEOWNERS | 1 + .pre-commit-config.yaml | 19 +++++++++++-------- .ruff.toml | 15 +++++++++++++++ .../tests/pep_lint/test_date.py | 2 +- .../tests/pep_lint/test_email.py | 2 +- .../tests/pep_lint/test_headers.py | 2 +- .../tests/pep_lint/test_post_url.py | 4 ---- .../transform/test_pep_headers.py | 12 ++++++------ .../pep_processor/transform/test_pep_zero.py | 2 +- .../tests/pep_zero_generator/test_parser.py | 4 ++-- .../tests/pep_zero_generator/test_writer.py | 2 +- 11 files changed, 40 insertions(+), 25 deletions(-) create mode 100644 .ruff.toml diff --git a/.github/CODEOWNERS b/.github/CODEOWNERS index cecf3d623..a331e70cd 100644 --- a/.github/CODEOWNERS +++ b/.github/CODEOWNERS @@ -20,6 +20,7 @@ contents.rst @AA-Turner .codespell/ @CAM-Gerlach @hugovk .codespellrc @CAM-Gerlach @hugovk .pre-commit-config.yaml @CAM-Gerlach @hugovk +.ruff.toml @AA-Turner @CAM-Gerlach @hugovk check-peps.py @AA-Turner @CAM-Gerlach @hugovk # Git infrastructure diff --git a/.pre-commit-config.yaml b/.pre-commit-config.yaml index 8775917c8..8da57b575 100644 --- a/.pre-commit-config.yaml +++ b/.pre-commit-config.yaml @@ -42,6 +42,17 @@ repos: - id: check-yaml name: "Check YAML" + - repo: https://github.com/astral-sh/ruff-pre-commit + rev: v0.0.287 + hooks: + - id: ruff + name: "Lint with Ruff" + args: + - '--exit-non-zero-on-fix' + - '--diff' + - '--format=github' + files: '^pep_sphinx_extensions/tests/' + - repo: https://github.com/psf/black rev: 23.7.0 hooks: @@ -52,14 +63,6 @@ repos: - '--target-version=py310' files: 'pep_sphinx_extensions/tests/.*' - - repo: https://github.com/PyCQA/isort - rev: 5.12.0 - hooks: - - id: isort - name: "Sort imports with isort" - args: ['--profile=black', '--atomic'] - files: 'pep_sphinx_extensions/tests/.*' - - repo: https://github.com/tox-dev/tox-ini-fmt rev: 1.3.1 hooks: diff --git a/.ruff.toml b/.ruff.toml new file mode 100644 index 000000000..5ab2337f9 --- /dev/null +++ b/.ruff.toml @@ -0,0 +1,15 @@ +ignore = [ + "E501", # Line too long +] + +select = [ + "E", # pycodestyle errors + "F", # pyflakes + "I", # isort + "PT", # flake8-pytest-style + "W", # pycodestyle warnings +] + +show-source = true + +target-version = "py39" diff --git a/pep_sphinx_extensions/tests/pep_lint/test_date.py b/pep_sphinx_extensions/tests/pep_lint/test_date.py index 3ce466610..2218fc2a0 100644 --- a/pep_sphinx_extensions/tests/pep_lint/test_date.py +++ b/pep_sphinx_extensions/tests/pep_lint/test_date.py @@ -93,7 +93,7 @@ def test_date_checker_too_early(date_str: str): [ # the future "31-Dec-2999", - "01-Jan-2100", + "01-Jan-2042", "01-Jan-2100", (dt.datetime.now() + dt.timedelta(days=15)).strftime("%d-%b-%Y"), (dt.datetime.now() + dt.timedelta(days=100)).strftime("%d-%b-%Y"), diff --git a/pep_sphinx_extensions/tests/pep_lint/test_email.py b/pep_sphinx_extensions/tests/pep_lint/test_email.py index 2ff4ba61f..d9f19592d 100644 --- a/pep_sphinx_extensions/tests/pep_lint/test_email.py +++ b/pep_sphinx_extensions/tests/pep_lint/test_email.py @@ -149,7 +149,7 @@ def test_validate_delegate(line: str): (r"Cardinal Ximénez ", {"valid email"}), ("Cardinal Ximénez <[Cardinal.Ximenez]@spanish.inquisition>", {"valid email"}), ('Cardinal Ximénez <"Cardinal"Ximenez"@spanish.inquisition>', {"valid email"}), - ("Cardinal Ximénez ", {"valid email"}), + ("Cardinal Ximenez ", {"valid email"}), ("Cardinal Ximénez ", {"valid email"}), ("Cardinal Ximénez ", {"valid email"}), # ... entries must contain a valid email address (domain) diff --git a/pep_sphinx_extensions/tests/pep_lint/test_headers.py b/pep_sphinx_extensions/tests/pep_lint/test_headers.py index 8246271e3..227eb5397 100644 --- a/pep_sphinx_extensions/tests/pep_lint/test_headers.py +++ b/pep_sphinx_extensions/tests/pep_lint/test_headers.py @@ -196,7 +196,7 @@ def test_validate_type_invalid(line: str): # duplicates ("Governance, Governance", {"duplicates"}), ("Release, Release", {"duplicates"}), - ("Release, Release", {"duplicates"}), + ("Packaging, Packaging", {"duplicates"}), ("Spam, Spam", {"duplicates", "valid"}), ("lobster, lobster", {"duplicates", "capitalisation", "valid"}), ("governance, governance", {"duplicates", "capitalisation"}), diff --git a/pep_sphinx_extensions/tests/pep_lint/test_post_url.py b/pep_sphinx_extensions/tests/pep_lint/test_post_url.py index dd04b4c39..982f4612e 100644 --- a/pep_sphinx_extensions/tests/pep_lint/test_post_url.py +++ b/pep_sphinx_extensions/tests/pep_lint/test_post_url.py @@ -108,8 +108,6 @@ def test_validate_resolution_valid(line: str): "https://mail.python.org/archives/list/list-name@python.org/thread/abcXYZ123/#anchor", "https://mail.python.org/archives/list/list-name@python.org/message/#abcXYZ123", "https://mail.python.org/archives/list/list-name@python.org/message/#abcXYZ123/", - "https://mail.python.org/archives/list/list-name@python.org/message/abcXYZ123/anchor/", - "https://mail.python.org/archives/list/list-name@python.org/message/abcXYZ123/anchor/", "https://mail.python.org/archives/list/list-name@python.org/spam/abcXYZ123", "https://mail.python.org/archives/list/list-name@python.org/spam/abcXYZ123/", ], @@ -233,8 +231,6 @@ def test_thread_checker_valid_allow_message(thread_url: str): "https://mail.python.org/archives/list/list-name@python.org/thread/abcXYZ123/#anchor", "https://mail.python.org/archives/list/list-name@python.org/message/#abcXYZ123", "https://mail.python.org/archives/list/list-name@python.org/message/#abcXYZ123/", - "https://mail.python.org/archives/list/list-name@python.org/message/abcXYZ123/anchor/", - "https://mail.python.org/archives/list/list-name@python.org/message/abcXYZ123/anchor/", "https://mail.python.org/archives/list/list-name@python.org/spam/abcXYZ123", "https://mail.python.org/archives/list/list-name@python.org/spam/abcXYZ123/", ], diff --git a/pep_sphinx_extensions/tests/pep_processor/transform/test_pep_headers.py b/pep_sphinx_extensions/tests/pep_processor/transform/test_pep_headers.py index 4cc45423e..772c24158 100644 --- a/pep_sphinx_extensions/tests/pep_processor/transform/test_pep_headers.py +++ b/pep_sphinx_extensions/tests/pep_processor/transform/test_pep_headers.py @@ -18,7 +18,7 @@ from pep_sphinx_extensions.pep_zero_generator.constants import ( @pytest.mark.parametrize( - "test_input, expected", + ("test_input", "expected"), [ ("my-mailing-list@example.com", "my-mailing-list@example.com"), ("python-tulip@googlegroups.com", "https://groups.google.com/g/python-tulip"), @@ -37,7 +37,7 @@ def test_generate_list_url(test_input, expected): @pytest.mark.parametrize( - "test_input, expected", + ("test_input", "expected"), [ ( "https://mail.python.org/pipermail/python-3000/2006-November/004190.html", @@ -72,7 +72,7 @@ def test_process_pretty_url(test_input, expected): @pytest.mark.parametrize( - "test_input, expected", + ("test_input", "expected"), [ ( "https://example.com/", @@ -94,7 +94,7 @@ def test_process_pretty_url_invalid(test_input, expected): @pytest.mark.parametrize( - "test_input, expected", + ("test_input", "expected"), [ ( "https://mail.python.org/pipermail/python-3000/2006-November/004190.html", @@ -129,7 +129,7 @@ def test_make_link_pretty(test_input, expected): @pytest.mark.parametrize( - "test_input, expected", + ("test_input", "expected"), [ (STATUS_ACCEPTED, "Normative proposal accepted for implementation"), (STATUS_ACTIVE, "Currently valid informational guidance, or an in-use process"), @@ -155,7 +155,7 @@ def test_abbreviate_status_unknown(): @pytest.mark.parametrize( - "test_input, expected", + ("test_input", "expected"), [ ( TYPE_INFO, diff --git a/pep_sphinx_extensions/tests/pep_processor/transform/test_pep_zero.py b/pep_sphinx_extensions/tests/pep_processor/transform/test_pep_zero.py index 09b2effea..e25d37fd2 100644 --- a/pep_sphinx_extensions/tests/pep_processor/transform/test_pep_zero.py +++ b/pep_sphinx_extensions/tests/pep_processor/transform/test_pep_zero.py @@ -5,7 +5,7 @@ from pep_sphinx_extensions.pep_processor.transforms import pep_zero @pytest.mark.parametrize( - "test_input, expected", + ("test_input", "expected"), [ ( nodes.reference( diff --git a/pep_sphinx_extensions/tests/pep_zero_generator/test_parser.py b/pep_sphinx_extensions/tests/pep_zero_generator/test_parser.py index cea1d61ab..0a1a108e1 100644 --- a/pep_sphinx_extensions/tests/pep_zero_generator/test_parser.py +++ b/pep_sphinx_extensions/tests/pep_zero_generator/test_parser.py @@ -52,7 +52,7 @@ def test_pep_details(monkeypatch): @pytest.mark.parametrize( - "test_input, expected", + ("test_input", "expected"), [ ( "First Last ", @@ -88,7 +88,7 @@ def test_parse_authors_invalid(): @pytest.mark.parametrize( - "test_type, test_status, expected", + ("test_type", "test_status", "expected"), [ (TYPE_INFO, STATUS_DRAFT, ":abbr:`I (Informational, Draft)`"), (TYPE_INFO, STATUS_ACTIVE, ":abbr:`IA (Informational, Active)`"), diff --git a/pep_sphinx_extensions/tests/pep_zero_generator/test_writer.py b/pep_sphinx_extensions/tests/pep_zero_generator/test_writer.py index 150a317bb..1ccf8c418 100644 --- a/pep_sphinx_extensions/tests/pep_zero_generator/test_writer.py +++ b/pep_sphinx_extensions/tests/pep_zero_generator/test_writer.py @@ -30,7 +30,7 @@ def test_pep_zero_writer_emit_title(): @pytest.mark.parametrize( - "test_input, expected", + ("test_input", "expected"), [ ( "pep-9000.rst",