Skip to content

Commit 6aaf4d7

Browse files
henryiiiedgarrmondragon
authored andcommitted
chore: move to using Ruff (#71)
Signed-off-by: Henry Schreiner <[email protected]>
1 parent d458e00 commit 6aaf4d7

File tree

6 files changed

+57
-30
lines changed

6 files changed

+57
-30
lines changed

.flake8

-3
This file was deleted.

.pre-commit-config.yaml

+6-9
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,6 @@
11
repos:
22
- repo: https://github.com/pre-commit/pre-commit-hooks
3-
rev: v3.1.0
3+
rev: "v4.4.0"
44
hooks:
55
- id: check-added-large-files
66
- id: check-case-conflict
@@ -12,17 +12,14 @@ repos:
1212
- id: mixed-line-ending
1313
- id: requirements-txt-fixer
1414
- id: trailing-whitespace
15-
- id: fix-encoding-pragma
1615

1716
- repo: https://github.com/mgedmin/check-manifest
18-
rev: "0.42"
17+
rev: "0.49"
1918
hooks:
2019
- id: check-manifest
2120

22-
- repo: https://github.com/PyCQA/flake8
23-
rev: 3.8.3
21+
- repo: https://github.com/charliermarsh/ruff-pre-commit
22+
rev: "v0.0.262"
2423
hooks:
25-
- id: flake8
26-
additional_dependencies:
27-
- flake8-bugbear
28-
- flake8-import-order
24+
- id: ruff
25+
args: ["--fix", "--show-fixes"]

MANIFEST.in

-1
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,6 @@
11
include *.py
22
include *.txt
33
include *.yaml
4-
include .flake8
54
include .pre-commit-config.yaml
65
include CHANGELOG.md
76
include LICENSE

plugin_test.py

+7-8
Original file line numberDiff line numberDiff line change
@@ -1,10 +1,9 @@
1-
# -*- coding: utf-8 -*-
2-
import os
1+
from __future__ import annotations
32

4-
from packaging import version
3+
import os
54

65
import pytest
7-
6+
from packaging import version
87

98
PYTEST_VERSION = version.parse(pytest.__version__)
109
pytest_plugins = "pytester"
@@ -13,7 +12,7 @@
1312
# result.stderr.no_fnmatch_line() is added to testdir on pytest 5.3.0
1413
# https://docs.pytest.org/en/stable/changelog.html#pytest-5-3-0-2019-11-19
1514
def no_fnmatch_line(result, pattern):
16-
if PYTEST_VERSION >= version.parse("5.3.0"):
15+
if version.parse("5.3.0") <= PYTEST_VERSION:
1716
result.stderr.no_fnmatch_line(
1817
pattern + "*",
1918
)
@@ -99,7 +98,7 @@ def test_fail():
9998

10099

101100
@pytest.mark.skipif(
102-
PYTEST_VERSION < version.parse("6.0.0"),
101+
version.parse("6.0.0") > PYTEST_VERSION,
103102
reason="requires pytest 6.0.0",
104103
)
105104
def test_annotation_warning(testdir):
@@ -124,7 +123,7 @@ def test_warning():
124123

125124

126125
@pytest.mark.skipif(
127-
PYTEST_VERSION < version.parse("6.0.0"),
126+
version.parse("6.0.0") > PYTEST_VERSION,
128127
reason="requires pytest 6.0.0",
129128
)
130129
def test_annotation_exclude_warnings(testdir):
@@ -172,7 +171,7 @@ def test_fail():
172171

173172

174173
@pytest.mark.skipif(
175-
PYTEST_VERSION < version.parse("6.0.0"),
174+
version.parse("6.0.0") > PYTEST_VERSION,
176175
reason="requires pytest 6.0.0",
177176
)
178177
def test_annotation_third_party_warning(testdir):

pyproject.toml

+38
Original file line numberDiff line numberDiff line change
@@ -49,3 +49,41 @@ changelog = "https://github.com/pytest-dev/pytest-github-actions-annotate-failur
4949

5050
[project.entry-points.pytest11]
5151
pytest_github_actions_annotate_failures = "pytest_github_actions_annotate_failures.plugin"
52+
53+
54+
[tool.ruff]
55+
select = [
56+
"E", "F", "W", # flake8
57+
"B", # flake8-bugbear
58+
"I", # isort
59+
"ARG", # flake8-unused-arguments
60+
"C4", # flake8-comprehensions
61+
"EM", # flake8-errmsg
62+
"ICN", # flake8-import-conventions
63+
"ISC", # flake8-implicit-str-concat
64+
"G", # flake8-logging-format
65+
"PGH", # pygrep-hooks
66+
"PIE", # flake8-pie
67+
"PL", # pylint
68+
"PT", # flake8-pytest-style
69+
"RET", # flake8-return
70+
"RUF", # Ruff-specific
71+
"SIM", # flake8-simplify
72+
"UP", # pyupgrade
73+
"YTT", # flake8-2020
74+
"EXE", # flake8-executable
75+
]
76+
extend-ignore = [
77+
"PLR", # Design related pylint codes
78+
"E501", # Line too long
79+
"PT004", # Use underscore for non-returning fixture (use usefixture instead)
80+
]
81+
target-version = "py37"
82+
unfixable = [
83+
"T20", # Removes print statements
84+
"F841", # Removes unused variables
85+
]
86+
isort.required-imports = ["from __future__ import annotations"]
87+
88+
[tool.ruff.per-file-ignores]
89+
"tests/**" = ["T20"]

pytest_github_actions_annotate_failures/plugin.py

+6-9
Original file line numberDiff line numberDiff line change
@@ -1,17 +1,14 @@
1-
# -*- coding: utf-8 -*-
21

32
from __future__ import annotations
43

54
import os
65
import sys
76
from typing import TYPE_CHECKING
87

8+
import pytest
99
from _pytest._code.code import ExceptionRepr
10-
1110
from packaging import version
1211

13-
import pytest
14-
1512
if TYPE_CHECKING:
1613
from _pytest.nodes import Item
1714
from _pytest.reports import CollectReport
@@ -30,7 +27,7 @@
3027

3128

3229
@pytest.hookimpl(tryfirst=True, hookwrapper=True)
33-
def pytest_runtest_makereport(item: Item, call):
30+
def pytest_runtest_makereport(item: Item, call): # noqa: ARG001
3431
# execute all other hooks to obtain the report object
3532
outcome = yield
3633
report: CollectReport = outcome.get_result()
@@ -95,7 +92,7 @@ def pytest_runtest_makereport(item: Item, call):
9592

9693

9794
class _AnnotateWarnings:
98-
def pytest_warning_recorded(self, warning_message, when, nodeid, location):
95+
def pytest_warning_recorded(self, warning_message, when, nodeid, location): # noqa: ARG002
9996
# enable only in a workflow of GitHub Actions
10097
# ref: https://help.github.com/en/actions/configuring-and-managing-workflows/using-environment-variables#default-environment-variables
10198
if os.environ.get("GITHUB_ACTIONS") != "true":
@@ -125,7 +122,7 @@ def pytest_warning_recorded(self, warning_message, when, nodeid, location):
125122
print(workflow_command, file=sys.stderr)
126123

127124

128-
if PYTEST_VERSION >= version.parse("6.0.0"):
125+
if version.parse("6.0.0") <= PYTEST_VERSION:
129126

130127
def pytest_addoption(parser):
131128
group = parser.getgroup("pytest_github_actions_annotate_failures")
@@ -152,7 +149,7 @@ def _build_workflow_command(
152149
message=None,
153150
):
154151
"""Build a command to annotate a workflow."""
155-
result = "::{} ".format(command_name)
152+
result = f"::{command_name} "
156153

157154
entries = [
158155
("file", file),
@@ -164,7 +161,7 @@ def _build_workflow_command(
164161
]
165162

166163
result = result + ",".join(
167-
"{}={}".format(k, v) for k, v in entries if v is not None
164+
f"{k}={v}" for k, v in entries if v is not None
168165
)
169166

170167
if message is not None:

0 commit comments

Comments
 (0)