Skip to content

Commit 07658e6

Browse files
authored
Use ruff (#3033)
1 parent b138c5c commit 07658e6

File tree

178 files changed

+1750
-1639
lines changed

Some content is hidden

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

178 files changed

+1750
-1639
lines changed

.github/workflows/check.yml

+7-7
Original file line numberDiff line numberDiff line change
@@ -18,16 +18,16 @@ jobs:
1818
fail-fast: false
1919
matrix:
2020
py:
21-
- "3.12.0-beta.1"
21+
- "3.12.0-beta.2"
2222
- "3.11"
2323
- "3.10"
2424
- "3.9"
2525
- "3.8"
2626
- "3.7"
2727
os:
28-
- ubuntu-22.04
29-
- windows-2022
30-
- macos-12
28+
- ubuntu-latest
29+
- windows-latest
30+
- macos-latest
3131
steps:
3232
- name: Setup python for tox
3333
uses: actions/setup-python@v4
@@ -63,10 +63,10 @@ jobs:
6363
- docs
6464
- pkg_meta
6565
os:
66-
- ubuntu-22.04
67-
- windows-2022
66+
- ubuntu-latest
67+
- windows-latest
6868
exclude:
69-
- { os: windows-2022, tox_env: pkg_meta }
69+
- { os: windows-latest, tox_env: pkg_meta }
7070
steps:
7171
- uses: actions/checkout@v3
7272
with:

.github/workflows/release.yml

+1-1
Original file line numberDiff line numberDiff line change
@@ -5,7 +5,7 @@ on:
55

66
jobs:
77
release:
8-
runs-on: ubuntu-22.04
8+
runs-on: ubuntu-latest
99
environment:
1010
name: release
1111
url: https://pypi.org/p/tox

.markdownlint.yaml

-12
This file was deleted.

.pre-commit-config.yaml

+17-52
Original file line numberDiff line numberDiff line change
@@ -2,76 +2,41 @@ repos:
22
- repo: https://github.com/pre-commit/pre-commit-hooks
33
rev: v4.4.0
44
hooks:
5-
- id: check-ast
6-
- id: check-builtin-literals
7-
- id: check-docstring-first
8-
- id: check-merge-conflict
9-
- id: check-yaml
10-
- id: check-toml
11-
- id: debug-statements
125
- id: end-of-file-fixer
136
- id: trailing-whitespace
14-
- repo: https://github.com/asottile/add-trailing-comma
15-
rev: v2.4.0
7+
- repo: https://github.com/astral-sh/ruff-pre-commit
8+
rev: "v0.0.272"
169
hooks:
17-
- id: add-trailing-comma
18-
args: [--py36-plus]
19-
- repo: https://github.com/asottile/pyupgrade
20-
rev: v3.4.0
21-
hooks:
22-
- id: pyupgrade
23-
args: ["--py37-plus"]
24-
exclude: "^(tests/demo_pkg_inline/build.py)$"
25-
- id: pyupgrade
26-
files: "^(tests/demo_pkg_inline/build.py)$"
27-
- repo: https://github.com/PyCQA/isort
28-
rev: 5.12.0
29-
hooks:
30-
- id: isort
10+
- id: ruff
11+
args: [--fix, --exit-non-zero-on-fix]
3112
- repo: https://github.com/psf/black
3213
rev: 23.3.0
3314
hooks:
3415
- id: black
35-
args: [--safe]
36-
- repo: https://github.com/asottile/blacken-docs
37-
rev: 1.13.0
38-
hooks:
39-
- id: blacken-docs
40-
additional_dependencies: [black==23.3]
41-
- repo: https://github.com/pre-commit/pygrep-hooks
42-
rev: v1.10.0
43-
hooks:
44-
- id: rst-backticks
4516
- repo: https://github.com/tox-dev/tox-ini-fmt
4617
rev: "1.3.0"
4718
hooks:
4819
- id: tox-ini-fmt
4920
args: ["-p", "fix"]
50-
- repo: https://github.com/PyCQA/flake8
51-
rev: 6.0.0
21+
- repo: https://github.com/tox-dev/pyproject-fmt
22+
rev: "0.11.2"
5223
hooks:
53-
- id: flake8
54-
additional_dependencies:
55-
- flake8-bugbear==23.5.9
56-
- flake8-comprehensions==3.12
57-
- flake8-pytest-style==1.7.2
58-
- flake8-spellcheck==0.28
59-
- flake8-unused-arguments==0.0.13
60-
- flake8-noqa==1.3.1
61-
- pep8-naming==0.13.3
62-
- flake8-pyproject==1.2.3
24+
- id: pyproject-fmt
25+
additional_dependencies: ["tox>=4.6"]
6326
- repo: https://github.com/pre-commit/mirrors-prettier
64-
rev: "v2.7.1"
27+
rev: "v3.0.0-alpha.9-for-vscode"
6528
hooks:
6629
- id: prettier
67-
additional_dependencies:
68-
69-
- "@prettier/[email protected]"
7030
args: ["--print-width=120", "--prose-wrap=always"]
71-
- repo: https://github.com/igorshubovych/markdownlint-cli
72-
rev: v0.34.0
31+
- repo: https://github.com/asottile/blacken-docs
32+
rev: 1.13.0
7333
hooks:
74-
- id: markdownlint
34+
- id: blacken-docs
35+
additional_dependencies: [black==23.3]
36+
- repo: https://github.com/pre-commit/pygrep-hooks
37+
rev: v1.10.0
38+
hooks:
39+
- id: rst-backticks
7540
- repo: local
7641
hooks:
7742
- id: changelogs-rst

docs/conf.py

+21-20
Original file line numberDiff line numberDiff line change
@@ -6,22 +6,24 @@
66
from importlib.machinery import SourceFileLoader
77
from pathlib import Path
88
from subprocess import check_output
9-
from typing import Any
9+
from typing import TYPE_CHECKING, Any
1010

11-
from docutils.nodes import Element, reference
12-
from sphinx.addnodes import pending_xref
13-
from sphinx.application import Sphinx
14-
from sphinx.builders import Builder
1511
from sphinx.domains.python import PythonDomain
16-
from sphinx.environment import BuildEnvironment
17-
from sphinx.ext.autodoc import Options
1812
from sphinx.ext.extlinks import ExternalLinksChecker
1913

2014
from tox import __version__
2115

16+
if TYPE_CHECKING:
17+
from docutils.nodes import Element, reference
18+
from sphinx.addnodes import pending_xref
19+
from sphinx.application import Sphinx
20+
from sphinx.builders import Builder
21+
from sphinx.environment import BuildEnvironment
22+
from sphinx.ext.autodoc import Options
23+
2224
company, name = "tox-dev", "tox"
2325
release, version = __version__, ".".join(__version__.split(".")[:2])
24-
copyright = f"{company}"
26+
copyright = f"{company}" # noqa: A001
2527
master_doc, source_suffix = "index", ".rst"
2628

2729
html_theme = "furo"
@@ -76,14 +78,14 @@
7678
extlinks_detect_hardcoded_links = True
7779

7880

79-
def process_signature(
80-
app: Sphinx, # noqa: U100
81+
def process_signature( # noqa: PLR0913
82+
app: Sphinx, # noqa: ARG001
8183
objtype: str,
82-
name: str, # noqa: U100
83-
obj: Any, # noqa: U100
84+
name: str, # noqa: ARG001
85+
obj: Any, # noqa: ARG001
8486
options: Options,
85-
args: str, # noqa: U100
86-
retann: str | None, # noqa: U100
87+
args: str, # noqa: ARG001
88+
retann: str | None, # noqa: ARG001
8789
) -> None | tuple[None, None]:
8890
# skip-member is not checked for class level docs, so disable via signature processing
8991
return (None, None) if objtype == "class" and "__init__" in options.get("exclude-members", set()) else None
@@ -95,16 +97,16 @@ def setup(app: Sphinx) -> None:
9597
root, exe = here.parent, Path(sys.executable)
9698
towncrier = exe.with_name(f"towncrier{exe.suffix}")
9799
cmd = [str(towncrier), "build", "--draft", "--version", "NEXT"]
98-
new = check_output(cmd, cwd=root, text=True, stderr=subprocess.DEVNULL)
100+
new = check_output(cmd, cwd=root, text=True, stderr=subprocess.DEVNULL) # noqa: S603
99101
(root / "docs" / "_draft.rst").write_text("" if "No significant changes" in new else new)
100102

101103
class PatchedPythonDomain(PythonDomain):
102-
def resolve_xref(
104+
def resolve_xref( # noqa: PLR0913
103105
self,
104106
env: BuildEnvironment,
105107
fromdocname: str,
106108
builder: Builder,
107-
type: str,
109+
type: str, # noqa: A002
108110
target: str,
109111
node: pending_xref,
110112
contnode: Element,
@@ -120,17 +122,16 @@ def resolve_xref(
120122
}
121123
if target in mapping:
122124
target = node["reftarget"] = mapping[target]
123-
# node.children[0].children[0] = Text(target, target)
124125
return super().resolve_xref(env, fromdocname, builder, type, target, node, contnode)
125126

126127
app.connect("autodoc-process-signature", process_signature, priority=400)
127128
app.add_domain(PatchedPythonDomain, override=True)
128129
tox_cfg = SourceFileLoader("tox_conf", str(here / "tox_conf.py")).load_module().ToxConfig
129130
app.add_directive(tox_cfg.name, tox_cfg)
130131

131-
def check_uri(self, refnode: reference) -> None:
132+
def check_uri(self: ExternalLinksChecker, refnode: reference) -> None: #
132133
if refnode.document.attributes["source"].endswith("index.rst"):
133-
return # do not use for the index file
134+
return None # do not use for the index file
134135
return prev_check(self, refnode)
135136

136137
prev_check, ExternalLinksChecker.check_uri = ExternalLinksChecker.check_uri, check_uri

docs/tox_conf.py

+6-4
Original file line numberDiff line numberDiff line change
@@ -1,16 +1,18 @@
11
from __future__ import annotations
22

3-
from typing import cast
3+
from typing import TYPE_CHECKING, cast
44

55
from docutils.nodes import Element, Node, Text, container, fully_normalize_name, literal, paragraph, reference, strong
66
from docutils.parsers.rst.directives import flag, unchanged, unchanged_required
7-
from docutils.parsers.rst.states import RSTState, RSTStateMachine
87
from docutils.statemachine import StringList, string2lines
98
from sphinx.domains.std import StandardDomain
109
from sphinx.locale import __
1110
from sphinx.util.docutils import SphinxDirective
1211
from sphinx.util.logging import getLogger
1312

13+
if TYPE_CHECKING:
14+
from docutils.parsers.rst.states import RSTState, RSTStateMachine
15+
1416
LOGGER = getLogger(__name__)
1517

1618

@@ -26,7 +28,7 @@ class ToxConfig(SphinxDirective):
2628
"ref_suffix": unchanged,
2729
}
2830

29-
def __init__(
31+
def __init__( # noqa: PLR0913
3032
self,
3133
name: str,
3234
arguments: list[str],
@@ -37,7 +39,7 @@ def __init__(
3739
block_text: str,
3840
state: RSTState,
3941
state_machine: RSTStateMachine,
40-
):
42+
) -> None:
4143
super().__init__(
4244
name,
4345
arguments,

0 commit comments

Comments
 (0)