Skip to content

Commit

Permalink
Updated deps, flake8 replaced with ruff.
Browse files Browse the repository at this point in the history
Signed-off-by: Pavel Kirilin <win10@list.ru>
  • Loading branch information
s3rius committed Oct 17, 2023
1 parent f81ec63 commit 31291b0
Show file tree
Hide file tree
Showing 11 changed files with 521 additions and 887 deletions.
2 changes: 1 addition & 1 deletion .github/workflows/release.yml
Original file line number Diff line number Diff line change
Expand Up @@ -13,7 +13,7 @@ jobs:
- name: Set up Python
uses: actions/setup-python@v2
with:
python-version: "3.9"
python-version: "3.11"
- name: Install deps
uses: knowsuchagency/poetry-install@v1
env:
Expand Down
13 changes: 5 additions & 8 deletions .github/workflows/test.yml
Original file line number Diff line number Diff line change
Expand Up @@ -13,14 +13,11 @@ jobs:
matrix:
cmd:
- black
- flake8
- isort
# mypy is disabled because redis>=5.0 has errors in typing
# - mypy
- autoflake
- ruff
- mypy
runs-on: ubuntu-latest
steps:
- uses: actions/checkout@v2
- uses: actions/checkout@v4
- name: Install poetry
run: pipx install poetry
- name: Set up Python
Expand All @@ -47,10 +44,10 @@ jobs:
- 6379:6379
strategy:
matrix:
py_version: ["3.8", "3.9", "3.10", "3.11"]
py_version: ["3.8", "3.9", "3.10", "3.11", "3.12"]
runs-on: "ubuntu-latest"
steps:
- uses: actions/checkout@v2
- uses: actions/checkout@v4
- name: Set up Python
uses: actions/setup-python@v2
with:
Expand Down
32 changes: 8 additions & 24 deletions .pre-commit-config.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -22,35 +22,19 @@ repos:
language: system
types: [python]

- id: autoflake
name: autoflake
entry: autoflake
language: system
types: [ python ]
args: [ --in-place, --remove-all-unused-imports, --remove-duplicate-keys ]

- id: isort
name: isort
entry: isort
language: system
types: [ python ]

- id: flake8
name: Check with Flake8
entry: flake8
- id: ruff
name: Run ruff lints
entry: poetry run ruff
language: system
pass_filenames: false
types: [ python ]
args: [--count, .]
types: [python]
args:
- "--fix"
- "taskiq_redis"
- "tests"

- id: mypy
name: Validate types with MyPy
entry: mypy
language: system
types: [ python ]

- id: yesqa
name: Remove usless noqa
entry: yesqa
language: system
types: [ python ]
1,252 changes: 421 additions & 831 deletions poetry.lock

Large diffs are not rendered by default.

80 changes: 70 additions & 10 deletions pyproject.toml
Original file line number Diff line number Diff line change
Expand Up @@ -29,21 +29,18 @@ python = "^3.8.1"
taskiq = "^0"
redis = "^5"

[tool.poetry.dev-dependencies]
[tool.poetry.group.dev.dependencies]
pytest = "^7.0"
flake8 = "^6"
mypy = "^1"
isort = "^5.10.1"
yesqa = "^1.3.0"
wemake-python-styleguide = "^0.18"
black = "^22.3.0"
autoflake = "^1.4"
pytest-cov = "^3.0.0"
anyio = "^3.6.1"
pytest-env = "^0.6.2"
fakeredis = "^2"
pre-commit = "^2.20.0"
pytest-xdist = { version = "^2.5.0", extras = ["psutil"] }
ruff = "^0.1.0"
types-redis = "^4.6.0.7"

[tool.mypy]
strict = true
Expand All @@ -61,10 +58,73 @@ module = ['redis']
ignore_missing_imports = true
strict = false

[tool.isort]
profile = "black"
multi_line_output = 3

[build-system]
requires = ["poetry-core>=1.0.0"]
build-backend = "poetry.core.masonry.api"

[tool.ruff]
# List of enabled rulsets.
# See https://docs.astral.sh/ruff/rules/ for more information.
select = [
"E", # Error
"F", # Pyflakes
"W", # Pycodestyle
"C90", # McCabe complexity
"I", # Isort
"N", # pep8-naming
"D", # Pydocstyle
"ANN", # Pytype annotations
"S", # Bandit
"B", # Bugbear
"COM", # Commas
"C4", # Comprehensions
"ISC", # Implicit string concat
"PIE", # Unnecessary code
"T20", # Catch prints
"PYI", # validate pyi files
"Q", # Checks for quotes
"RSE", # Checks raise statements
"RET", # Checks return statements
"SLF", # Self checks
"SIM", # Simplificator
"PTH", # Pathlib checks
"ERA", # Checks for commented out code
"PL", # PyLint checks
"RUF", # Specific to Ruff checks
]
ignore = [
"D105", # Missing docstring in magic method
"D107", # Missing docstring in __init__
"D212", # Multi-line docstring summary should start at the first line
"D401", # First line should be in imperative mood
"D104", # Missing docstring in public package
"D100", # Missing docstring in public module
"ANN102", # Missing type annotation for self in method
"ANN101", # Missing type annotation for argument
"ANN401", # typing.Any are disallowed in `**kwargs
"PLR0913", # Too many arguments for function call
"D106", # Missing docstring in public nested class
]
exclude = [".venv/"]
mccabe = { max-complexity = 10 }
line-length = 88

[tool.ruff.per-file-ignores]
"tests/*" = [
"S101", # Use of assert detected
"S301", # Use of pickle detected
"D103", # Missing docstring in public function
"SLF001", # Private member accessed
"S311", # Standard pseudo-random generators are not suitable for security/cryptographic purposes
"D101", # Missing docstring in public class
]

[tool.ruff.pydocstyle]
convention = "pep257"
ignore-decorators = ["typing.overload"]

[tool.ruff.pylint]
allow-magic-value-types = ["int", "str", "float", "tuple"]

[tool.ruff.flake8-bugbear]
extend-immutable-calls = ["taskiq_dependencies.Depends", "taskiq.TaskiqDepends"]
Empty file added taskiq_redis/py.typed
Empty file.
10 changes: 6 additions & 4 deletions taskiq_redis/redis_backend.py
Original file line number Diff line number Diff line change
Expand Up @@ -23,7 +23,7 @@ def __init__(
keep_results: bool = True,
result_ex_time: Optional[int] = None,
result_px_time: Optional[int] = None,
):
) -> None:
"""
Constructs a new result backend.
Expand Down Expand Up @@ -87,7 +87,7 @@ async def set_result(
redis_set_params["px"] = self.result_px_time

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

async def is_result_ready(self, task_id: str) -> bool:
"""
Expand Down Expand Up @@ -124,9 +124,11 @@ async def get_result(
)

if result_value is None:
raise ResultIsMissingError()
raise ResultIsMissingError

taskiq_result: TaskiqResult[_ReturnType] = pickle.loads(result_value)
taskiq_result: TaskiqResult[_ReturnType] = pickle.loads( # noqa: S301
result_value,
)

if not with_logs:
taskiq_result.log = None
Expand Down
4 changes: 2 additions & 2 deletions taskiq_redis/redis_broker.py
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,7 @@
from taskiq.abc.result_backend import AsyncResultBackend
from taskiq.message import BrokerMessage

_T = TypeVar("_T") # noqa: WPS111
_T = TypeVar("_T")

logger = getLogger("taskiq.redis_broker")

Expand Down Expand Up @@ -109,7 +109,7 @@ async def listen(self) -> AsyncGenerator[bytes, None]:
"""
redis_brpop_data_position = 1
async with Redis(connection_pool=self.connection_pool) as redis_conn:
while True: # noqa: WPS457
while True:
yield (await redis_conn.brpop(self.queue_name))[
redis_brpop_data_position
]
6 changes: 3 additions & 3 deletions tests/test_backend.py
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
import asyncio
import uuid
from typing import TypeVar
from typing import Any, TypeVar

import pytest
from taskiq import TaskiqResult
Expand Down Expand Up @@ -34,7 +34,7 @@ def task_id() -> str:


@pytest.fixture
def default_taskiq_result() -> TaskiqResult[_ReturnType]:
def default_taskiq_result() -> TaskiqResult[Any]:
"""
Generates default TaskiqResult.
Expand All @@ -49,7 +49,7 @@ def default_taskiq_result() -> TaskiqResult[_ReturnType]:


@pytest.fixture
def custom_taskiq_result() -> TaskiqResult[_ReturnType]:
def custom_taskiq_result() -> TaskiqResult[Any]:
"""
Generates custom TaskiqResult.
Expand Down
5 changes: 3 additions & 2 deletions tests/test_broker.py
Original file line number Diff line number Diff line change
Expand Up @@ -14,7 +14,7 @@ def test_no_url_should_raise_typeerror() -> None:
ListQueueBroker() # type: ignore


async def get_message( # type: ignore
async def get_message(
broker: AsyncBroker,
) -> Union[bytes, AckableMessage]:
"""
Expand All @@ -23,8 +23,9 @@ async def get_message( # type: ignore
:param broker: async message broker.
:return: first message from listen method.
"""
async for message in broker.listen(): # noqa: WPS328
async for message in broker.listen():
return message
return b""


@pytest.fixture
Expand Down
4 changes: 2 additions & 2 deletions tests/test_result_backend.py
Original file line number Diff line number Diff line change
Expand Up @@ -35,7 +35,7 @@ async def test_set_result_success(redis_url: str) -> None:
)
assert fetched_result.log == "My Log"
assert fetched_result.return_value == 11
assert fetched_result.execution_time == 112.2 # noqa: WPS459
assert fetched_result.execution_time == 112.2
assert fetched_result.is_err


Expand Down Expand Up @@ -67,7 +67,7 @@ async def test_fetch_without_logs(redis_url: str) -> None:
)
assert fetched_result.log is None
assert fetched_result.return_value == 11
assert fetched_result.execution_time == 112.2 # noqa: WPS459
assert fetched_result.execution_time == 112.2
assert fetched_result.is_err


Expand Down

0 comments on commit 31291b0

Please sign in to comment.