Skip to content

Commit 4588653

Browse files
Migrate from autoflake, black, isort, pyupgrade, flake8 and pydocstyle, to ruff
ruff is faster and handle everything we had prior. isort configuration done based on the indication from astral-sh/ruff#4670, previousely based on reorder-python-import (#11896) flake8-docstrings was a wrapper around pydocstyle (now archived) that explicitly asks to use ruff in PyCQA/pydocstyle#658. flake8-typing-import is useful mainly for project that support python 3.7 and the one useful check will be implemented in astral-sh/ruff#2302 We need to keep blacken-doc because ruff does not handle detection of python code inside .md and .rst. The direct link to the repo is now used to avoid a redirection. Manual fixes: - Lines that became too long - % formatting that was not done automatically - type: ignore that were moved around - noqa of hard to fix issues (UP031 generally) - fmt: off and fmt: on that is not really identical between black and ruff - autofix re-order in pre-commit from faster to slower Co-authored-by: Ran Benita <[email protected]>
1 parent 046f647 commit 4588653

File tree

149 files changed

+799
-971
lines changed

Some content is hidden

Large Commits have some content hidden by default. Use the searchbox below for content that may be hidden.

149 files changed

+799
-971
lines changed

.pre-commit-config.yaml

Lines changed: 10 additions & 36 deletions
Original file line numberDiff line numberDiff line change
@@ -1,14 +1,10 @@
11
repos:
2-
- repo: https://github.com/psf/black
3-
rev: 24.1.1
4-
hooks:
5-
- id: black
6-
args: [--safe, --quiet]
7-
- repo: https://github.com/asottile/blacken-docs
8-
rev: 1.16.0
9-
hooks:
10-
- id: blacken-docs
11-
additional_dependencies: [black==24.1.1]
2+
- repo: https://github.com/astral-sh/ruff-pre-commit
3+
rev: "v0.1.15"
4+
hooks:
5+
- id: ruff
6+
args: ["--fix"]
7+
- id: ruff-format
128
- repo: https://github.com/pre-commit/pre-commit-hooks
139
rev: v4.5.0
1410
hooks:
@@ -20,33 +16,11 @@ repos:
2016
- id: debug-statements
2117
exclude: _pytest/(debugging|hookspec).py
2218
language_version: python3
23-
- repo: https://github.com/PyCQA/autoflake
24-
rev: v2.2.1
25-
hooks:
26-
- id: autoflake
27-
name: autoflake
28-
args: ["--in-place", "--remove-unused-variables", "--remove-all-unused-imports"]
29-
language: python
30-
files: \.py$
31-
- repo: https://github.com/PyCQA/flake8
32-
rev: 7.0.0
33-
hooks:
34-
- id: flake8
35-
language_version: python3
36-
additional_dependencies:
37-
- flake8-typing-imports==1.12.0
38-
- flake8-docstrings==1.5.0
39-
- repo: https://github.com/pycqa/isort
40-
rev: 5.13.2
41-
hooks:
42-
- id: isort
43-
name: isort
44-
args: [--force-single-line, --profile=black]
45-
- repo: https://github.com/asottile/pyupgrade
46-
rev: v3.15.0
19+
- repo: https://github.com/adamchainz/blacken-docs
20+
rev: 1.16.0
4721
hooks:
48-
- id: pyupgrade
49-
args: [--py38-plus]
22+
- id: blacken-docs
23+
additional_dependencies: [black==24.1.1]
5024
- repo: https://github.com/asottile/setup-cfg-fmt
5125
rev: v2.5.0
5226
hooks:

README.rst

Lines changed: 0 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -27,9 +27,6 @@
2727
:target: https://results.pre-commit.ci/latest/github/pytest-dev/pytest/main
2828
:alt: pre-commit.ci status
2929

30-
.. image:: https://img.shields.io/badge/code%20style-black-000000.svg
31-
:target: https://github.com/psf/black
32-
3330
.. image:: https://www.codetriage.com/pytest-dev/pytest/badges/users.svg
3431
:target: https://www.codetriage.com/pytest-dev/pytest
3532

bench/bench.py

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,6 @@
11
import sys
22

3+
34
if __name__ == "__main__":
45
import cProfile
56
import pstats

bench/bench_argcomplete.py

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -4,6 +4,7 @@
44
# FastFilesCompleter 0.7383 1.0760
55
import timeit
66

7+
78
imports = [
89
"from argcomplete.completers import FilesCompleter as completer",
910
"from _pytest._argcomplete import FastFilesCompleter as completer",

bench/skip.py

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,6 @@
11
import pytest
22

3+
34
SKIP = True
45

56

bench/unit_test.py

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,6 @@
11
from unittest import TestCase # noqa: F401
22

3+
34
for i in range(15000):
45
exec(
56
f"""

doc/en/conf.py

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -23,6 +23,7 @@
2323

2424
from _pytest import __version__ as version
2525

26+
2627
if TYPE_CHECKING:
2728
import sphinx.application
2829

doc/en/example/assertion/global_testmodule_config/conftest.py

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -2,6 +2,7 @@
22

33
import pytest
44

5+
56
mydir = os.path.dirname(__file__)
67

78

doc/en/example/assertion/test_failures.py

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,7 @@
11
import os.path
22
import shutil
33

4+
45
failure_demo = os.path.join(os.path.dirname(__file__), "failure_demo.py")
56
pytest_plugins = ("pytester",)
67

doc/en/example/multipython.py

Lines changed: 9 additions & 12 deletions
Original file line numberDiff line numberDiff line change
@@ -7,6 +7,7 @@
77

88
import pytest
99

10+
1011
pythonlist = ["python3.9", "python3.10", "python3.11"]
1112

1213

@@ -32,14 +33,12 @@ def dumps(self, obj):
3233
dumpfile = self.picklefile.with_name("dump.py")
3334
dumpfile.write_text(
3435
textwrap.dedent(
35-
r"""
36+
rf"""
3637
import pickle
37-
f = open({!r}, 'wb')
38-
s = pickle.dump({!r}, f, protocol=2)
38+
f = open({str(self.picklefile)!r}, 'wb')
39+
s = pickle.dump({obj!r}, f, protocol=2)
3940
f.close()
40-
""".format(
41-
str(self.picklefile), obj
42-
)
41+
"""
4342
)
4443
)
4544
subprocess.run((self.pythonpath, str(dumpfile)), check=True)
@@ -48,17 +47,15 @@ def load_and_is_true(self, expression):
4847
loadfile = self.picklefile.with_name("load.py")
4948
loadfile.write_text(
5049
textwrap.dedent(
51-
r"""
50+
rf"""
5251
import pickle
53-
f = open({!r}, 'rb')
52+
f = open({str(self.picklefile)!r}, 'rb')
5453
obj = pickle.load(f)
5554
f.close()
56-
res = eval({!r})
55+
res = eval({expression!r})
5756
if not res:
5857
raise SystemExit(1)
59-
""".format(
60-
str(self.picklefile), expression
61-
)
58+
"""
6259
)
6360
)
6461
print(loadfile)

0 commit comments

Comments
 (0)