From f9ff61b258f7175a21db02f3da710dd469483ff4 Mon Sep 17 00:00:00 2001 From: Tuomas Haapala Date: Wed, 16 Oct 2024 17:31:35 +0300 Subject: [PATCH] chore: replace Black, Flake8 and isort with Ruff --- .github/workflows/ci.yml | 19 +++++++----------- .pre-commit-config.yaml | 21 +++++++------------- pyproject.toml | 34 +++++++++++++++++++++++--------- requirements-dev.in | 7 ++----- requirements-dev.txt | 42 ++++------------------------------------ setup.cfg | 9 --------- 6 files changed, 45 insertions(+), 87 deletions(-) delete mode 100644 setup.cfg diff --git a/.github/workflows/ci.yml b/.github/workflows/ci.yml index 50375527b..6b9d8c8e1 100644 --- a/.github/workflows/ci.yml +++ b/.github/workflows/ci.yml @@ -86,21 +86,16 @@ jobs: run: | python manage.py spectacular --lang en --validate --fail-on-warn --api-version v1 - - name: Check black - run: | - black --check . - - - name: Check flake8 - uses: liskin/gh-problem-matcher-wrap@v2 + - name: Run Ruff lint + uses: astral-sh/ruff-action@v1 with: - linters: flake8 - run: flake8 + version: 0.7.1 - - name: Check isort - uses: liskin/gh-problem-matcher-wrap@v2 + - name: Run Ruff format check + uses: astral-sh/ruff-action@v1 with: - linters: isort - run: isort . --check-only --diff + version: 0.7.1 + args: "format --check" - name: Check commitlint uses: wagoid/commitlint-github-action@0d749a1a91d4770e983a7b8f83d4a3f0e7e0874e # v5.4.4 diff --git a/.pre-commit-config.yaml b/.pre-commit-config.yaml index a3ce1968e..dee65eea7 100644 --- a/.pre-commit-config.yaml +++ b/.pre-commit-config.yaml @@ -12,21 +12,14 @@ repos: - id: check-yaml - id: check-toml - id: check-added-large-files - - repo: https://github.com/psf/black - rev: 24.8.0 + - repo: https://github.com/astral-sh/ruff-pre-commit + rev: v0.7.1 hooks: - - id: black - - repo: https://github.com/pycqa/flake8 - rev: 7.1.1 - hooks: - - id: flake8 - additional_dependencies: [pep8-naming, flake8-bugbear] - exclude: "migrations|tests" - - repo: https://github.com/pycqa/isort - rev: 5.13.2 - hooks: - - id: isort - exclude: "migrations" + - id: ruff + name: ruff lint + - id: ruff-format + name: ruff format + args: [ --check ] - repo: https://github.com/alessandrojcm/commitlint-pre-commit-hook rev: v9.18.0 hooks: diff --git a/pyproject.toml b/pyproject.toml index 03c9bbe9e..638b855c2 100644 --- a/pyproject.toml +++ b/pyproject.toml @@ -1,10 +1,26 @@ -[tool.black] -line-length = 88 # Black's default value -target-version = ["py39"] +[tool.ruff] +target-version = "py39" -[tool.isort] -profile = "black" -py_version = 39 -atomic = true -order_by_type = false -extend_skip_glob = ["*migrations*"] +[tool.ruff.lint] +select = [ + # Pyflakes + "F", + # pycodestyle + "E", + "W", + # isort + "I", + # pep8-naming + "N", + # flake8-bugbear without opinionated rules + "B0", + # flake8-pie + "PIE", + # flake8-print + "T20", +] +extend-per-file-ignores = { "*/migrations/*" = ["E501"], "*/tests/*" = ["E501"] } + +[tool.pytest.ini_options] +DJANGO_SETTINGS_MODULE = "linkedevents.test_settings" +norecursedirs = [".git", "venv"] diff --git a/requirements-dev.in b/requirements-dev.in index 4e4c78383..d9415272d 100644 --- a/requirements-dev.in +++ b/requirements-dev.in @@ -1,16 +1,11 @@ -c requirements.txt Werkzeug -black django-anymail django-debug-toolbar django-extensions factory_boy -flake8 -flake8-bugbear freezegun -isort -pep8-naming pip-tools pytest pytest-cov @@ -19,4 +14,6 @@ pytest-factoryboy pytest-freezer python-jose requests-mock +# Keep this in sync with .pre-commit-config.yaml +ruff==0.7.1 snakemd diff --git a/requirements-dev.txt b/requirements-dev.txt index 90ad109d4..c48972781 100644 --- a/requirements-dev.txt +++ b/requirements-dev.txt @@ -8,12 +8,6 @@ asgiref==3.8.1 # via # -c requirements.txt # django -attrs==24.2.0 - # via - # -c requirements.txt - # flake8-bugbear -black==24.8.0 - # via -r requirements-dev.in build==1.2.2 # via pip-tools certifi==2024.8.30 @@ -25,9 +19,7 @@ charset-normalizer==3.3.2 # -c requirements.txt # requests click==8.1.7 - # via - # black - # pip-tools + # via pip-tools coverage[toml]==7.6.1 # via pytest-cov django==4.2.16 @@ -56,13 +48,6 @@ factory-boy==3.3.1 # pytest-factoryboy faker==29.0.0 # via factory-boy -flake8==7.1.1 - # via - # -r requirements-dev.in - # flake8-bugbear - # pep8-naming -flake8-bugbear==24.8.19 - # via -r requirements-dev.in freezegun==1.5.1 # via # -r requirements-dev.in @@ -81,33 +66,18 @@ inflection==0.5.1 # pytest-factoryboy iniconfig==2.0.0 # via pytest -isort==5.13.2 - # via -r requirements-dev.in markupsafe==2.1.5 # via # -c requirements.txt # werkzeug -mccabe==0.7.0 - # via flake8 -mypy-extensions==1.0.0 - # via black packaging==24.1 # via # -c requirements.txt - # black # build # pytest # pytest-factoryboy -pathspec==0.12.1 - # via black -pep8-naming==0.14.1 - # via -r requirements-dev.in pip-tools==7.4.1 # via -r requirements-dev.in -platformdirs==4.3.6 - # via - # -c requirements.txt - # black pluggy==1.5.0 # via pytest pyasn1==0.6.1 @@ -115,10 +85,6 @@ pyasn1==0.6.1 # -c requirements.txt # python-jose # rsa -pycodestyle==2.12.1 - # via flake8 -pyflakes==3.2.0 - # via flake8 pyproject-hooks==1.1.0 # via # build @@ -158,6 +124,8 @@ rsa==4.9 # via # -c requirements.txt # python-jose +ruff==0.7.1 + # via -r requirements-dev.in six==1.16.0 # via # -c requirements.txt @@ -170,9 +138,8 @@ sqlparse==0.5.1 # -c requirements.txt # django # django-debug-toolbar -tomli==2.0.1 +tomli==2.0.2 # via - # black # build # coverage # pip-tools @@ -181,7 +148,6 @@ typing-extensions==4.12.2 # via # -c requirements.txt # asgiref - # black # pytest-factoryboy urllib3==1.26.20 # via diff --git a/setup.cfg b/setup.cfg deleted file mode 100644 index 118ffe2f6..000000000 --- a/setup.cfg +++ /dev/null @@ -1,9 +0,0 @@ -[flake8] -exclude = migrations,tests -max-line-length = 120 -max-complexity = 23 -extend-ignore = E203 - -[tool:pytest] -DJANGO_SETTINGS_MODULE = linkedevents.test_settings -norecursedirs = .git venv