Skip to content

Commit 0dc8afd

Browse files
authored
Merge pull request #3 from unicef/ruff
Ruff
2 parents 95096af + 2354fd0 commit 0dc8afd

File tree

18 files changed

+172
-207
lines changed

18 files changed

+172
-207
lines changed

.github/workflows/lint.yml

Lines changed: 8 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -29,10 +29,10 @@ jobs:
2929
lint: ${{steps.changes.outputs.lint }}
3030
steps:
3131
- name: Checkout code
32-
uses: actions/checkout@v4.1.7
32+
uses: actions/checkout@v4
3333
- id: changes
3434
name: Check for file changes
35-
uses: dorny/paths-filter@0bc4621a3135347011ad047f9ecf449bf72ce2bd # v3.0.0
35+
uses: dorny/paths-filter@v3
3636
with:
3737
base: ${{ github.ref }}
3838
token: ${{ github.token }}
@@ -47,16 +47,19 @@ jobs:
4747
if: needs.changes.outputs.lint
4848
steps:
4949
- name: Checkout code
50-
uses: actions/checkout@v4.1.7
50+
uses: actions/checkout@v4
5151

5252
- name: Set up Python
5353
uses: actions/setup-python@v5
5454
with:
5555
python-version: 3.12
5656
architecture: 'x64'
5757
- uses: yezz123/setup-uv@v4
58+
with:
59+
version: "latest"
5860
- name: lint
5961
if: needs.changes.outputs.lint
6062
run: |
61-
uv run isort src/ --check-only
62-
uv run flake8 src/
63+
pip install ruff
64+
ruff check -e
65+
ruff format --check

.github/workflows/test.yml

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -30,10 +30,10 @@ jobs:
3030
lint: ${{steps.changes.outputs.lint }}
3131
steps:
3232
- name: Checkout code
33-
uses: actions/checkout@v4.1.7
33+
uses: actions/checkout@v4
3434
- id: changes
3535
name: Check for file changes
36-
uses: dorny/paths-filter@0bc4621a3135347011ad047f9ecf449bf72ce2bd # v3.0.0
36+
uses: dorny/paths-filter@v3
3737
with:
3838
base: ${{ github.ref }}
3939
token: ${{ github.token }}
@@ -74,7 +74,7 @@ jobs:
7474
DB_PASSWORD: "postgres"
7575
steps:
7676
- name: Checkout code
77-
uses: actions/checkout@v4.1.7
77+
uses: actions/checkout@v4
7878
- name: Set up Python ${{ matrix.python-version }}
7979
uses: actions/setup-python@v5
8080
with:
@@ -119,7 +119,7 @@ jobs:
119119
if: ${{ always() }}
120120

121121
- name: Upload coverage to Codecov
122-
uses: codecov/codecov-action@v4
122+
uses: codecov/codecov-action@v5
123123
if: matrix.python-version == 3.12
124124
continue-on-error: true
125125
with:

ruff.toml

Lines changed: 81 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,81 @@
1+
target-version = "py313"
2+
line-length = 120
3+
4+
[lint.isort]
5+
case-sensitive = true
6+
7+
[lint]
8+
select = [
9+
"A", # prevent using keywords that clobber python builtins
10+
# "ANN", # flake8 annotations
11+
"B", # bugbear: security warnings
12+
"BLE", # blind exceptions
13+
"C4", # flake8-comprehensions
14+
"C90", # McCabe complexity
15+
"COM", # flake8-commas
16+
"D", # pydocstyle
17+
"DJ", # flake8-django
18+
"E", # pycodestylex
19+
"E4", "E7", "E9",
20+
"ERA", # eradicate
21+
"F", # pyflakes
22+
"FLY", # flynt
23+
"FURB", # refurb
24+
"I", # isort
25+
"ICN", # flake8-import-conventions
26+
"ISC", # implicit string concatenation
27+
"N", # Pep* naming
28+
"PERF", # perflint
29+
"PIE", # flake8-pie
30+
"PL", # PyLint
31+
# "PT", # flake8-pytest-style
32+
"Q", # flake8-quotes
33+
"R", # PyLint Refactor
34+
"RET", # flake8-return
35+
"S", # bandit,
36+
"SIM", # flake8-simplify
37+
"T10", # flake8-debugger
38+
"T20", # flake8-print
39+
"TC", # flake8-type-checking
40+
"UP", # pyupgrade
41+
"W", # pycodestyle warnings
42+
"YTT", # flake8 2020
43+
]
44+
extend-select = ["UP", ]
45+
ignore = [
46+
"ANN401",
47+
"B904", # raise-without-from-inside-except: syntax not compatible with py2
48+
"COM812",
49+
"D100", # Missing docstring in public module
50+
"D101", # Missing docstring in public class
51+
"D102", # Missing docstring in public method
52+
"D103", # Missing docstring in public function
53+
"D104", # Missing docstring in public package
54+
"D105", # Missing docstring in magic method
55+
"D106", # Missing docstring in public nested class
56+
"D107", # Missing docstring in `__init__`
57+
"D203", # one-blank-line-before-class
58+
# "D212", # multi-line-summary-first-line
59+
"D213", # multi-line-summary-second-line
60+
"E731", # lambda-assignment: lambdas are substential in maintenance of py2/3 codebase
61+
"ISC001", # conflicts with ruff format command
62+
"RUF005", # collection-literal-concatenation: syntax not compatible with py2
63+
"RUF012", # mutable-class-default: typing is not available for py2
64+
"I001", # unsorted imports https://docs.astral.sh/ruff/rules/unsorted-imports/#unsorted-imports-i001
65+
"UP037", # [*] Remove quotes from type annotation
66+
"UP035", # Import from `collections.abc` instead: `Sequence`
67+
"UP031", # Use format specifiers instead of percent format
68+
"SIM108", # Use ternary operator instead of...
69+
"PLR2004", # Magic value used in comparison
70+
"DJ001", # Avoid using `null=True` on string-based fields such as `CharField`
71+
]
72+
73+
[format]
74+
quote-style = "double"
75+
indent-style = "space"
76+
skip-magic-trailing-comma = false
77+
line-ending = "auto"
78+
79+
[lint.per-file-ignores]
80+
"tests/**.py" = ["S101", "PLR2004", "S", "SIM117", "D", "UP", "PLR0913", "ANN", "N999"]
81+
"src/**/versioning/**.py" = ["N999", ]

src/django_celery_boost/admin.py

Lines changed: 11 additions & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,4 @@
1-
from typing import Any, Optional, Sequence
1+
from typing import Any, Sequence
22

33
from admin_extra_buttons.decorators import button
44
from admin_extra_buttons.mixins import ExtraButtonsMixin, confirm_action
@@ -19,7 +19,7 @@ class CeleryTaskModelAdmin(ExtraButtonsMixin, admin.ModelAdmin):
1919
inspect_template = None
2020
queue_template = None
2121

22-
def get_readonly_fields(self, request: HttpRequest, obj: "Optional[Model]" = None) -> Sequence[str]:
22+
def get_readonly_fields(self, request: HttpRequest, obj: Model | None = None) -> Sequence[str]:
2323
ret = list(super().get_readonly_fields(request, obj))
2424
ret.append("curr_async_result_id")
2525
return ret
@@ -53,7 +53,7 @@ def celery_inspect(self, request: HttpRequest, pk: str) -> HttpResponse:
5353
ctx,
5454
)
5555

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

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

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

101101
if obj.is_queued():
102102
self.message_user(request, "Task has already been queued.", messages.WARNING)
103-
return
103+
return None
104104
if obj.is_terminated() and not obj.repeatable:
105105
self.message_user(request, "Task is already terminated.", messages.WARNING)
106-
return
106+
return None
107107

108108
return confirm_action(
109109
self,
@@ -122,15 +122,15 @@ def doit(request: "HttpRequest") -> HttpResponseRedirect:
122122
)
123123

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

128128
if not obj.is_queued():
129129
self.message_user(request, "Task not queued.", messages.WARNING)
130-
return
130+
return None
131131
if obj.is_terminated():
132132
self.message_user(request, "Task is already terminated.", messages.WARNING)
133-
return
133+
return None
134134
ctx = self.get_common_context(request, pk, title=f"Confirm revoking action for {obj}")
135135

136136
def doit(request: "HttpRequest") -> HttpResponseRedirect:
@@ -161,10 +161,10 @@ def _celery_terminate(self, request: HttpRequest, pk: str) -> "HttpResponse": #
161161
obj: CeleryTaskModel = self.get_object(request, pk)
162162
if not obj.is_queued():
163163
self.message_user(request, "Task not queued.", messages.WARNING)
164-
return
164+
return None
165165
if obj.is_terminated():
166166
self.message_user(request, "Task is already terminated.", messages.WARNING)
167-
return
167+
return None
168168
ctx = self.get_common_context(request, pk, title=f"Confirm termination request for {obj}")
169169

170170
def doit(request: "HttpRequest") -> HttpResponseRedirect:

0 commit comments

Comments
 (0)