Skip to content

Commit

Permalink
ruff
Browse files Browse the repository at this point in the history
  • Loading branch information
domdinicola committed Jan 7, 2025
1 parent 87e4fa1 commit 2354fd0
Show file tree
Hide file tree
Showing 18 changed files with 172 additions and 207 deletions.
13 changes: 8 additions & 5 deletions .github/workflows/lint.yml
Original file line number Diff line number Diff line change
Expand Up @@ -29,10 +29,10 @@ jobs:
lint: ${{steps.changes.outputs.lint }}
steps:
- name: Checkout code
uses: actions/checkout@v4.1.7
uses: actions/checkout@v4
- id: changes
name: Check for file changes
uses: dorny/paths-filter@0bc4621a3135347011ad047f9ecf449bf72ce2bd # v3.0.0
uses: dorny/paths-filter@v3
with:
base: ${{ github.ref }}
token: ${{ github.token }}
Expand All @@ -47,16 +47,19 @@ jobs:
if: needs.changes.outputs.lint
steps:
- name: Checkout code
uses: actions/checkout@v4.1.7
uses: actions/checkout@v4

- name: Set up Python
uses: actions/setup-python@v5
with:
python-version: 3.12
architecture: 'x64'
- uses: yezz123/setup-uv@v4
with:
version: "latest"
- name: lint
if: needs.changes.outputs.lint
run: |
uv run isort src/ --check-only
uv run flake8 src/
pip install ruff
ruff check -e
ruff format --check
8 changes: 4 additions & 4 deletions .github/workflows/test.yml
Original file line number Diff line number Diff line change
Expand Up @@ -30,10 +30,10 @@ jobs:
lint: ${{steps.changes.outputs.lint }}
steps:
- name: Checkout code
uses: actions/checkout@v4.1.7
uses: actions/checkout@v4
- id: changes
name: Check for file changes
uses: dorny/paths-filter@0bc4621a3135347011ad047f9ecf449bf72ce2bd # v3.0.0
uses: dorny/paths-filter@v3
with:
base: ${{ github.ref }}
token: ${{ github.token }}
Expand Down Expand Up @@ -74,7 +74,7 @@ jobs:
DB_PASSWORD: "postgres"
steps:
- name: Checkout code
uses: actions/checkout@v4.1.7
uses: actions/checkout@v4
- name: Set up Python ${{ matrix.python-version }}
uses: actions/setup-python@v5
with:
Expand Down Expand Up @@ -119,7 +119,7 @@ jobs:
if: ${{ always() }}

- name: Upload coverage to Codecov
uses: codecov/codecov-action@v4
uses: codecov/codecov-action@v5
if: matrix.python-version == 3.12
continue-on-error: true
with:
Expand Down
81 changes: 81 additions & 0 deletions ruff.toml
Original file line number Diff line number Diff line change
@@ -0,0 +1,81 @@
target-version = "py313"
line-length = 120

[lint.isort]
case-sensitive = true

[lint]
select = [
"A", # prevent using keywords that clobber python builtins
# "ANN", # flake8 annotations
"B", # bugbear: security warnings
"BLE", # blind exceptions
"C4", # flake8-comprehensions
"C90", # McCabe complexity
"COM", # flake8-commas
"D", # pydocstyle
"DJ", # flake8-django
"E", # pycodestylex
"E4", "E7", "E9",
"ERA", # eradicate
"F", # pyflakes
"FLY", # flynt
"FURB", # refurb
"I", # isort
"ICN", # flake8-import-conventions
"ISC", # implicit string concatenation
"N", # Pep* naming
"PERF", # perflint
"PIE", # flake8-pie
"PL", # PyLint
# "PT", # flake8-pytest-style
"Q", # flake8-quotes
"R", # PyLint Refactor
"RET", # flake8-return
"S", # bandit,
"SIM", # flake8-simplify
"T10", # flake8-debugger
"T20", # flake8-print
"TC", # flake8-type-checking
"UP", # pyupgrade
"W", # pycodestyle warnings
"YTT", # flake8 2020
]
extend-select = ["UP", ]
ignore = [
"ANN401",
"B904", # raise-without-from-inside-except: syntax not compatible with py2
"COM812",
"D100", # Missing docstring in public module
"D101", # Missing docstring in public class
"D102", # Missing docstring in public method
"D103", # Missing docstring in public function
"D104", # Missing docstring in public package
"D105", # Missing docstring in magic method
"D106", # Missing docstring in public nested class
"D107", # Missing docstring in `__init__`
"D203", # one-blank-line-before-class
# "D212", # multi-line-summary-first-line
"D213", # multi-line-summary-second-line
"E731", # lambda-assignment: lambdas are substential in maintenance of py2/3 codebase
"ISC001", # conflicts with ruff format command
"RUF005", # collection-literal-concatenation: syntax not compatible with py2
"RUF012", # mutable-class-default: typing is not available for py2
"I001", # unsorted imports https://docs.astral.sh/ruff/rules/unsorted-imports/#unsorted-imports-i001
"UP037", # [*] Remove quotes from type annotation
"UP035", # Import from `collections.abc` instead: `Sequence`
"UP031", # Use format specifiers instead of percent format
"SIM108", # Use ternary operator instead of...
"PLR2004", # Magic value used in comparison
"DJ001", # Avoid using `null=True` on string-based fields such as `CharField`
]

[format]
quote-style = "double"
indent-style = "space"
skip-magic-trailing-comma = false
line-ending = "auto"

[lint.per-file-ignores]
"tests/**.py" = ["S101", "PLR2004", "S", "SIM117", "D", "UP", "PLR0913", "ANN", "N999"]
"src/**/versioning/**.py" = ["N999", ]
22 changes: 11 additions & 11 deletions src/django_celery_boost/admin.py
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
from typing import Any, Optional, Sequence
from typing import Any, Sequence

from admin_extra_buttons.decorators import button
from admin_extra_buttons.mixins import ExtraButtonsMixin, confirm_action
Expand All @@ -19,7 +19,7 @@ class CeleryTaskModelAdmin(ExtraButtonsMixin, admin.ModelAdmin):
inspect_template = None
queue_template = None

def get_readonly_fields(self, request: HttpRequest, obj: "Optional[Model]" = None) -> Sequence[str]:
def get_readonly_fields(self, request: HttpRequest, obj: Model | None = None) -> Sequence[str]:
ret = list(super().get_readonly_fields(request, obj))
ret.append("curr_async_result_id")
return ret
Expand Down Expand Up @@ -53,7 +53,7 @@ def celery_inspect(self, request: HttpRequest, pk: str) -> HttpResponse:
ctx,
)

def has_queue_permission(self, perm, request: HttpRequest, o: Optional[CeleryTaskModel]) -> bool:
def has_queue_permission(self, perm, request: HttpRequest, o: CeleryTaskModel | None) -> bool:
perm = "%s.%s_%s" % (
self.model._meta.app_label,
perm,
Expand Down Expand Up @@ -83,7 +83,7 @@ def celery_terminate(self, request: "HttpRequest", pk: str) -> "HttpResponse":
return self._celery_terminate(request, pk)

def _celery_queue(self, request: "HttpRequest", pk: str) -> "HttpResponse": # type: ignore
obj: Optional[CeleryTaskModel]
obj: CeleryTaskModel | None
obj = self.get_object(request, pk)

ctx = self.get_common_context(request, pk, title=f"Confirm queue action for {obj}")
Expand All @@ -100,10 +100,10 @@ def doit(request: "HttpRequest") -> HttpResponseRedirect:

if obj.is_queued():
self.message_user(request, "Task has already been queued.", messages.WARNING)
return
return None
if obj.is_terminated() and not obj.repeatable:
self.message_user(request, "Task is already terminated.", messages.WARNING)
return
return None

return confirm_action(
self,
Expand All @@ -122,15 +122,15 @@ def doit(request: "HttpRequest") -> HttpResponseRedirect:
)

def _celery_revoke(self, request: "HttpRequest", pk: str) -> "HttpResponse": # type: ignore
obj: Optional[CeleryTaskModel]
obj: CeleryTaskModel | None
obj = self.get_object(request, pk)

if not obj.is_queued():
self.message_user(request, "Task not queued.", messages.WARNING)
return
return None
if obj.is_terminated():
self.message_user(request, "Task is already terminated.", messages.WARNING)
return
return None
ctx = self.get_common_context(request, pk, title=f"Confirm revoking action for {obj}")

def doit(request: "HttpRequest") -> HttpResponseRedirect:
Expand Down Expand Up @@ -161,10 +161,10 @@ def _celery_terminate(self, request: HttpRequest, pk: str) -> "HttpResponse": #
obj: CeleryTaskModel = self.get_object(request, pk)
if not obj.is_queued():
self.message_user(request, "Task not queued.", messages.WARNING)
return
return None
if obj.is_terminated():
self.message_user(request, "Task is already terminated.", messages.WARNING)
return
return None
ctx = self.get_common_context(request, pk, title=f"Confirm termination request for {obj}")

def doit(request: "HttpRequest") -> HttpResponseRedirect:
Expand Down
Loading

0 comments on commit 2354fd0

Please sign in to comment.