Skip to content

Commit

Permalink
Adopt Ruff
Browse files Browse the repository at this point in the history
  • Loading branch information
AA-Turner committed Apr 16, 2024
1 parent 781815a commit 48a778c
Show file tree
Hide file tree
Showing 8 changed files with 97 additions and 42 deletions.
3 changes: 0 additions & 3 deletions .flake8

This file was deleted.

37 changes: 4 additions & 33 deletions .pre-commit-config.yaml
Original file line number Diff line number Diff line change
@@ -1,26 +1,9 @@
repos:
- repo: https://github.com/asottile/pyupgrade
rev: v3.15.2
- repo: https://github.com/astral-sh/ruff-pre-commit
rev: v0.3.7
hooks:
- id: pyupgrade
args: [--py39-plus]

- repo: https://github.com/psf/black-pre-commit-mirror
rev: 24.4.0
hooks:
- id: black

- repo: https://github.com/PyCQA/isort
rev: 5.13.2
hooks:
- id: isort
files: \.py$
args: ["--profile", "black"]

- repo: https://github.com/PyCQA/flake8
rev: 7.0.0
hooks:
- id: flake8
- id: ruff
- id: ruff-format

- repo: https://github.com/pre-commit/pre-commit-hooks
rev: v4.6.0
Expand All @@ -34,15 +17,3 @@ repos:
- id: end-of-file-fixer
- id: forbid-new-submodules
- id: trailing-whitespace

- repo: https://github.com/PyCQA/pydocstyle
rev: 6.3.0
hooks:
- id: pydocstyle
files: src/.*\.py$

- repo: https://github.com/asottile/blacken-docs
rev: 1.16.0
hooks:
- id: blacken-docs
additional_dependencies: [black==24.4.0]
84 changes: 84 additions & 0 deletions .ruff.toml
Original file line number Diff line number Diff line change
@@ -0,0 +1,84 @@
target-version = "py39" # Pin Ruff to Python 3.9
line-length = 88
output-format = "full"
extend-exclude = [
"noxfile.py",
]

[lint]
preview = true
ignore = [
"D100",
"D101",
"D102",
"D103",
"D105",
"D107",
"E203",
# "W503", # unimplemented in Ruff (as of 2024-04-16)
]
select = [
# flake8-builtins ('A')
"A",
# flake8-unused-arguments ('ARG')
"ARG",
# flake8-async ('ASYNC')
"ASYNC",
# flake8-bugbear ('B')
"B",
# flake8-comprehensions ('C4')
"C4",
# mccabe ('C90')
"C901",
# pydocstyle ('D')
"D",
# pycodestyle ('E')
"E",
# pyflakes ('F')
"F",
# isort ('I')
"I",
# pep8-naming ('N')
"N",
# perflint ('PERF')
"PERF",
# pygrep-hooks ('PGH')
"PGH",
# flake8-pytest-style ('PT')
"PT",
# flake8-quotes ('Q')
"Q",
# flake8-return ('RET')
"RET",
# flake8-raise ('RSE')
"RSE",
# flake8-simplify ('SIM')
"SIM",
# pyupgrade ('UP')
"UP",
# pycodestyle ('W')
"W",
]

[lint.pydocstyle]
convention = "pep257"

[lint.per-file-ignores]
"tests/*" = [
"E501",
"S101", # whitelist ``assert`` for tests
"T201", # whitelist ``print`` for tests
]

[lint.flake8-quotes]
inline-quotes = "double"

[lint.isort]
forced-separate = [
"tests",
]

[format]
preview = true
quote-style = "double"
docstring-code-format = true
1 change: 0 additions & 1 deletion sphinx_autobuild/__main__.py
Original file line number Diff line number Diff line change
Expand Up @@ -123,7 +123,6 @@ def _get_sphinx_build_parser():

def _get_parser():
"""Get the application's argument parser."""

parser = argparse.ArgumentParser(allow_abbrev=False)
parser.add_argument(
"--version", action="version", version=f"sphinx-autobuild {__version__}"
Expand Down
1 change: 0 additions & 1 deletion sphinx_autobuild/build.py
Original file line number Diff line number Diff line change
Expand Up @@ -16,7 +16,6 @@ def __init__(self, sphinx_args, *, url_host, pre_build_commands):

def __call__(self, *, rebuild: bool = True):
"""Generate the documentation using ``sphinx``."""

if rebuild:
show(context="Detected change. Rebuilding...")

Expand Down
2 changes: 1 addition & 1 deletion sphinx_autobuild/filter.py
Original file line number Diff line number Diff line change
Expand Up @@ -27,7 +27,7 @@ def __call__(self, path):
return True

# Any regular expression matches.
for regex in self.regex_based_patterns:
for regex in self.regex_based_patterns: # NoQA: SIM110
if regex.search(path):
return True

Expand Down
6 changes: 5 additions & 1 deletion sphinx_autobuild/middleware.py
Original file line number Diff line number Diff line change
@@ -1,7 +1,11 @@
from __future__ import annotations

from typing import TYPE_CHECKING

from starlette.datastructures import MutableHeaders
from starlette.types import ASGIApp, Message, Receive, Scope, Send

if TYPE_CHECKING:
from starlette.types import ASGIApp, Message, Receive, Scope, Send


def web_socket_script(ws_url: str) -> str:
Expand Down
5 changes: 3 additions & 2 deletions sphinx_autobuild/server.py
Original file line number Diff line number Diff line change
Expand Up @@ -4,15 +4,16 @@
import os
from concurrent.futures import ProcessPoolExecutor
from contextlib import AbstractAsyncContextManager, asynccontextmanager
from typing import TYPE_CHECKING

import watchfiles
from starlette.types import Receive, Scope, Send
from starlette.websockets import WebSocket

TYPE_CHECKING = False
if TYPE_CHECKING:
from collections.abc import Callable

from starlette.types import Receive, Scope, Send

from sphinx_autobuild.filter import IgnoreFilter


Expand Down

0 comments on commit 48a778c

Please sign in to comment.