From 39e5135e219d26edc98334a40d9638b88afa4cd9 Mon Sep 17 00:00:00 2001 From: Hugo Osvaldo Barrera Date: Tue, 16 May 2023 12:09:53 +0200 Subject: [PATCH 1/2] Use ruff for linting Use ruff instead of flake8+isort+pyupgrade+pygrep-hooks. This change configures ruff to apply all the same rules that these tools apply. I've omitted E501 for now since there are a few violations. --- .flake8 | 4 ---- .pre-commit-config.yaml | 22 +++++----------------- debug_toolbar/panels/sql/utils.py | 2 +- docs/contributing.rst | 2 +- pyproject.toml | 26 ++++++++++++++++++++++---- requirements_dev.txt | 2 -- 6 files changed, 29 insertions(+), 29 deletions(-) delete mode 100644 .flake8 diff --git a/.flake8 b/.flake8 deleted file mode 100644 index 7d44b7eca..000000000 --- a/.flake8 +++ /dev/null @@ -1,4 +0,0 @@ -# TODO: move this to pyproject.toml when supported, see https://github.com/PyCQA/flake8/issues/234 - -[flake8] -extend-ignore = E203, E501 diff --git a/.pre-commit-config.yaml b/.pre-commit-config.yaml index 124892d78..f28cdd625 100644 --- a/.pre-commit-config.yaml +++ b/.pre-commit-config.yaml @@ -7,35 +7,18 @@ repos: - id: end-of-file-fixer - id: trailing-whitespace - id: mixed-line-ending -- repo: https://github.com/pycqa/flake8 - rev: 6.0.0 - hooks: - - id: flake8 - repo: https://github.com/pycqa/doc8 rev: v1.1.1 hooks: - id: doc8 -- repo: https://github.com/asottile/pyupgrade - rev: v3.4.0 - hooks: - - id: pyupgrade - args: [--py38-plus] - repo: https://github.com/adamchainz/django-upgrade rev: 1.13.0 hooks: - id: django-upgrade args: [--target-version, "3.2"] -- repo: https://github.com/pycqa/isort - rev: 5.12.0 - hooks: - - id: isort - repo: https://github.com/pre-commit/pygrep-hooks rev: v1.10.0 hooks: - - id: python-check-blanket-noqa - - id: python-check-mock-methods - - id: python-no-eval - - id: python-no-log-warn - id: rst-backticks - id: rst-directive-colons - repo: https://github.com/pre-commit/mirrors-prettier @@ -53,6 +36,11 @@ repos: types: [file] args: - --fix +- repo: https://github.com/charliermarsh/ruff-pre-commit + rev: 'v0.0.267' + hooks: + - id: ruff + args: [--fix, --exit-non-zero-on-fix] - repo: https://github.com/psf/black rev: 23.3.0 hooks: diff --git a/debug_toolbar/panels/sql/utils.py b/debug_toolbar/panels/sql/utils.py index efd7c1637..120674c96 100644 --- a/debug_toolbar/panels/sql/utils.py +++ b/debug_toolbar/panels/sql/utils.py @@ -132,7 +132,7 @@ def contrasting_color_generator(): """ def rgb_to_hex(rgb): - return "#%02x%02x%02x" % tuple(rgb) + return "#{:02x}{:02x}{:02x}".format(*tuple(rgb)) triples = [ (1, 0, 0), diff --git a/docs/contributing.rst b/docs/contributing.rst index 079a8b195..5e11ee603 100644 --- a/docs/contributing.rst +++ b/docs/contributing.rst @@ -101,7 +101,7 @@ Style ----- The Django Debug Toolbar uses `black `__ to -format code and additionally uses flake8 and isort. The toolbar uses +format code and additionally uses ruff. The toolbar uses `pre-commit `__ to automatically apply our style guidelines when a commit is made. Set up pre-commit before committing with:: diff --git a/pyproject.toml b/pyproject.toml index d012cbaa3..ff8c22874 100644 --- a/pyproject.toml +++ b/pyproject.toml @@ -49,10 +49,6 @@ packages = ["debug_toolbar"] [tool.hatch.version] path = "debug_toolbar/__init__.py" -[tool.isort] -combine_as_imports = true -profile = "black" - [tool.coverage.html] skip_covered = true skip_empty = true @@ -69,3 +65,25 @@ source = ["src", ".tox/*/site-packages"] # Update coverage badge link in README.rst when fail_under changes fail_under = 94 show_missing = true + +[tool.ruff.isort] +combine-as-imports = true + +[tool.ruff] +select = [ + # flake8/Pyflakes + "F", + # flake8/pycodestyle + "E", + "W", + # isort + "I", + # pyupgrade + "UP", + # pygrep-hooks + "PGH", +] +ignore = [ + "E501", +] +target-version = "py38" diff --git a/requirements_dev.txt b/requirements_dev.txt index ade334aba..4b90beb08 100644 --- a/requirements_dev.txt +++ b/requirements_dev.txt @@ -7,9 +7,7 @@ Jinja2 # Testing coverage[toml] -flake8 html5lib -isort selenium tox black From 52ff5eb9c5a0b20c9dd77cb0ceed8a746a23fffc Mon Sep 17 00:00:00 2001 From: Matthias Kestenholz Date: Mon, 22 May 2023 11:52:14 +0200 Subject: [PATCH 2/2] Mention ruff in the changelog --- .pre-commit-config.yaml | 2 ++ docs/changes.rst | 2 ++ docs/spelling_wordlist.txt | 25 +++++++++++++------------ 3 files changed, 17 insertions(+), 12 deletions(-) diff --git a/.pre-commit-config.yaml b/.pre-commit-config.yaml index f28cdd625..559e3d696 100644 --- a/.pre-commit-config.yaml +++ b/.pre-commit-config.yaml @@ -7,6 +7,8 @@ repos: - id: end-of-file-fixer - id: trailing-whitespace - id: mixed-line-ending + - id: file-contents-sorter + files: docs/spelling_wordlist.txt - repo: https://github.com/pycqa/doc8 rev: v1.1.1 hooks: diff --git a/docs/changes.rst b/docs/changes.rst index 06a0cc744..3ba8b7155 100644 --- a/docs/changes.rst +++ b/docs/changes.rst @@ -5,6 +5,8 @@ Pending ------- * Adjusted app directories system check to allow for nested template loaders. +* Switched from flake8, isort and pyupgrade to `ruff + `__. 4.1.0 (2023-05-15) ------------------ diff --git a/docs/spelling_wordlist.txt b/docs/spelling_wordlist.txt index d5aa73afe..2ab01758c 100644 --- a/docs/spelling_wordlist.txt +++ b/docs/spelling_wordlist.txt @@ -1,3 +1,12 @@ +Hatchling +Hotwire +Jazzband +Makefile +Pympler +Roboto +Transifex +Werkzeug +async backend backends backported @@ -9,17 +18,13 @@ fallbacks flamegraph flatpages frontend -Hatchling -Hotwire htmx inlining isort -Jazzband -jinja jQuery +jinja jrestclient js -Makefile margins memcache memcached @@ -36,22 +41,18 @@ psycopg py pyflame pylibmc -Pympler +pyupgrade querysets refactoring resizing -Roboto spellchecking spooler stacktrace stacktraces startup -timeline theming +timeline tox -Transifex -unhashable uWSGI +unhashable validator -Werkzeug -async