Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Migrate from autoflake, black, isort, pyupgrade, flake8 and pydocstyle, to ruff #11901

Merged
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
6 changes: 4 additions & 2 deletions .git-blame-ignore-revs
Original file line number Diff line number Diff line change
Expand Up @@ -23,9 +23,11 @@ afc607cfd81458d4e4f3b1f3cf8cc931b933907e
5f95dce95602921a70bfbc7d8de2f7712c5e4505
# ran pyupgrade-docs again
75d0b899bbb56d6849e9d69d83a9426ed3f43f8b

# move argument parser to own file
c9df77cbd6a365dcb73c39618e4842711817e871

# Replace reorder-python-imports by isort due to black incompatibility (#11896)
8b54596639f41dfac070030ef20394b9001fe63c
# Run blacken-docs with black's 2024's style
4546d5445aaefe6a03957db028c263521dfb5c4b
# Migration to ruff / ruff format
4588653b2497ed25976b7aaff225b889fb476756
46 changes: 10 additions & 36 deletions .pre-commit-config.yaml
Original file line number Diff line number Diff line change
@@ -1,14 +1,10 @@
repos:
- repo: https://github.com/psf/black
rev: 24.1.1
hooks:
- id: black
args: [--safe, --quiet]
- repo: https://github.com/asottile/blacken-docs
rev: 1.16.0
hooks:
- id: blacken-docs
additional_dependencies: [black==24.1.1]
- repo: https://github.com/astral-sh/ruff-pre-commit
rev: "v0.1.15"
hooks:
- id: ruff
args: ["--fix"]
- id: ruff-format
- repo: https://github.com/pre-commit/pre-commit-hooks
rev: v4.5.0
hooks:
Expand All @@ -20,33 +16,11 @@ repos:
- id: debug-statements
exclude: _pytest/(debugging|hookspec).py
language_version: python3
- repo: https://github.com/PyCQA/autoflake
rev: v2.2.1
hooks:
- id: autoflake
name: autoflake
args: ["--in-place", "--remove-unused-variables", "--remove-all-unused-imports"]
language: python
files: \.py$
- repo: https://github.com/PyCQA/flake8
rev: 7.0.0
hooks:
- id: flake8
language_version: python3
additional_dependencies:
- flake8-typing-imports==1.12.0
- flake8-docstrings==1.5.0
- repo: https://github.com/pycqa/isort
rev: 5.13.2
hooks:
- id: isort
name: isort
args: [--force-single-line, --profile=black]
- repo: https://github.com/asottile/pyupgrade
rev: v3.15.0
- repo: https://github.com/adamchainz/blacken-docs
rev: 1.16.0
hooks:
- id: pyupgrade
args: [--py38-plus]
- id: blacken-docs
additional_dependencies: [black==24.1.1]
- repo: https://github.com/asottile/setup-cfg-fmt
rev: v2.5.0
hooks:
Expand Down
3 changes: 0 additions & 3 deletions README.rst
Original file line number Diff line number Diff line change
Expand Up @@ -27,9 +27,6 @@
:target: https://results.pre-commit.ci/latest/github/pytest-dev/pytest/main
:alt: pre-commit.ci status

.. image:: https://img.shields.io/badge/code%20style-black-000000.svg
:target: https://github.com/psf/black

.. image:: https://www.codetriage.com/pytest-dev/pytest/badges/users.svg
:target: https://www.codetriage.com/pytest-dev/pytest

Expand Down
1 change: 1 addition & 0 deletions bench/bench.py
Original file line number Diff line number Diff line change
@@ -1,5 +1,6 @@
import sys


if __name__ == "__main__":
import cProfile
import pstats
Expand Down
1 change: 1 addition & 0 deletions bench/bench_argcomplete.py
Original file line number Diff line number Diff line change
Expand Up @@ -4,6 +4,7 @@
# FastFilesCompleter 0.7383 1.0760
import timeit


imports = [
"from argcomplete.completers import FilesCompleter as completer",
"from _pytest._argcomplete import FastFilesCompleter as completer",
Expand Down
1 change: 1 addition & 0 deletions bench/skip.py
Original file line number Diff line number Diff line change
@@ -1,5 +1,6 @@
import pytest


SKIP = True


Expand Down
1 change: 1 addition & 0 deletions bench/unit_test.py
Original file line number Diff line number Diff line change
@@ -1,5 +1,6 @@
from unittest import TestCase # noqa: F401


for i in range(15000):
exec(
f"""
Expand Down
1 change: 1 addition & 0 deletions doc/en/conf.py
Original file line number Diff line number Diff line change
Expand Up @@ -23,6 +23,7 @@

from _pytest import __version__ as version


if TYPE_CHECKING:
import sphinx.application

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,7 @@

import pytest


mydir = os.path.dirname(__file__)


Expand Down
1 change: 1 addition & 0 deletions doc/en/example/assertion/test_failures.py
Original file line number Diff line number Diff line change
@@ -1,6 +1,7 @@
import os.path
import shutil


failure_demo = os.path.join(os.path.dirname(__file__), "failure_demo.py")
pytest_plugins = ("pytester",)

Expand Down
21 changes: 9 additions & 12 deletions doc/en/example/multipython.py
Original file line number Diff line number Diff line change
Expand Up @@ -7,6 +7,7 @@

import pytest


pythonlist = ["python3.9", "python3.10", "python3.11"]


Expand All @@ -32,14 +33,12 @@ def dumps(self, obj):
dumpfile = self.picklefile.with_name("dump.py")
dumpfile.write_text(
textwrap.dedent(
r"""
rf"""
import pickle
f = open({!r}, 'wb')
s = pickle.dump({!r}, f, protocol=2)
f = open({str(self.picklefile)!r}, 'wb')
s = pickle.dump({obj!r}, f, protocol=2)
f.close()
""".format(
str(self.picklefile), obj
)
"""
)
)
subprocess.run((self.pythonpath, str(dumpfile)), check=True)
Expand All @@ -48,17 +47,15 @@ def load_and_is_true(self, expression):
loadfile = self.picklefile.with_name("load.py")
loadfile.write_text(
textwrap.dedent(
r"""
rf"""
import pickle
f = open({!r}, 'rb')
f = open({str(self.picklefile)!r}, 'rb')
obj = pickle.load(f)
f.close()
res = eval({!r})
res = eval({expression!r})
if not res:
raise SystemExit(1)
""".format(
str(self.picklefile), expression
)
"""
)
)
print(loadfile)
Expand Down
1 change: 1 addition & 0 deletions doc/en/example/xfail_demo.py
Original file line number Diff line number Diff line change
@@ -1,5 +1,6 @@
import pytest


xfail = pytest.mark.xfail


Expand Down
1 change: 1 addition & 0 deletions extra/get_issues.py
Original file line number Diff line number Diff line change
Expand Up @@ -3,6 +3,7 @@

import requests


issues_url = "https://api.github.com/repos/pytest-dev/pytest/issues"


Expand Down
52 changes: 52 additions & 0 deletions pyproject.toml
Original file line number Diff line number Diff line change
Expand Up @@ -123,3 +123,55 @@ target-version = ['py38']
[tool.check-wheel-contents]
# W009: Wheel contains multiple toplevel library entries
ignore = "W009"

[tool.ruff]
src = ["src"]
line-length = 88
select = [
"D", # pydocstyle
"E", # pycodestyle
"F", # pyflakes
"I", # isort
"UP", # pyupgrade
"W", # pycodestyle
]
ignore = [
# pycodestyle ignore
# pytest can do weird low-level things, and we usually know
# what we're doing when we use type(..) is ...
"E721", # Do not compare types, use `isinstance()`
# pydocstyle ignore
"D100", # Missing docstring in public module
"D101", # Missing docstring in public class
"D102", # Missing docstring in public method
"D103", # Missing docstring in public function
"D104", # Missing docstring in public package
"D105", # Missing docstring in magic method
"D106", # Missing docstring in public nested class
"D107", # Missing docstring in `__init__`
"D209", # [*] Multi-line docstring closing quotes should be on a separate line
"D205", # 1 blank line required between summary line and description
"D400", # First line should end with a period
"D401", # First line of docstring should be in imperative mood
"D402", # First line should not be the function's signature
"D404", # First word of the docstring should not be "This"
"D415", # First line should end with a period, question mark, or exclamation point
]

[tool.ruff.format]
docstring-code-format = true

[tool.ruff.lint.pycodestyle]
# In order to be able to format for 88 char in ruff format
max-line-length = 120

[tool.ruff.lint.pydocstyle]
convention = "pep257"

[tool.ruff.lint.isort]
Pierre-Sassoulas marked this conversation as resolved.
Show resolved Hide resolved
force-single-line = true
combine-as-imports = true
force-sort-within-sections = true
Pierre-Sassoulas marked this conversation as resolved.
Show resolved Hide resolved
order-by-type = false
known-local-folder = ["pytest", "_pytest"]
lines-after-imports = 2
2 changes: 1 addition & 1 deletion scripts/generate-gh-release-notes.py
Original file line number Diff line number Diff line change
Expand Up @@ -8,9 +8,9 @@

Requires Python3.6+.
"""
from pathlib import Path
import re
import sys
from pathlib import Path
from typing import Sequence

import pypandoc
Expand Down
2 changes: 1 addition & 1 deletion scripts/prepare-release-pr.py
Original file line number Diff line number Diff line change
Expand Up @@ -14,8 +14,8 @@
`pytest bot <pytestbot@gmail.com>` commit author.
"""
import argparse
import re
from pathlib import Path
import re
from subprocess import check_call
from subprocess import check_output
from subprocess import run
Expand Down
2 changes: 1 addition & 1 deletion scripts/towncrier-draft-to-file.py
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
# mypy: disallow-untyped-defs
import sys
from subprocess import call
import sys


def main() -> int:
Expand Down
7 changes: 3 additions & 4 deletions scripts/update-plugin-list.py
Original file line number Diff line number Diff line change
Expand Up @@ -11,13 +11,14 @@

import packaging.version
import platformdirs
import tabulate
import wcwidth
from requests_cache import CachedResponse
from requests_cache import CachedSession
from requests_cache import OriginalResponse
from requests_cache import SQLiteCache
import tabulate
from tqdm import tqdm
import wcwidth


FILE_HEAD = r"""
.. Note this file is autogenerated by scripts/update-plugin-list.py - usually weekly via github action
Expand Down Expand Up @@ -85,7 +86,6 @@ def project_response_with_refresh(

force refresh in case of last serial mismatch
"""

response = session.get(f"https://pypi.org/pypi/{name}/json")
if int(response.headers.get("X-PyPI-Last-Serial", -1)) != last_serial:
response = session.get(f"https://pypi.org/pypi/{name}/json", refresh=True)
Expand Down Expand Up @@ -184,7 +184,6 @@ def version_sort_key(version_string: str) -> Any:

def plugin_definitions(plugins: Iterable[PluginInfo]) -> Iterator[str]:
"""Return RST for the plugin list that fits better on a vertical page."""

for plugin in plugins:
yield dedent(
f"""
Expand Down
2 changes: 1 addition & 1 deletion src/_pytest/_argcomplete.py
Original file line number Diff line number Diff line change
Expand Up @@ -63,9 +63,9 @@
"""

import argparse
from glob import glob
import os
import sys
from glob import glob
from typing import Any
from typing import List
from typing import Optional
Expand Down
1 change: 1 addition & 0 deletions src/_pytest/_code/__init__.py
Original file line number Diff line number Diff line change
Expand Up @@ -10,6 +10,7 @@
from .source import getrawcode
from .source import Source


__all__ = [
"Code",
"ExceptionInfo",
Expand Down
Loading
Loading