From d7afc859d8e939b292ca4a3f58626db75ab7868c Mon Sep 17 00:00:00 2001 From: Igor Date: Thu, 16 Nov 2023 15:04:30 +0000 Subject: [PATCH] WIP Switch from flake8 to ruff --- .github/workflows/lint.yml | 4 ++-- Makefile | 9 +++++++-- README.rst | 1 + pyproject.toml | 24 ++++++++++++++++++++++++ requirements-lint.txt | 7 +------ setup.cfg | 5 ----- setup.py | 2 +- tox.ini | 2 +- 8 files changed, 37 insertions(+), 17 deletions(-) diff --git a/.github/workflows/lint.yml b/.github/workflows/lint.yml index 32f9282..1b9c235 100644 --- a/.github/workflows/lint.yml +++ b/.github/workflows/lint.yml @@ -15,5 +15,5 @@ jobs: run: pip install -U setuptools pip wheel - name: Install linting requirements run: pip install -r requirements-lint.txt - - name: Lint code - run: flake8 --verbose + - name: Check code style + run: ruff check . diff --git a/Makefile b/Makefile index 5e22e75..c15f6ac 100644 --- a/Makefile +++ b/Makefile @@ -1,4 +1,4 @@ -.PHONY: help init clean test test-all coverage lint release +.PHONY: help init clean test test-all coverage lint format release help: @echo "Using make is entirely optional; these are simply shortcuts" @@ -10,6 +10,7 @@ help: @echo "test-all - run all tests in all supported python environments" @echo "coverage - check code coverage while running all tests using current python environment" @echo "lint - check code style" + @echo "format - fix code style" @echo "release - NOT NORMALLY USED; See README.rst for release process" init: @@ -39,7 +40,11 @@ coverage: lint: pip install -r requirements-lint.txt - flake8 --verbose + ruff check . + +format: + pip install -r requirements-lint.txt + ruff format . release: clean pip install -r requirements-release.txt diff --git a/README.rst b/README.rst index 7dd2851..cd41ed5 100644 --- a/README.rst +++ b/README.rst @@ -50,6 +50,7 @@ History Unreleased Migrated test, build and release processes away from deprecated setuptools commands. + Switched to `ruff `_ for code linting and formatting. No significant library changes. 0.8 diff --git a/pyproject.toml b/pyproject.toml index fed528d..27fbc25 100644 --- a/pyproject.toml +++ b/pyproject.toml @@ -1,3 +1,27 @@ [build-system] requires = ["setuptools"] build-backend = "setuptools.build_meta" + +[tool.ruff] +exclude = [".git/", ".eggs/", ".tox/", "build/", "dist/", "env/", "venv/"] +indent-width = 4 +line-length = 120 + +[tool.ruff.format] +indent-style = "space" +line-ending = "lf" +quote-style = "single" +skip-magic-trailing-comma = false + +[tool.ruff.lint] +preview = true +select = ["B", "BLE", "C", "E", "F", "I", "PL", "PYI", "Q", "RUF", "S", "SIM", "T", "TCH", "TID", "UP", "W", "YTT"] + +[tool.ruff.lint.flake8-quotes] +inline-quotes = "single" + +[tool.ruff.lint.mccabe] +max-complexity = 10 + +[tool.ruff.lint.pylint] +max-args = 7 diff --git a/requirements-lint.txt b/requirements-lint.txt index 68de36f..af3ee57 100644 --- a/requirements-lint.txt +++ b/requirements-lint.txt @@ -1,6 +1 @@ -flake8 -flake8-blind-except -flake8-bugbear -flake8-debugger -flake8-quotes -pep8-naming +ruff diff --git a/setup.cfg b/setup.cfg index 16730c8..d87048e 100644 --- a/setup.cfg +++ b/setup.cfg @@ -44,11 +44,6 @@ install_requires = Django>=2.2,<4.3 requests -[flake8] -exclude = .git/,.eggs/,.tox/,build/,dist/,env/,venv/ -max-complexity = 10 -max-line-length = 120 - [coverage:run] omit = setup.py diff --git a/setup.py b/setup.py index d0a11e5..6943ee4 100755 --- a/setup.py +++ b/setup.py @@ -4,7 +4,7 @@ from setuptools import setup -if sys.version_info[0:2] < (3, 8): +if sys.version_info[0:2] < (3, 8): # noqa: UP036 warnings.warn('This package is only tested on Python version 3.8+', stacklevel=1) setup() diff --git a/tox.ini b/tox.ini index 7e1178b..b5148ce 100644 --- a/tox.ini +++ b/tox.ini @@ -26,4 +26,4 @@ commands = python -m tests [testenv:lint] description = lint code deps = -r requirements-lint.txt -commands = flake8 --verbose +commands = ruff check .