Skip to content

Commit

Permalink
Merge pull request #1019 from Aiven-Open/jjaakola-aiven-fastapi-use-ruff
Browse files Browse the repository at this point in the history
chore: use ruff
  • Loading branch information
nosahama authored Jan 8, 2025
2 parents e640102 + 40ace39 commit 5f6408b
Show file tree
Hide file tree
Showing 171 changed files with 379 additions and 369 deletions.
14 changes: 0 additions & 14 deletions .flake8

This file was deleted.

43 changes: 8 additions & 35 deletions .pre-commit-config.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -30,36 +30,6 @@ repos:
hooks:
- id: shfmt

- repo: https://github.com/asottile/pyupgrade
rev: v3.4.0
hooks:
- id: pyupgrade
args: [ --py310-plus ]

- repo: https://github.com/pycqa/autoflake
rev: v2.1.1
hooks:
- id: autoflake
args:
- --in-place
- --remove-all-unused-imports
- --ignore-init-module-imports

- repo: https://github.com/PyCQA/isort
rev: 5.12.0
hooks:
- id: isort

- repo: https://github.com/psf/black
rev: 23.3.0
hooks:
- id: black

- repo: https://github.com/PyCQA/flake8
rev: 7.1.0
hooks:
- id: flake8

- repo: https://github.com/hadolint/hadolint
rev: v2.12.0
hooks:
Expand All @@ -70,9 +40,12 @@ repos:
# https://github.com/hadolint/hadolint/issues/497
- --ignore=DL3042

- repo: https://github.com/PyCQA/pylint
# Note: pre-commit autoupdate changes to an alpha version. Instead, manually find the
# latest stable version here: https://github.com/pylint-dev/pylint/releases
rev: v3.2.6
- repo: https://github.com/astral-sh/ruff-pre-commit
# Ruff version.
rev: v0.8.6
hooks:
- id: pylint
# Run the linter.
- id: ruff
args: [ --fix ]
# Run the formatter.
- id: ruff-format
43 changes: 0 additions & 43 deletions .pylintrc

This file was deleted.

3 changes: 0 additions & 3 deletions container/compose.yml
Original file line number Diff line number Diff line change
Expand Up @@ -143,10 +143,7 @@ services:
- ../tests:/opt/karapace/tests
- ../pytest.ini:/opt/karapace/pytest.ini
- ../mypy.ini:/opt/karapace/mypy.ini
- ../.flake8:/opt/karapace/.flake8
- ../.isort.cfg:/opt/karapace/.isort.cfg
- ../.pre-commit-config.yaml:/opt/karapace/.pre-commit-config.yaml
- ../.pylintrc:/opt/karapace/.pylintrc
- ../.coveragerc:/opt/karapace/.coveragerc
- ../.coverage.3.10:/opt/karapace/coverage/.coverage.3.10
- ../.coverage.3.11:/opt/karapace/coverage/.coverage.3.11
Expand Down
1 change: 1 addition & 0 deletions container/healthcheck.py
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,7 @@
Copyright (c) 2023 Aiven Ltd
See LICENSE for details
"""

from __future__ import annotations

from http import HTTPStatus
Expand Down
1 change: 1 addition & 0 deletions performance-test/rest-proxy-produce-consume-test.py
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,7 @@
Copyright (c) 2023 Aiven Ltd
See LICENSE for details
"""

from kafka.admin import KafkaAdminClient, NewTopic
from kafka.errors import TopicAlreadyExistsError
from locust import FastHttpUser, task
Expand Down
1 change: 1 addition & 0 deletions performance-test/schema-registry-schema-post.py
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,7 @@
Copyright (c) 2023 Aiven Ltd
See LICENSE for details
"""

from dataclasses import dataclass, field
from locust import FastHttpUser, task
from locust.contrib.fasthttp import ResponseContextManager
Expand Down
4 changes: 2 additions & 2 deletions pyproject.toml
Original file line number Diff line number Diff line change
Expand Up @@ -80,6 +80,7 @@ ujson = ["ujson"]
dev = [
# Developer QoL
"pdbpp",
"ruff",

# testing
"filelock",
Expand Down Expand Up @@ -112,6 +113,5 @@ include-package-data = true
[tool.setuptools_scm]
version_file = "src/karapace/version.py"

[tool.black]
target-version = ["py310", "py311"]
[tool.ruff]
line-length = 125
1 change: 1 addition & 0 deletions setup.py
Original file line number Diff line number Diff line change
Expand Up @@ -3,6 +3,7 @@
Copyright (c) 2023 Aiven Ltd
See LICENSE for details
"""

from setuptools import Extension, setup

setup(
Expand Down
3 changes: 2 additions & 1 deletion src/karapace/anonymize_schemas/anonymize_avro.py
Original file line number Diff line number Diff line change
Expand Up @@ -4,6 +4,7 @@
Copyright (c) 2023 Aiven Ltd
See LICENSE for details
"""

from typing import Any, TypeAlias, Union

import hashlib
Expand Down Expand Up @@ -98,7 +99,7 @@ def anonymize_element(m: re.Match) -> str:


def anonymize(input_schema: Schema) -> Schema:
if not input_schema: # pylint: disable=no-else-return
if not input_schema:
return input_schema
elif isinstance(input_schema, str):
if input_schema in ALL_TYPES:
Expand Down
21 changes: 8 additions & 13 deletions src/karapace/auth.py
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,7 @@
Copyright (c) 2023 Aiven Ltd
See LICENSE for details
"""

from __future__ import annotations

from base64 import b64encode
Expand Down Expand Up @@ -98,29 +99,23 @@ class AuthData(TypedDict):


class AuthenticateProtocol(Protocol):
def authenticate(self, *, username: str, password: str) -> User | None:
...
def authenticate(self, *, username: str, password: str) -> User | None: ...


class AuthorizeProtocol(Protocol):
def get_user(self, username: str) -> User | None:
...
def get_user(self, username: str) -> User | None: ...

def check_authorization(self, user: User | None, operation: Operation, resource: str) -> bool:
...
def check_authorization(self, user: User | None, operation: Operation, resource: str) -> bool: ...

def check_authorization_any(self, user: User | None, operation: Operation, resources: list[str]) -> bool:
...
def check_authorization_any(self, user: User | None, operation: Operation, resources: list[str]) -> bool: ...


class AuthenticatorAndAuthorizer(AuthenticateProtocol, AuthorizeProtocol):
MUST_AUTHENTICATE: bool = True

async def close(self) -> None:
...
async def close(self) -> None: ...

async def start(self, stats: StatsClient) -> None: # pylint: disable=unused-argument
...
async def start(self, stats: StatsClient) -> None: ...


class NoAuthAndAuthz(AuthenticatorAndAuthorizer):
Expand Down Expand Up @@ -241,7 +236,7 @@ async def _refresh_authfile() -> None:
except asyncio.CancelledError:
log.info("Closing schema registry ACL refresh task")
return
except Exception as ex: # pylint: disable=broad-except
except Exception as ex:
log.exception("Schema registry auth file could not be loaded")
stats.unexpected_exception(ex=ex, where="schema_registry_authfile_reloader")
return
Expand Down
11 changes: 4 additions & 7 deletions src/karapace/avro_dataclasses/introspect.py
Original file line number Diff line number Diff line change
Expand Up @@ -20,16 +20,13 @@
from _typeshed import DataclassInstance
else:

class DataclassInstance:
...
class DataclassInstance: ...


class UnsupportedAnnotation(NotImplementedError):
...
class UnsupportedAnnotation(NotImplementedError): ...


class UnderspecifiedAnnotation(UnsupportedAnnotation):
...
class UnderspecifiedAnnotation(UnsupportedAnnotation): ...


def _field_type_array(field: Field, origin: type, type_: object) -> AvroType:
Expand Down Expand Up @@ -60,7 +57,7 @@ def _field_type_array(field: Field, origin: type, type_: object) -> AvroType:
sequence_types: Final = frozenset({tuple, list, Sequence})


def _field_type(field: Field, type_: object) -> AvroType: # pylint: disable=too-many-return-statements
def _field_type(field: Field, type_: object) -> AvroType:
# Handle primitives.
if type_ is bool:
return "boolean"
Expand Down
6 changes: 2 additions & 4 deletions src/karapace/avro_dataclasses/models.py
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,7 @@
Copyright (c) 2023 Aiven Ltd
See LICENSE for details
"""

from __future__ import annotations

from .introspect import record_schema
Expand All @@ -22,8 +23,7 @@
from _typeshed import DataclassInstance
else:

class DataclassInstance:
...
class DataclassInstance: ...


__all__ = ("AvroModel",)
Expand Down Expand Up @@ -76,8 +76,6 @@ def parse(value: object) -> object:


def from_avro_value(type_: object) -> Parser | None:
# pylint: disable=too-many-return-statements

if isinstance(type_, type):
if is_dataclass(type_):
return partial(from_avro_dict, type_)
Expand Down
1 change: 1 addition & 0 deletions src/karapace/avro_dataclasses/schema.py
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,7 @@
Copyright (c) 2023 Aiven Ltd
See LICENSE for details
"""

from __future__ import annotations

from collections.abc import Mapping
Expand Down
3 changes: 2 additions & 1 deletion src/karapace/backup/api.py
Original file line number Diff line number Diff line change
Expand Up @@ -4,6 +4,7 @@
Copyright (c) 2023 Aiven Ltd
See LICENSE for details
"""

from __future__ import annotations

from .backends.reader import BaseBackupReader, BaseItemsBackupReader, ProducerSend, RestoreTopic, RestoreTopicLegacy
Expand Down Expand Up @@ -170,7 +171,7 @@ def before_sleep(it: RetryCallState) -> None:
result = f"failed ({outcome.exception()})"
else:
result = f"returned {outcome.result()!r}"
LOG.info(f"{description} {result}, retrying... (Ctrl+C to abort)") # pylint: disable=logging-fstring-interpolation
LOG.info(f"{description} {result}, retrying... (Ctrl+C to abort)")

return before_sleep

Expand Down
4 changes: 2 additions & 2 deletions src/karapace/backup/backends/reader.py
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,7 @@
Copyright (c) 2023 Aiven Ltd
See LICENSE for details
"""

from __future__ import annotations

from collections.abc import Callable, Generator, Iterator, Mapping, Sequence
Expand Down Expand Up @@ -78,8 +79,7 @@ def __init__(

@staticmethod
@abc.abstractmethod
def items_from_file(fp: IO[str]) -> Iterator[Sequence[str]]:
...
def items_from_file(fp: IO[str]) -> Iterator[Sequence[str]]: ...

def read(
self,
Expand Down
1 change: 1 addition & 0 deletions src/karapace/backup/backends/v1.py
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,7 @@
Copyright (c) 2023 Aiven Ltd
See LICENSE for details
"""

from __future__ import annotations

from collections.abc import Generator
Expand Down
1 change: 1 addition & 0 deletions src/karapace/backup/backends/v2.py
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,7 @@
Copyright (c) 2023 Aiven Ltd
See LICENSE for details
"""

from __future__ import annotations

from collections.abc import Generator, Sequence
Expand Down
1 change: 1 addition & 0 deletions src/karapace/backup/backends/v3/backend.py
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,7 @@
Copyright (c) 2023 Aiven Ltd
See LICENSE for details
"""

from __future__ import annotations

from .checksum import RunningChecksum
Expand Down
7 changes: 3 additions & 4 deletions src/karapace/backup/backends/v3/checksum.py
Original file line number Diff line number Diff line change
Expand Up @@ -2,14 +2,13 @@
Copyright (c) 2023 Aiven Ltd
See LICENSE for details
"""

from __future__ import annotations

from typing import Protocol


class RunningChecksum(Protocol):
def update(self, data: bytes) -> None:
...
def update(self, data: bytes) -> None: ...

def digest(self) -> bytes:
...
def digest(self) -> bytes: ...
1 change: 1 addition & 0 deletions src/karapace/backup/backends/v3/constants.py
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,7 @@
Copyright (c) 2023 Aiven Ltd
See LICENSE for details
"""

from typing import Final

V3_MARKER: Final = b"/V3\n"
1 change: 1 addition & 0 deletions src/karapace/backup/backends/v3/readers.py
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,7 @@
Copyright (c) 2023 Aiven Ltd
See LICENSE for details
"""

from __future__ import annotations

from .checksum import RunningChecksum
Expand Down
Loading

0 comments on commit 5f6408b

Please sign in to comment.