diff --git a/.flake8 b/.flake8 deleted file mode 100644 index b23915d..0000000 --- a/.flake8 +++ /dev/null @@ -1,3 +0,0 @@ -[flake8] -ignore = E203, E231, E501, E722, W503, B950 -select = C,E,F,W,B,B9,I diff --git a/.pre-commit-config.yaml b/.pre-commit-config.yaml index df86f85..c8fcc59 100644 --- a/.pre-commit-config.yaml +++ b/.pre-commit-config.yaml @@ -1,6 +1,6 @@ repos: - repo: https://github.com/pre-commit/pre-commit-hooks - rev: v3.1.0 + rev: "v4.4.0" hooks: - id: check-added-large-files - id: check-case-conflict @@ -12,17 +12,14 @@ repos: - id: mixed-line-ending - id: requirements-txt-fixer - id: trailing-whitespace - - id: fix-encoding-pragma - repo: https://github.com/mgedmin/check-manifest - rev: "0.42" + rev: "0.49" hooks: - id: check-manifest -- repo: https://github.com/PyCQA/flake8 - rev: 3.8.3 +- repo: https://github.com/charliermarsh/ruff-pre-commit + rev: "v0.0.262" hooks: - - id: flake8 - additional_dependencies: - - flake8-bugbear - - flake8-import-order + - id: ruff + args: ["--fix", "--show-fixes"] diff --git a/MANIFEST.in b/MANIFEST.in index d07d8e6..ee937c8 100644 --- a/MANIFEST.in +++ b/MANIFEST.in @@ -1,7 +1,6 @@ include *.py include *.txt include *.yaml -include .flake8 include .pre-commit-config.yaml include CHANGELOG.md include LICENSE diff --git a/plugin_test.py b/plugin_test.py index 2cab47a..df73cd6 100644 --- a/plugin_test.py +++ b/plugin_test.py @@ -1,10 +1,9 @@ -# -*- coding: utf-8 -*- -import os +from __future__ import annotations -from packaging import version +import os import pytest - +from packaging import version PYTEST_VERSION = version.parse(pytest.__version__) pytest_plugins = "pytester" @@ -13,7 +12,7 @@ # result.stderr.no_fnmatch_line() is added to testdir on pytest 5.3.0 # https://docs.pytest.org/en/stable/changelog.html#pytest-5-3-0-2019-11-19 def no_fnmatch_line(result, pattern): - if PYTEST_VERSION >= version.parse("5.3.0"): + if version.parse("5.3.0") <= PYTEST_VERSION: result.stderr.no_fnmatch_line( pattern + "*", ) @@ -99,7 +98,7 @@ def test_fail(): @pytest.mark.skipif( - PYTEST_VERSION < version.parse("6.0.0"), + version.parse("6.0.0") > PYTEST_VERSION, reason="requires pytest 6.0.0", ) def test_annotation_warning(testdir): @@ -124,7 +123,7 @@ def test_warning(): @pytest.mark.skipif( - PYTEST_VERSION < version.parse("6.0.0"), + version.parse("6.0.0") > PYTEST_VERSION, reason="requires pytest 6.0.0", ) def test_annotation_exclude_warnings(testdir): @@ -172,7 +171,7 @@ def test_fail(): @pytest.mark.skipif( - PYTEST_VERSION < version.parse("6.0.0"), + version.parse("6.0.0") > PYTEST_VERSION, reason="requires pytest 6.0.0", ) def test_annotation_third_party_warning(testdir): diff --git a/pyproject.toml b/pyproject.toml index 69c327f..7e3ba1e 100644 --- a/pyproject.toml +++ b/pyproject.toml @@ -49,3 +49,41 @@ changelog = "https://github.com/pytest-dev/pytest-github-actions-annotate-failur [project.entry-points.pytest11] pytest_github_actions_annotate_failures = "pytest_github_actions_annotate_failures.plugin" + + +[tool.ruff] +select = [ + "E", "F", "W", # flake8 + "B", # flake8-bugbear + "I", # isort + "ARG", # flake8-unused-arguments + "C4", # flake8-comprehensions + "EM", # flake8-errmsg + "ICN", # flake8-import-conventions + "ISC", # flake8-implicit-str-concat + "G", # flake8-logging-format + "PGH", # pygrep-hooks + "PIE", # flake8-pie + "PL", # pylint + "PT", # flake8-pytest-style + "RET", # flake8-return + "RUF", # Ruff-specific + "SIM", # flake8-simplify + "UP", # pyupgrade + "YTT", # flake8-2020 + "EXE", # flake8-executable +] +extend-ignore = [ + "PLR", # Design related pylint codes + "E501", # Line too long + "PT004", # Use underscore for non-returning fixture (use usefixture instead) +] +target-version = "py37" +unfixable = [ + "T20", # Removes print statements + "F841", # Removes unused variables +] +isort.required-imports = ["from __future__ import annotations"] + +[tool.ruff.per-file-ignores] +"tests/**" = ["T20"] diff --git a/pytest_github_actions_annotate_failures/plugin.py b/pytest_github_actions_annotate_failures/plugin.py index 3199a63..cc16ae7 100644 --- a/pytest_github_actions_annotate_failures/plugin.py +++ b/pytest_github_actions_annotate_failures/plugin.py @@ -1,4 +1,3 @@ -# -*- coding: utf-8 -*- from __future__ import annotations @@ -6,12 +5,10 @@ import sys from typing import TYPE_CHECKING +import pytest from _pytest._code.code import ExceptionRepr - from packaging import version -import pytest - if TYPE_CHECKING: from _pytest.nodes import Item from _pytest.reports import CollectReport @@ -30,7 +27,7 @@ @pytest.hookimpl(tryfirst=True, hookwrapper=True) -def pytest_runtest_makereport(item: Item, call): +def pytest_runtest_makereport(item: Item, call): # noqa: ARG001 # execute all other hooks to obtain the report object outcome = yield report: CollectReport = outcome.get_result() @@ -95,7 +92,7 @@ def pytest_runtest_makereport(item: Item, call): class _AnnotateWarnings: - def pytest_warning_recorded(self, warning_message, when, nodeid, location): + def pytest_warning_recorded(self, warning_message, when, nodeid, location): # noqa: ARG002 # enable only in a workflow of GitHub Actions # ref: https://help.github.com/en/actions/configuring-and-managing-workflows/using-environment-variables#default-environment-variables if os.environ.get("GITHUB_ACTIONS") != "true": @@ -125,7 +122,7 @@ def pytest_warning_recorded(self, warning_message, when, nodeid, location): print(workflow_command, file=sys.stderr) -if PYTEST_VERSION >= version.parse("6.0.0"): +if version.parse("6.0.0") <= PYTEST_VERSION: def pytest_addoption(parser): group = parser.getgroup("pytest_github_actions_annotate_failures") @@ -152,7 +149,7 @@ def _build_workflow_command( message=None, ): """Build a command to annotate a workflow.""" - result = "::{} ".format(command_name) + result = f"::{command_name} " entries = [ ("file", file), @@ -164,7 +161,7 @@ def _build_workflow_command( ] result = result + ",".join( - "{}={}".format(k, v) for k, v in entries if v is not None + f"{k}={v}" for k, v in entries if v is not None ) if message is not None: