Skip to content

Commit 3dd8914

Browse files
authored
Migrate formatting and linting to Ruff (#675)
1 parent 88de49a commit 3dd8914

File tree

5 files changed

+46
-41
lines changed

5 files changed

+46
-41
lines changed

.pre-commit-config.yaml

Lines changed: 5 additions & 22 deletions
Original file line numberDiff line numberDiff line change
@@ -34,35 +34,18 @@ repos:
3434
- id: rstcheck
3535
additional_dependencies:
3636
- tomli==2.0.1
37-
- repo: https://github.com/asottile/pyupgrade
38-
rev: ce40a160603ab0e7d9c627ae33d7ef3906e2d2b2 # frozen: v3.19.1
39-
hooks:
40-
- id: pyupgrade
41-
args: [--py39-plus]
42-
- repo: https://github.com/psf/black-pre-commit-mirror
43-
rev: a4920527036bb9a3f3e6055d595849d67d0da066 # frozen: 25.1.0
44-
hooks:
45-
- id: black
4637
- repo: https://github.com/adamchainz/blacken-docs
4738
rev: 78a9dcbecf4f755f65d1f3dec556bc249d723600 # frozen: 1.19.1
4839
hooks:
4940
- id: blacken-docs
5041
additional_dependencies:
5142
- black==25.1.0
52-
- repo: https://github.com/pycqa/isort
53-
rev: c8ab4a5b21bac924d106e3103dd7c979fdd0f9bc # frozen: 6.0.1
43+
- repo: https://github.com/astral-sh/ruff-pre-commit
44+
rev: 12753357c00c3fb8615100354c9fdc6ab80b044d # frozen: v0.11.10
5445
hooks:
55-
- id: isort
56-
name: isort (python)
57-
- repo: https://github.com/PyCQA/flake8
58-
rev: 4b5e89b4b108a6c1a000c591d334a99a80d34c7b # frozen: 7.2.0
59-
hooks:
60-
- id: flake8
61-
additional_dependencies:
62-
- flake8-bugbear
63-
- flake8-comprehensions
64-
- flake8-logging
65-
- flake8-tidy-imports
46+
- id: ruff-check
47+
args: [ --fix ]
48+
- id: ruff-format
6649
- repo: https://github.com/pre-commit/mirrors-mypy
6750
rev: f40886d54c729f533f864ed6ce584e920feb0af7 # frozen: v1.15.0
6851
hooks:

pyproject.toml

Lines changed: 35 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -56,12 +56,42 @@ test = [
5656
"pytest-xdist",
5757
]
5858

59-
[tool.isort]
60-
add_imports = [
61-
"from __future__ import annotations",
59+
[tool.ruff]
60+
lint.select = [
61+
# flake8-bugbear
62+
"B",
63+
# flake8-comprehensions
64+
"C4",
65+
# pycodestyle
66+
"E",
67+
# Pyflakes errors
68+
"F",
69+
# isort
70+
"I",
71+
# flake8-simplify
72+
"SIM",
73+
# flake8-tidy-imports
74+
"TID",
75+
# pyupgrade
76+
"UP",
77+
# Pyflakes warnings
78+
"W",
6279
]
63-
force_single_line = true
64-
profile = "black"
80+
lint.ignore = [
81+
# flake8-bugbear opinionated rules
82+
"B9",
83+
# line-too-long
84+
"E501",
85+
# suppressible-exception
86+
"SIM105",
87+
# if-else-block-instead-of-if-exp
88+
"SIM108",
89+
]
90+
lint.extend-safe-fixes = [
91+
# non-pep585-annotation
92+
"UP006",
93+
]
94+
lint.isort.required-imports = [ "from __future__ import annotations" ]
6595

6696
[tool.pyproject-fmt]
6797
max_supported_python = "3.13"

src/pytest_randomly/__init__.py

Lines changed: 5 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -6,16 +6,12 @@
66
import sys
77
from itertools import groupby
88
from types import ModuleType
9-
from typing import Any
10-
from typing import Callable
11-
from typing import TypeVar
9+
from typing import Any, Callable, TypeVar
1210

1311
from _pytest.config import Config
1412
from _pytest.config.argparsing import Parser
1513
from _pytest.nodes import Item
16-
from pytest import Collector
17-
from pytest import fixture
18-
from pytest import hookimpl
14+
from pytest import Collector, fixture, hookimpl
1915

2016
if sys.version_info < (3, 10):
2117
from importlib_metadata import entry_points
@@ -117,9 +113,9 @@ def pytest_configure(config: Config) -> None:
117113

118114
seed_value = config.getoption("randomly_seed")
119115
if seed_value == "last":
120-
assert hasattr(
121-
config, "cache"
122-
), "The cacheprovider plugin is required to use 'last'"
116+
assert hasattr(config, "cache"), (
117+
"The cacheprovider plugin is required to use 'last'"
118+
)
123119
assert config.cache is not None
124120
seed = config.cache.get("randomly_seed", default_seed)
125121
elif seed_value == "default":

tests/test_pytest_randomly.py

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -738,7 +738,7 @@ def test_failing_import(testdir):
738738

739739
modcol = testdir.getmodulecol("pytest_plugins='xasdlkj',")
740740
with pytest.raises(ImportError):
741-
modcol.obj
741+
modcol.obj # noqa: B018
742742

743743

744744
def test_entrypoint_injection(pytester, monkeypatch):

tox.ini

Lines changed: 0 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -21,7 +21,3 @@ commands =
2121
-m pytest -p no:randomly {posargs:tests}
2222
dependency_groups =
2323
test
24-
25-
[flake8]
26-
max-line-length = 88
27-
extend-ignore = E203,E501

0 commit comments

Comments
 (0)