summaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
authorCalum Lind <calumlind+deluge@gmail.com>2024-02-19 18:52:47 +0100
committerCalum Lind <calumlind+deluge@gmail.com>2024-09-08 18:46:40 +0200
commit90c5e75373b9bcba1730ea8f8dcb39b3236748d3 (patch)
tree8e7cdcbf3f60616f2fddd4425056642e4f3b1f2d
parent[Console] Block interactive-mode on Windows even with windows-curses (diff)
downloaddeluge-90c5e75373b9bcba1730ea8f8dcb39b3236748d3.tar.xz
deluge-90c5e75373b9bcba1730ea8f8dcb39b3236748d3.zip
[Lint] Replace black/flake8/isort with ruff
Use ruff as a single performant tool to lint and format Python code.
-rw-r--r--.pre-commit-config.yaml28
-rw-r--r--deluge/plugins/Stats/deluge_stats/tests/test_stats.py1
-rw-r--r--pyproject.toml43
-rw-r--r--setup.cfg20
-rw-r--r--tox.ini13
5 files changed, 47 insertions, 58 deletions
diff --git a/.pre-commit-config.yaml b/.pre-commit-config.yaml
index 4d0d922ef..84d82235c 100644
--- a/.pre-commit-config.yaml
+++ b/.pre-commit-config.yaml
@@ -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]
diff --git a/deluge/plugins/Stats/deluge_stats/tests/test_stats.py b/deluge/plugins/Stats/deluge_stats/tests/test_stats.py
index d61cd4666..8af1b739e 100644
--- a/deluge/plugins/Stats/deluge_stats/tests/test_stats.py
+++ b/deluge/plugins/Stats/deluge_stats/tests/test_stats.py
@@ -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
diff --git a/pyproject.toml b/pyproject.toml
index 169561f13..beec7960a 100644
--- a/pyproject.toml
+++ b/pyproject.toml
@@ -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"]
diff --git a/setup.cfg b/setup.cfg
index 9403fb0cb..47c80c29d 100644
--- a/setup.cfg
+++ b/setup.cfg
@@ -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
diff --git a/tox.ini b/tox.ini
index 3756a5406..a896eb7d2 100644
--- a/tox.ini
+++ b/tox.ini
@@ -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