Skip to content

Commit 62c8ae1

Browse files
committed
Changed linter to ruff.
Signed-off-by: Pavel Kirilin <[email protected]>
1 parent 28b873f commit 62c8ae1

40 files changed

+726
-1239
lines changed

.github/workflows/test.yml

Lines changed: 1 addition & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -8,10 +8,8 @@ jobs:
88
matrix:
99
cmd:
1010
- black
11-
- flake8
12-
- isort
11+
- ruff
1312
- mypy
14-
- autoflake
1513
runs-on: ubuntu-latest
1614
steps:
1715
- uses: actions/checkout@v2

.gitignore

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -168,3 +168,6 @@ node_modules
168168

169169
# macOS
170170
.DS_Store
171+
172+
# Ruff
173+
.ruff_cache/

.pre-commit-config.yaml

Lines changed: 10 additions & 26 deletions
Original file line numberDiff line numberDiff line change
@@ -12,7 +12,7 @@ repos:
1212
- repo: https://github.com/asottile/add-trailing-comma
1313
rev: v2.1.0
1414
hooks:
15-
- id: add-trailing-comma
15+
- id: add-trailing-comma
1616

1717
- repo: local
1818
hooks:
@@ -22,35 +22,19 @@ repos:
2222
language: system
2323
types: [python]
2424

25-
- id: autoflake
26-
name: autoflake
27-
entry: poetry run autoflake
28-
language: system
29-
types: [ python ]
30-
args: [ --in-place, --remove-all-unused-imports, --remove-duplicate-keys ]
31-
32-
- id: isort
33-
name: isort
34-
entry: poetry run isort
35-
language: system
36-
types: [ python ]
37-
38-
- id: flake8
39-
name: Check with Flake8
40-
entry: poetry run flake8
25+
- id: ruff
26+
name: Run ruff lints
27+
entry: poetry run ruff
4128
language: system
4229
pass_filenames: false
43-
types: [ python ]
44-
args: [--count, taskiq]
30+
types: [python]
31+
args:
32+
- "--fix"
33+
- "taskiq"
34+
- "tests"
4535

4636
- id: mypy
4737
name: Validate types with MyPy
4838
entry: poetry run mypy
4939
language: system
50-
types: [ python ]
51-
52-
- id: yesqa
53-
name: Remove usless noqa
54-
entry: poetry run yesqa
55-
language: system
56-
types: [ python ]
40+
types: [python]

poetry.lock

Lines changed: 187 additions & 772 deletions
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

pyproject.toml

Lines changed: 72 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -47,19 +47,15 @@ pytz = "*"
4747

4848
[tool.poetry.dev-dependencies]
4949
pytest = "^7.1.2"
50+
ruff = "^0.0.291"
5051
black = { version = "^22.6.0", allow-prereleases = true }
51-
flake8 = "^6"
52-
isort = "^5.10.1"
5352
mypy = "^1"
5453
pre-commit = "^2.20.0"
55-
yesqa = "^1.3.0"
56-
autoflake = "^1.4"
5754
coverage = "^6.4.2"
5855
pytest-cov = "^3.0.0"
5956
mock = "^4.0.3"
6057
pytest-xdist = { version = "^2.5.0", extras = ["psutil"] }
6158
types-mock = "^4.0.15"
62-
wemake-python-styleguide = "^0.18.0"
6359
tox = "^4.6.4"
6460
freezegun = "^1.2.2"
6561
pytest-mock = "^3.11.1"
@@ -96,7 +92,7 @@ profile = "black"
9692
multi_line_output = 3
9793

9894
[tool.pytest.ini_options]
99-
log_level='INFO'
95+
log_level = 'INFO'
10096

10197
[tool.coverage.run]
10298
omit = [
@@ -113,3 +109,73 @@ omit = [
113109
[build-system]
114110
requires = ["poetry-core>=1.0.0"]
115111
build-backend = "poetry.core.masonry.api"
112+
113+
[tool.ruff]
114+
# List of enabled rulsets.
115+
# See https://docs.astral.sh/ruff/rules/ for more information.
116+
select = [
117+
"E", # Error
118+
"F", # Pyflakes
119+
"W", # Pycodestyle
120+
"C90", # McCabe complexity
121+
"I", # Isort
122+
"N", # pep8-naming
123+
"D", # Pydocstyle
124+
"ANN", # Pytype annotations
125+
"S", # Bandit
126+
"B", # Bugbear
127+
"COM", # Commas
128+
"C4", # Comprehensions
129+
"ISC", # Implicit string concat
130+
"PIE", # Unnecessary code
131+
"T20", # Catch prints
132+
"PYI", # validate pyi files
133+
"Q", # Checks for quotes
134+
"RSE", # Checks raise statements
135+
"RET", # Checks return statements
136+
"SLF", # Self checks
137+
"SIM", # Simplificator
138+
"PTH", # Pathlib checks
139+
"ERA", # Checks for commented out code
140+
"PL", # PyLint checks
141+
"RUF", # Specific to Ruff checks
142+
]
143+
ignore = [
144+
"D105", # Missing docstring in magic method
145+
"D107", # Missing docstring in __init__
146+
"D212", # Multi-line docstring summary should start at the first line
147+
"D401", # First line should be in imperative mood
148+
"D104", # Missing docstring in public package
149+
"D100", # Missing docstring in public module
150+
"ANN102", # Missing type annotation for self in method
151+
"ANN101", # Missing type annotation for argument
152+
"ANN401", # typing.Any are disallowed in `**kwargs
153+
"PLR0913", # Too many arguments for function call
154+
"D106", # Missing docstring in public nested class
155+
]
156+
exclude = [".venv/"]
157+
mccabe = { max-complexity = 10 }
158+
line-length = 88
159+
160+
[tool.ruff.per-file-ignores]
161+
"tests/*" = [
162+
"S101", # Use of assert detected
163+
"S301", # Use of pickle detected
164+
"D103", # Missing docstring in public function
165+
"SLF001", # Private member accessed
166+
"S311", # Standard pseudo-random generators are not suitable for security/cryptographic purposes
167+
"D101", # Missing docstring in public class
168+
]
169+
170+
[tool.ruff.pydocstyle]
171+
convention = "pep257"
172+
ignore-decorators = ["typing.overload"]
173+
174+
[tool.ruff.pylint]
175+
allow-magic-value-types = ["int", "str", "float", "tuple"]
176+
177+
[tool.ruff.flake8-bugbear]
178+
extend-immutable-calls = [
179+
"taskiq_dependencies.Depends",
180+
"taskiq.TaskiqDepends",
181+
]

taskiq/__main__.py

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -8,7 +8,7 @@
88
from taskiq.abc.cmd import TaskiqCMD
99

1010

11-
def main() -> None: # noqa: C901, WPS210 # pragma: no cover
11+
def main() -> None: # pragma: no cover
1212
"""
1313
Main entrypoint of the taskiq.
1414
@@ -48,7 +48,7 @@ def main() -> None: # noqa: C901, WPS210 # pragma: no cover
4848
try:
4949
cmd_class = entrypoint.load()
5050
except ImportError as exc:
51-
print(f"Could not load {entrypoint.value}. Cause: {exc}") # noqa: WPS421
51+
print(f"Could not load {entrypoint.value}. Cause: {exc}") # noqa: T201
5252
continue
5353
if issubclass(cmd_class, TaskiqCMD):
5454
subparsers.add_parser(
@@ -61,7 +61,7 @@ def main() -> None: # noqa: C901, WPS210 # pragma: no cover
6161
args, _ = parser.parse_known_args()
6262

6363
if args.version:
64-
print(__version__) # noqa: WPS421
64+
print(__version__) # noqa: T201
6565
return
6666

6767
if args.subcommand is None:
@@ -72,7 +72,7 @@ def main() -> None: # noqa: C901, WPS210 # pragma: no cover
7272
sys.argv.pop(0)
7373
status = command.exec(sys.argv[1:])
7474
if status is not None:
75-
exit(status) # noqa: WPS421
75+
exit(status) # noqa: PLR1722
7676

7777

7878
if __name__ == "__main__": # pragma: no cover

taskiq/abc/broker.py

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -5,7 +5,7 @@
55
from collections import defaultdict
66
from functools import wraps
77
from logging import getLogger
8-
from typing import ( # noqa: WPS235
8+
from typing import (
99
TYPE_CHECKING,
1010
Any,
1111
AsyncGenerator,
@@ -39,7 +39,7 @@
3939
from taskiq.abc.formatter import TaskiqFormatter
4040
from taskiq.abc.result_backend import AsyncResultBackend
4141

42-
_T = TypeVar("_T") # noqa: WPS111
42+
_T = TypeVar("_T")
4343
_FuncParams = ParamSpec("_FuncParams")
4444
_ReturnType = TypeVar("_ReturnType")
4545

@@ -307,7 +307,7 @@ def make_decorated_task(
307307
def inner(
308308
func: Callable[_FuncParams, _ReturnType],
309309
) -> AsyncTaskiqDecoratedTask[_FuncParams, _ReturnType]:
310-
nonlocal inner_task_name # noqa: WPS420
310+
nonlocal inner_task_name
311311
if inner_task_name is None:
312312
fmodule = func.__module__
313313
if fmodule == "__main__": # pragma: no cover
@@ -319,7 +319,7 @@ def inner(
319319
fname = func.__name__
320320
if fname == "<lambda>":
321321
fname = f"lambda_{uuid4().hex}"
322-
inner_task_name = f"{fmodule}:{fname}" # noqa: WPS442
322+
inner_task_name = f"{fmodule}:{fname}"
323323
wrapper = wraps(func)
324324

325325
decorated_task = wrapper(

taskiq/api/receiver.py

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -9,7 +9,7 @@
99
logger = getLogger("taskiq.receiver")
1010

1111

12-
async def run_receiver_task( # noqa: WPS211
12+
async def run_receiver_task(
1313
broker: AsyncBroker,
1414
receiver_cls: Type[Receiver] = Receiver,
1515
sync_workers: int = 4,

taskiq/api/scheduler.py

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -19,5 +19,5 @@ async def run_scheduler_task(
1919
await source.startup()
2020
if run_startup:
2121
await scheduler.startup()
22-
while True: # noqa: WPS457
22+
while True:
2323
await run_scheduler_loop(scheduler)

taskiq/brokers/inmemory_broker.py

Lines changed: 6 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -39,9 +39,11 @@ async def set_result(self, task_id: str, result: TaskiqResult[_ReturnType]) -> N
3939
:param task_id: id of a task.
4040
:param result: result of an execution.
4141
"""
42-
if self.max_stored_results != -1:
43-
if len(self.results) >= self.max_stored_results:
44-
self.results.popitem(last=False)
42+
if (
43+
self.max_stored_results != -1
44+
and len(self.results) >= self.max_stored_results
45+
):
46+
self.results.popitem(last=False)
4547
self.results[task_id] = result
4648

4749
async def is_result_ready(self, task_id: str) -> bool:
@@ -85,7 +87,7 @@ class InMemoryBroker(AsyncBroker):
8587
It's useful for local development, if you don't want to setup real broker.
8688
"""
8789

88-
def __init__( # noqa: WPS211
90+
def __init__(
8991
self,
9092
sync_tasks_pool_size: int = 4,
9193
max_stored_results: int = 100,

0 commit comments

Comments
 (0)