Skip to content

Commit

Permalink
Use ruff (#3033)
Browse files Browse the repository at this point in the history
  • Loading branch information
gaborbernat committed Jun 15, 2023
1 parent b138c5c commit 07658e6
Show file tree
Hide file tree
Showing 178 changed files with 1,750 additions and 1,639 deletions.
14 changes: 7 additions & 7 deletions .github/workflows/check.yml
Original file line number Diff line number Diff line change
Expand Up @@ -18,16 +18,16 @@ jobs:
fail-fast: false
matrix:
py:
- "3.12.0-beta.1"
- "3.12.0-beta.2"
- "3.11"
- "3.10"
- "3.9"
- "3.8"
- "3.7"
os:
- ubuntu-22.04
- windows-2022
- macos-12
- ubuntu-latest
- windows-latest
- macos-latest
steps:
- name: Setup python for tox
uses: actions/setup-python@v4
Expand Down Expand Up @@ -63,10 +63,10 @@ jobs:
- docs
- pkg_meta
os:
- ubuntu-22.04
- windows-2022
- ubuntu-latest
- windows-latest
exclude:
- { os: windows-2022, tox_env: pkg_meta }
- { os: windows-latest, tox_env: pkg_meta }
steps:
- uses: actions/checkout@v3
with:
Expand Down
2 changes: 1 addition & 1 deletion .github/workflows/release.yml
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,7 @@ on:

jobs:
release:
runs-on: ubuntu-22.04
runs-on: ubuntu-latest
environment:
name: release
url: https://pypi.org/p/tox
Expand Down
12 changes: 0 additions & 12 deletions .markdownlint.yaml

This file was deleted.

69 changes: 17 additions & 52 deletions .pre-commit-config.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -2,76 +2,41 @@ repos:
- repo: https://github.com/pre-commit/pre-commit-hooks
rev: v4.4.0
hooks:
- id: check-ast
- id: check-builtin-literals
- id: check-docstring-first
- id: check-merge-conflict
- id: check-yaml
- id: check-toml
- id: debug-statements
- id: end-of-file-fixer
- id: trailing-whitespace
- repo: https://github.com/asottile/add-trailing-comma
rev: v2.4.0
- repo: https://github.com/astral-sh/ruff-pre-commit
rev: "v0.0.272"
hooks:
- id: add-trailing-comma
args: [--py36-plus]
- repo: https://github.com/asottile/pyupgrade
rev: v3.4.0
hooks:
- id: pyupgrade
args: ["--py37-plus"]
exclude: "^(tests/demo_pkg_inline/build.py)$"
- id: pyupgrade
files: "^(tests/demo_pkg_inline/build.py)$"
- repo: https://github.com/PyCQA/isort
rev: 5.12.0
hooks:
- id: isort
- id: ruff
args: [--fix, --exit-non-zero-on-fix]
- repo: https://github.com/psf/black
rev: 23.3.0
hooks:
- id: black
args: [--safe]
- repo: https://github.com/asottile/blacken-docs
rev: 1.13.0
hooks:
- id: blacken-docs
additional_dependencies: [black==23.3]
- repo: https://github.com/pre-commit/pygrep-hooks
rev: v1.10.0
hooks:
- id: rst-backticks
- repo: https://github.com/tox-dev/tox-ini-fmt
rev: "1.3.0"
hooks:
- id: tox-ini-fmt
args: ["-p", "fix"]
- repo: https://github.com/PyCQA/flake8
rev: 6.0.0
- repo: https://github.com/tox-dev/pyproject-fmt
rev: "0.11.2"
hooks:
- id: flake8
additional_dependencies:
- flake8-bugbear==23.5.9
- flake8-comprehensions==3.12
- flake8-pytest-style==1.7.2
- flake8-spellcheck==0.28
- flake8-unused-arguments==0.0.13
- flake8-noqa==1.3.1
- pep8-naming==0.13.3
- flake8-pyproject==1.2.3
- id: pyproject-fmt
additional_dependencies: ["tox>=4.6"]
- repo: https://github.com/pre-commit/mirrors-prettier
rev: "v2.7.1"
rev: "v3.0.0-alpha.9-for-vscode"
hooks:
- id: prettier
additional_dependencies:
- prettier@2.7.1
- "@prettier/plugin-xml@2.2"
args: ["--print-width=120", "--prose-wrap=always"]
- repo: https://github.com/igorshubovych/markdownlint-cli
rev: v0.34.0
- repo: https://github.com/asottile/blacken-docs
rev: 1.13.0
hooks:
- id: markdownlint
- id: blacken-docs
additional_dependencies: [black==23.3]
- repo: https://github.com/pre-commit/pygrep-hooks
rev: v1.10.0
hooks:
- id: rst-backticks
- repo: local
hooks:
- id: changelogs-rst
Expand Down
41 changes: 21 additions & 20 deletions docs/conf.py
Original file line number Diff line number Diff line change
Expand Up @@ -6,22 +6,24 @@
from importlib.machinery import SourceFileLoader
from pathlib import Path
from subprocess import check_output
from typing import Any
from typing import TYPE_CHECKING, Any

from docutils.nodes import Element, reference
from sphinx.addnodes import pending_xref
from sphinx.application import Sphinx
from sphinx.builders import Builder
from sphinx.domains.python import PythonDomain
from sphinx.environment import BuildEnvironment
from sphinx.ext.autodoc import Options
from sphinx.ext.extlinks import ExternalLinksChecker

from tox import __version__

if TYPE_CHECKING:
from docutils.nodes import Element, reference
from sphinx.addnodes import pending_xref
from sphinx.application import Sphinx
from sphinx.builders import Builder
from sphinx.environment import BuildEnvironment
from sphinx.ext.autodoc import Options

company, name = "tox-dev", "tox"
release, version = __version__, ".".join(__version__.split(".")[:2])
copyright = f"{company}"
copyright = f"{company}" # noqa: A001
master_doc, source_suffix = "index", ".rst"

html_theme = "furo"
Expand Down Expand Up @@ -76,14 +78,14 @@
extlinks_detect_hardcoded_links = True


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

class PatchedPythonDomain(PythonDomain):
def resolve_xref(
def resolve_xref( # noqa: PLR0913
self,
env: BuildEnvironment,
fromdocname: str,
builder: Builder,
type: str,
type: str, # noqa: A002
target: str,
node: pending_xref,
contnode: Element,
Expand All @@ -120,17 +122,16 @@ def resolve_xref(
}
if target in mapping:
target = node["reftarget"] = mapping[target]
# node.children[0].children[0] = Text(target, target)
return super().resolve_xref(env, fromdocname, builder, type, target, node, contnode)

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

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

prev_check, ExternalLinksChecker.check_uri = ExternalLinksChecker.check_uri, check_uri
10 changes: 6 additions & 4 deletions docs/tox_conf.py
Original file line number Diff line number Diff line change
@@ -1,16 +1,18 @@
from __future__ import annotations

from typing import cast
from typing import TYPE_CHECKING, cast

from docutils.nodes import Element, Node, Text, container, fully_normalize_name, literal, paragraph, reference, strong
from docutils.parsers.rst.directives import flag, unchanged, unchanged_required
from docutils.parsers.rst.states import RSTState, RSTStateMachine
from docutils.statemachine import StringList, string2lines
from sphinx.domains.std import StandardDomain
from sphinx.locale import __
from sphinx.util.docutils import SphinxDirective
from sphinx.util.logging import getLogger

if TYPE_CHECKING:
from docutils.parsers.rst.states import RSTState, RSTStateMachine

LOGGER = getLogger(__name__)


Expand All @@ -26,7 +28,7 @@ class ToxConfig(SphinxDirective):
"ref_suffix": unchanged,
}

def __init__(
def __init__( # noqa: PLR0913
self,
name: str,
arguments: list[str],
Expand All @@ -37,7 +39,7 @@ def __init__(
block_text: str,
state: RSTState,
state_machine: RSTStateMachine,
):
) -> None:
super().__init__(
name,
arguments,
Expand Down

0 comments on commit 07658e6

Please sign in to comment.