Skip to content

Commit

Permalink
chore: move to using Ruff (#71)
Browse files Browse the repository at this point in the history
Signed-off-by: Henry Schreiner <henryschreineriii@gmail.com>
  • Loading branch information
henryiii authored and edgarrmondragon committed May 17, 2023
1 parent d458e00 commit 6aaf4d7
Show file tree
Hide file tree
Showing 6 changed files with 57 additions and 30 deletions.
3 changes: 0 additions & 3 deletions .flake8

This file was deleted.

15 changes: 6 additions & 9 deletions .pre-commit-config.yaml
Original file line number Diff line number Diff line change
@@ -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
Expand All @@ -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"]
1 change: 0 additions & 1 deletion MANIFEST.in
Original file line number Diff line number Diff line change
@@ -1,7 +1,6 @@
include *.py
include *.txt
include *.yaml
include .flake8
include .pre-commit-config.yaml
include CHANGELOG.md
include LICENSE
Expand Down
15 changes: 7 additions & 8 deletions plugin_test.py
Original file line number Diff line number Diff line change
@@ -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"
Expand All @@ -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 + "*",
)
Expand Down Expand Up @@ -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):
Expand All @@ -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):
Expand Down Expand Up @@ -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):
Expand Down
38 changes: 38 additions & 0 deletions pyproject.toml
Original file line number Diff line number Diff line change
Expand Up @@ -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"]
15 changes: 6 additions & 9 deletions pytest_github_actions_annotate_failures/plugin.py
Original file line number Diff line number Diff line change
@@ -1,17 +1,14 @@
# -*- coding: utf-8 -*-

from __future__ import annotations

import os
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
Expand All @@ -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()
Expand Down Expand Up @@ -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":
Expand Down Expand Up @@ -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")
Expand All @@ -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),
Expand All @@ -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:
Expand Down

0 comments on commit 6aaf4d7

Please sign in to comment.