[Lint] Replace black/flake8/isort with ruff

Use ruff as a single performant tool to lint and format Python code.
This commit is contained in:
Calum Lind 2024-02-19 17:52:47 +00:00
parent c88f750108
commit 90c5e75373
No known key found for this signature in database
GPG Key ID: 90597A687B836BA3
5 changed files with 47 additions and 58 deletions

View File

@ -6,11 +6,15 @@ exclude: >
deluge/tests/data/.*svg|
)$
repos:
- repo: https://github.com/psf/black
rev: 23.1.0
- repo: https://github.com/astral-sh/ruff-pre-commit
# Ruff version.
rev: v0.6.4
hooks:
- id: black
name: Fmt Black
- id: ruff
name: Chk Ruff
args: [--fix]
- id: ruff-format
name: Fmt Ruff
- repo: https://github.com/pre-commit/mirrors-prettier
rev: v2.7.1
hooks:
@ -18,23 +22,9 @@ repos:
name: Fmt Prettier
# Workaround to list modified files only.
args: [--list-different]
- repo: https://github.com/pycqa/isort
rev: 5.12.0
hooks:
- id: isort
name: Fmt isort
- repo: https://github.com/pycqa/flake8
rev: 6.0.0
hooks:
- id: flake8
name: Chk Flake8
additional_dependencies:
- pep8-naming==0.12.1
- repo: https://github.com/pre-commit/pre-commit-hooks
rev: v4.4.0
hooks:
- id: double-quote-string-fixer
name: Fix Double-quotes
- id: end-of-file-fixer
name: Fix End-of-files
exclude_types: [javascript, css]
@ -47,5 +37,5 @@ repos:
rev: v3.3.1
hooks:
- id: pyupgrade
args: [--py36-plus]
args: [--py37-plus]
stages: [manual]

View File

@ -64,6 +64,7 @@ class TestStatsPlugin:
Not strictly a unit test, but tests if calls do not fail...
"""
# ruff: noqa: I001
from deluge_stats import graph, gtkui
from deluge.configmanager import ConfigManager

View File

@ -1,12 +1,6 @@
[build-system]
requires = ["setuptools", "wheel"]
[tool.black]
skip-string-normalization = true
[tool.isort]
profile = "black"
[tool.pytest.ini_options]
# Dump tracebacks if a test takes longer than X seconds
faulthandler_timeout = 60
@ -27,3 +21,40 @@ filterwarnings = [
"ignore:Using readBody.*:DeprecationWarning",
"ignore:resume_data is deprecated.*:DeprecationWarning:deluge.core.alertmanager",
]
[tool.ruff]
line-length = 88
builtins = ["_", "_n", "__request__"]
extend-exclude = ["dist", "build"]
target-version = "py37"
[tool.ruff.format]
# Prefer single quotes over double quotes
quote-style = "single"
[tool.ruff.lint]
ignore = [
"N818", # error-suffix-on-exception-name
"E501", # Line-too-long, let formatter resolve it
]
select = [
"A", # flake8-builtins
"E", # pycodestyle
"F", # Pyflakes
"N", # pep8-naming
"W", # pycodestyle
"INT", # flake8-gettext
"I", # isort
]
[tool.ruff.lint.flake8-gettext]
extend-function-names = ["_n"]
[tool.ruff.lint.extend-per-file-ignores]
# E402 import not top of file (gi version check required before import)
"deluge/**/gtkui/*.py" = ["E402"]
"deluge/**/gtkui.py" = ["E402"]
"deluge/plugins/Stats/deluge_stats/graph.py" = ["E402"]
"deluge/ui/gtk3/*.py" = ["E402"]

View File

@ -23,23 +23,3 @@ includes = glib, gio, cairo, pango, pangocairo, atk, gobject, gtk.keysyms,
zope.interface, mako.cache, email.mime, libtorrent, gtkosx_application,
HTMLParser
frameworks = CoreFoundation, Foundation, AppKit
[flake8]
max-line-length = 120
builtins = _,_n,__request__
extend-exclude = dist,build
extend-ignore =
# flake8-builtins: A003 class attribute is shadowing a python builtin
A003,
# E203 whitespace before ':'
E203,
# N818 pep8-naming: error suffix in exception names
N818
per-file-ignores =
# import not top of file (gi checks required before import)
deluge/ui/gtk3/*.py : E402
deluge/**/gtkui.py: E402
deluge/**/gtkui/*.py: E402
deluge/plugins/Stats/deluge_stats/graph.py: E402
[pycodestyle]
max-line-length = 88

13
tox.ini
View File

@ -94,19 +94,6 @@ passenv = HOMEPATH,SSH_AUTH_SOCK
deps = {[baselint]deps}
commands = pre-commit run --all-files
[testenv:flake8]
sitepackages = False
deps = {[baselint]deps}
commands =
flake8 --version
python -c 'import isort; print(isort.__version__)'
flake8 *.py deluge
[testenv:flake8-complexity]
sitepackages = False
deps = {[baselint]deps}
commands = flake8 --exit-zero --max-complexity 15 deluge
[testenv:pylint]
sitepackages = False
ignore_errors = True