Skip to content

Commit

Permalink
Lint Python with ruff replacing bandit, flake8, isort, pyupgrade
Browse files Browse the repository at this point in the history
  • Loading branch information
cclauss committed Jul 11, 2023
1 parent e6e2e96 commit 8ca5c90
Show file tree
Hide file tree
Showing 8 changed files with 95 additions and 40 deletions.
7 changes: 2 additions & 5 deletions .github/workflows/lint_python.yml
Original file line number Diff line number Diff line change
Expand Up @@ -8,18 +8,15 @@ jobs:
- uses: actions/setup-python@v4
with:
python-version: 3.x
- run: pip install --upgrade pip setuptools
- run: pip install --upgrade pip setuptools ruff
- run: pip install -e ".[dev]"
- run: bandit --configfile pyproject.toml --recursive .
- run: black --check .
- run: codespell --ignore-words-list="ro" --skip="*.json,*.lock,./.git"
- run: flake8 .
- run: isort --check-only .
- run: ruff --format=github .
- run: pip install --editable .
- run: mypy --non-interactive .
- run: cp -R django_ckeditor_5 example/blog
- run: cd example
- run: pip install -e ".[dev]"
- run: pytest example/blog
- run: shopt -s globstar && pyupgrade --py37-plus **/*.py
- run: safety check
2 changes: 1 addition & 1 deletion django_ckeditor_5/views.py
Original file line number Diff line number Diff line change
Expand Up @@ -64,7 +64,7 @@ def upload_file(request):
try:
image_verify(request.FILES["upload"])
except NoImageException as ex:
return JsonResponse({"error": {"message": f"{str(ex)}"}})
return JsonResponse({"error": {"message": f"{ex!s}"}})
if form.is_valid():
url = handle_uploaded_file(request.FILES["upload"])
return JsonResponse({"url": url})
Expand Down
2 changes: 1 addition & 1 deletion django_ckeditor_5/widgets.py
Original file line number Diff line number Diff line change
Expand Up @@ -52,7 +52,7 @@ class Media:
js = ["django_ckeditor_5/dist/bundle.js", ]
configs = getattr(settings, "CKEDITOR_5_CONFIGS", None)
if configs is not None:
for config in configs.keys():
for config in configs:
language = configs[config].get('language')
if language:
if isinstance(language, str) and language != "en":
Expand Down
3 changes: 2 additions & 1 deletion example/blog/articles/migrations/0001_initial.py
Original file line number Diff line number Diff line change
@@ -1,7 +1,8 @@
# Generated by Django 4.0.4 on 2022-05-28 14:27

from django.db import migrations, models
import django.db.models.deletion
from django.db import migrations, models

import django_ckeditor_5.fields


Expand Down
1 change: 0 additions & 1 deletion example/blog/blog/settings.py
Original file line number Diff line number Diff line change
Expand Up @@ -13,7 +13,6 @@
import os

# Build paths inside the project like this: os.path.join(BASE_DIR, ...)
import uuid

BASE_DIR = os.path.dirname(os.path.dirname(os.path.abspath(__file__)))

Expand Down
2 changes: 1 addition & 1 deletion example/blog/blog/urls.py
Original file line number Diff line number Diff line change
Expand Up @@ -14,7 +14,7 @@
2. Add a URL to urlpatterns: path('blog/', include('blog.urls'))
"""
from django.conf import settings
from django.conf.urls.static import serve, static
from django.conf.urls.static import serve
from django.contrib import admin
from django.urls import include, path, re_path

Expand Down
2 changes: 1 addition & 1 deletion example/blog/conftest.py
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,7 @@
import pytest


@pytest.fixture
@pytest.fixture()
def file():
file_path = os.path.join(os.path.dirname(__file__), "fixtures", "files", "test.png")
return open(file_path, "rb")
116 changes: 87 additions & 29 deletions pyproject.toml
Original file line number Diff line number Diff line change
Expand Up @@ -44,24 +44,15 @@ repository = "https://github.com/hvlads/django-ckeditor-5"

[project.optional-dependencies]
dev = [
'bandit == 1.7.4',
'black == 22.12.0',
'codespell == 2.2.2',
'coverage == 6.5.0',
'flake8 == 6.0.0',
'flake8-2020 == 1.7.0',
'flake8-bugbear == 22.12.6',
'flake8-comprehensions == 3.10.1',
'Flake8-pyproject == 1.2.2',
'isort == 5.11.3',
'mypy == 0.991',
'mypy-extensions == 0.4.3',
'pylint == 2.15.8',
'pytest == 7.2.0',
'pytest-cov == 4.0.0',
'pytest-django == 4.5.2',
'pytest-mock == 3.10.0',
'pyupgrade == 3.3.1',
'safety == 2.3.5',
'types-setuptools == 65.6.0.2',
'typing_extensions == 4.4.0',
Expand All @@ -70,10 +61,6 @@ dev = [
[tool.setuptools]
packages = ["django_ckeditor_5"]

[tool.bandit]
exclude_dirs = ["example/blog/env", ]
skips = ["B101", "B105", "B308", "B703"]

[tool.black]
exclude = '''
(
Expand All @@ -97,22 +84,6 @@ exclude = '''
)
'''

[tool.flake8]
count = true
exclude = '.git,__pycache__,docs/source/conf.py,old,build,dist,env'
ignore = ['B009', 'E302', 'F401', 'W292', 'W391']
max-complexity = 10
max-line-length = 140
per-file-ignores = [
'__init__.py:F401',
]
show-source = true
statistics = true

[tool.isort]
profile = "black"
skip = ["env", "migrations", "build"]

[tool.mypy]
exclude = [
'example/blog/articles/migrations',
Expand All @@ -122,3 +93,90 @@ exclude = [
]
ignore_missing_imports = true
install_types = true

[tool.ruff]
select = [
"A", # flake8-builtins
"AIR", # Airflow
"ARG", # flake8-unused-arguments
"ASYNC", # flake8-async
"B", # flake8-bugbear
"BLE", # flake8-blind-except
"C4", # flake8-comprehensions
"C90", # McCabe cyclomatic complexity
"CPY", # Copyright-related rules
"DJ", # flake8-django
"DTZ", # flake8-datetimez
"E", # pycodestyle
"ERA", # eradicate
"EXE", # flake8-executable
"F", # Pyflakes
"FA", # flake8-future-annotations
"FBT", # flake8-boolean-trap
"FIX", # flake8-fixme
"FLY", # flynt
"G", # flake8-logging-format
"I", # isort
"ICN", # flake8-import-conventions
"INP", # flake8-no-pep420
"INT", # flake8-gettext
"ISC", # flake8-implicit-str-concat
"N", # pep8-naming
"PERF", # Perflint
"PGH", # pygrep-hooks
"PIE", # flake8-pie
"PL", # Pylint
"PT", # flake8-pytest-style
"PYI", # flake8-pyi
"RET", # flake8-return
"RSE", # flake8-raise
"RUF", # Ruff-specific rules
"S", # flake8-bandit
"SIM", # flake8-simplify
"SLF", # flake8-self
"SLOT", # flake8-slots
"T10", # flake8-debugger
"T20", # flake8-print
"TCH", # flake8-type-checking
"TD", # flake8-todos
"TID", # flake8-tidy-imports
"TRY", # tryceratops
"UP", # pyupgrade
"W", # pycodestyle
"YTT", # flake8-2020
# "ANN", # flake8-annotations
# "COM", # flake8-commas
# "D", # pydocstyle
# "EM", # flake8-errmsg
# "NPY", # NumPy-specific rules
# "PD", # pandas-vet
# "PTH", # flake8-use-pathlib
# "Q", # flake8-quotes
]
ignore = ["RUF012"]
target-version = "py38"
line-length = 112 # Recommended: 88

[tool.ruff.mccabe]
max-complexity = 10 # Recommended: 10

[tool.ruff.pylint]
allow-magic-value-types = ["int", "str"]
max-args = 5 # Recommended: 5
max-branches = 12 # Recommended: 12
max-returns = 6 # Recommended: 6
max-statements = 50 # Recommended: 50

[tool.ruff.per-file-ignores]
"example/blog/articles/migrations/*" = ["E501"]
"django_ckeditor_5/fields.py" = ["PIE800"]
"django_ckeditor_5/views.py" = ["B904", "N818", "RET505", "RUF012", "TRY003", "TRY200"]
"django_ckeditor_5/widgets.py" = ["B009", "S308"]
"example/blog/*" = ["INP001"]
"example/blog/articles/models.py" = ["DJ001"]
"example/blog/articles/views.py" = ["ARG002"]
"example/blog/conftest.py" = ["SIM115"]
"example/blog/manage.py" = ["TRY003"]
"example/blog/blog/settings.py" = ["N816", "S105"]
"example/blog/tests/*" = ["S101"]
"example/blog/tests/test_upload_file.py" = ["ARG001"]

0 comments on commit 8ca5c90

Please sign in to comment.