Skip to content

Commit 31291b0

Browse files
committed
Updated deps, flake8 replaced with ruff.
Signed-off-by: Pavel Kirilin <[email protected]>
1 parent f81ec63 commit 31291b0

11 files changed

+521
-887
lines changed

.github/workflows/release.yml

+1-1
Original file line numberDiff line numberDiff line change
@@ -13,7 +13,7 @@ jobs:
1313
- name: Set up Python
1414
uses: actions/setup-python@v2
1515
with:
16-
python-version: "3.9"
16+
python-version: "3.11"
1717
- name: Install deps
1818
uses: knowsuchagency/poetry-install@v1
1919
env:

.github/workflows/test.yml

+5-8
Original file line numberDiff line numberDiff line change
@@ -13,14 +13,11 @@ jobs:
1313
matrix:
1414
cmd:
1515
- black
16-
- flake8
17-
- isort
18-
# mypy is disabled because redis>=5.0 has errors in typing
19-
# - mypy
20-
- autoflake
16+
- ruff
17+
- mypy
2118
runs-on: ubuntu-latest
2219
steps:
23-
- uses: actions/checkout@v2
20+
- uses: actions/checkout@v4
2421
- name: Install poetry
2522
run: pipx install poetry
2623
- name: Set up Python
@@ -47,10 +44,10 @@ jobs:
4744
- 6379:6379
4845
strategy:
4946
matrix:
50-
py_version: ["3.8", "3.9", "3.10", "3.11"]
47+
py_version: ["3.8", "3.9", "3.10", "3.11", "3.12"]
5148
runs-on: "ubuntu-latest"
5249
steps:
53-
- uses: actions/checkout@v2
50+
- uses: actions/checkout@v4
5451
- name: Set up Python
5552
uses: actions/setup-python@v2
5653
with:

.pre-commit-config.yaml

+8-24
Original file line numberDiff line numberDiff line change
@@ -22,35 +22,19 @@ repos:
2222
language: system
2323
types: [python]
2424

25-
- id: autoflake
26-
name: autoflake
27-
entry: 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: isort
35-
language: system
36-
types: [ python ]
37-
38-
- id: flake8
39-
name: Check with Flake8
40-
entry: 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, .]
30+
types: [python]
31+
args:
32+
- "--fix"
33+
- "taskiq_redis"
34+
- "tests"
4535

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

poetry.lock

+421-831
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

pyproject.toml

+70-10
Original file line numberDiff line numberDiff line change
@@ -29,21 +29,18 @@ python = "^3.8.1"
2929
taskiq = "^0"
3030
redis = "^5"
3131

32-
[tool.poetry.dev-dependencies]
32+
[tool.poetry.group.dev.dependencies]
3333
pytest = "^7.0"
34-
flake8 = "^6"
3534
mypy = "^1"
36-
isort = "^5.10.1"
37-
yesqa = "^1.3.0"
38-
wemake-python-styleguide = "^0.18"
3935
black = "^22.3.0"
40-
autoflake = "^1.4"
4136
pytest-cov = "^3.0.0"
4237
anyio = "^3.6.1"
4338
pytest-env = "^0.6.2"
4439
fakeredis = "^2"
4540
pre-commit = "^2.20.0"
4641
pytest-xdist = { version = "^2.5.0", extras = ["psutil"] }
42+
ruff = "^0.1.0"
43+
types-redis = "^4.6.0.7"
4744

4845
[tool.mypy]
4946
strict = true
@@ -61,10 +58,73 @@ module = ['redis']
6158
ignore_missing_imports = true
6259
strict = false
6360

64-
[tool.isort]
65-
profile = "black"
66-
multi_line_output = 3
67-
6861
[build-system]
6962
requires = ["poetry-core>=1.0.0"]
7063
build-backend = "poetry.core.masonry.api"
64+
65+
[tool.ruff]
66+
# List of enabled rulsets.
67+
# See https://docs.astral.sh/ruff/rules/ for more information.
68+
select = [
69+
"E", # Error
70+
"F", # Pyflakes
71+
"W", # Pycodestyle
72+
"C90", # McCabe complexity
73+
"I", # Isort
74+
"N", # pep8-naming
75+
"D", # Pydocstyle
76+
"ANN", # Pytype annotations
77+
"S", # Bandit
78+
"B", # Bugbear
79+
"COM", # Commas
80+
"C4", # Comprehensions
81+
"ISC", # Implicit string concat
82+
"PIE", # Unnecessary code
83+
"T20", # Catch prints
84+
"PYI", # validate pyi files
85+
"Q", # Checks for quotes
86+
"RSE", # Checks raise statements
87+
"RET", # Checks return statements
88+
"SLF", # Self checks
89+
"SIM", # Simplificator
90+
"PTH", # Pathlib checks
91+
"ERA", # Checks for commented out code
92+
"PL", # PyLint checks
93+
"RUF", # Specific to Ruff checks
94+
]
95+
ignore = [
96+
"D105", # Missing docstring in magic method
97+
"D107", # Missing docstring in __init__
98+
"D212", # Multi-line docstring summary should start at the first line
99+
"D401", # First line should be in imperative mood
100+
"D104", # Missing docstring in public package
101+
"D100", # Missing docstring in public module
102+
"ANN102", # Missing type annotation for self in method
103+
"ANN101", # Missing type annotation for argument
104+
"ANN401", # typing.Any are disallowed in `**kwargs
105+
"PLR0913", # Too many arguments for function call
106+
"D106", # Missing docstring in public nested class
107+
]
108+
exclude = [".venv/"]
109+
mccabe = { max-complexity = 10 }
110+
line-length = 88
111+
112+
[tool.ruff.per-file-ignores]
113+
"tests/*" = [
114+
"S101", # Use of assert detected
115+
"S301", # Use of pickle detected
116+
"D103", # Missing docstring in public function
117+
"SLF001", # Private member accessed
118+
"S311", # Standard pseudo-random generators are not suitable for security/cryptographic purposes
119+
"D101", # Missing docstring in public class
120+
]
121+
122+
[tool.ruff.pydocstyle]
123+
convention = "pep257"
124+
ignore-decorators = ["typing.overload"]
125+
126+
[tool.ruff.pylint]
127+
allow-magic-value-types = ["int", "str", "float", "tuple"]
128+
129+
[tool.ruff.flake8-bugbear]
130+
extend-immutable-calls = ["taskiq_dependencies.Depends", "taskiq.TaskiqDepends"]

taskiq_redis/py.typed

Whitespace-only changes.

taskiq_redis/redis_backend.py

+6-4
Original file line numberDiff line numberDiff line change
@@ -23,7 +23,7 @@ def __init__(
2323
keep_results: bool = True,
2424
result_ex_time: Optional[int] = None,
2525
result_px_time: Optional[int] = None,
26-
):
26+
) -> None:
2727
"""
2828
Constructs a new result backend.
2929
@@ -87,7 +87,7 @@ async def set_result(
8787
redis_set_params["px"] = self.result_px_time
8888

8989
async with Redis(connection_pool=self.redis_pool) as redis:
90-
await redis.set(**redis_set_params)
90+
await redis.set(**redis_set_params) # type: ignore
9191

9292
async def is_result_ready(self, task_id: str) -> bool:
9393
"""
@@ -124,9 +124,11 @@ async def get_result(
124124
)
125125

126126
if result_value is None:
127-
raise ResultIsMissingError()
127+
raise ResultIsMissingError
128128

129-
taskiq_result: TaskiqResult[_ReturnType] = pickle.loads(result_value)
129+
taskiq_result: TaskiqResult[_ReturnType] = pickle.loads( # noqa: S301
130+
result_value,
131+
)
130132

131133
if not with_logs:
132134
taskiq_result.log = None

taskiq_redis/redis_broker.py

+2-2
Original file line numberDiff line numberDiff line change
@@ -6,7 +6,7 @@
66
from taskiq.abc.result_backend import AsyncResultBackend
77
from taskiq.message import BrokerMessage
88

9-
_T = TypeVar("_T") # noqa: WPS111
9+
_T = TypeVar("_T")
1010

1111
logger = getLogger("taskiq.redis_broker")
1212

@@ -109,7 +109,7 @@ async def listen(self) -> AsyncGenerator[bytes, None]:
109109
"""
110110
redis_brpop_data_position = 1
111111
async with Redis(connection_pool=self.connection_pool) as redis_conn:
112-
while True: # noqa: WPS457
112+
while True:
113113
yield (await redis_conn.brpop(self.queue_name))[
114114
redis_brpop_data_position
115115
]

tests/test_backend.py

+3-3
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,6 @@
11
import asyncio
22
import uuid
3-
from typing import TypeVar
3+
from typing import Any, TypeVar
44

55
import pytest
66
from taskiq import TaskiqResult
@@ -34,7 +34,7 @@ def task_id() -> str:
3434

3535

3636
@pytest.fixture
37-
def default_taskiq_result() -> TaskiqResult[_ReturnType]:
37+
def default_taskiq_result() -> TaskiqResult[Any]:
3838
"""
3939
Generates default TaskiqResult.
4040
@@ -49,7 +49,7 @@ def default_taskiq_result() -> TaskiqResult[_ReturnType]:
4949

5050

5151
@pytest.fixture
52-
def custom_taskiq_result() -> TaskiqResult[_ReturnType]:
52+
def custom_taskiq_result() -> TaskiqResult[Any]:
5353
"""
5454
Generates custom TaskiqResult.
5555

tests/test_broker.py

+3-2
Original file line numberDiff line numberDiff line change
@@ -14,7 +14,7 @@ def test_no_url_should_raise_typeerror() -> None:
1414
ListQueueBroker() # type: ignore
1515

1616

17-
async def get_message( # type: ignore
17+
async def get_message(
1818
broker: AsyncBroker,
1919
) -> Union[bytes, AckableMessage]:
2020
"""
@@ -23,8 +23,9 @@ async def get_message( # type: ignore
2323
:param broker: async message broker.
2424
:return: first message from listen method.
2525
"""
26-
async for message in broker.listen(): # noqa: WPS328
26+
async for message in broker.listen():
2727
return message
28+
return b""
2829

2930

3031
@pytest.fixture

tests/test_result_backend.py

+2-2
Original file line numberDiff line numberDiff line change
@@ -35,7 +35,7 @@ async def test_set_result_success(redis_url: str) -> None:
3535
)
3636
assert fetched_result.log == "My Log"
3737
assert fetched_result.return_value == 11
38-
assert fetched_result.execution_time == 112.2 # noqa: WPS459
38+
assert fetched_result.execution_time == 112.2
3939
assert fetched_result.is_err
4040

4141

@@ -67,7 +67,7 @@ async def test_fetch_without_logs(redis_url: str) -> None:
6767
)
6868
assert fetched_result.log is None
6969
assert fetched_result.return_value == 11
70-
assert fetched_result.execution_time == 112.2 # noqa: WPS459
70+
assert fetched_result.execution_time == 112.2
7171
assert fetched_result.is_err
7272

7373

0 commit comments

Comments
 (0)