Skip to content

Commit

Permalink
Update Ruff (#475)
Browse files Browse the repository at this point in the history
  • Loading branch information
disrupted authored Mar 28, 2024
1 parent 791a798 commit 6d42170
Show file tree
Hide file tree
Showing 20 changed files with 109 additions and 110 deletions.
1 change: 1 addition & 0 deletions hooks/__init__.py
Original file line number Diff line number Diff line change
@@ -1,4 +1,5 @@
"""KPOps pre-commit hooks."""

from pathlib import Path

ROOT = Path(__file__).parents[1].resolve()
6 changes: 3 additions & 3 deletions hooks/gen_docs/gen_docs_components.py
Original file line number Diff line number Diff line change
Expand Up @@ -225,9 +225,9 @@ def get_sections(component_name: str, *, exist_changes: bool) -> KpopsComponent:
component_sections: list[str] = PIPELINE_COMPONENT_DEPENDENCIES[ # type: ignore [reportGeneralTypeIssues]
component_file_name
]
component_sections_not_inherited: list[
str
] = DEFAULTS_PIPELINE_COMPONENT_DEPENDENCIES[component_file_name] # type: ignore [reportGeneralTypeIssues]
component_sections_not_inherited: list[str] = (
DEFAULTS_PIPELINE_COMPONENT_DEPENDENCIES[component_file_name]
) # type: ignore [reportGeneralTypeIssues]
return KpopsComponent(component_sections, component_sections_not_inherited)


Expand Down
1 change: 1 addition & 0 deletions hooks/gen_docs/gen_docs_env_vars.py
Original file line number Diff line number Diff line change
@@ -1,4 +1,5 @@
"""Generates the documentation on KPOps environment variables."""

from __future__ import annotations

import csv
Expand Down
1 change: 1 addition & 0 deletions hooks/gen_schema.py
Original file line number Diff line number Diff line change
@@ -1,4 +1,5 @@
"""Generates the stock KPOps editor integration schemas."""

from contextlib import redirect_stdout
from io import StringIO
from pathlib import Path
Expand Down
3 changes: 1 addition & 2 deletions kpops/cli/main.py
Original file line number Diff line number Diff line change
Expand Up @@ -508,8 +508,7 @@ def main(
callback=version_callback,
is_eager=True,
),
):
...
): ...


if __name__ == "__main__":
Expand Down
3 changes: 1 addition & 2 deletions kpops/component_handlers/helm_wrapper/model.py
Original file line number Diff line number Diff line change
Expand Up @@ -140,8 +140,7 @@ def to_command(self) -> list[str]:
return command


class HelmUpgradeInstallFlags(HelmFlags):
...
class HelmUpgradeInstallFlags(HelmFlags): ...


class HelmTemplateFlags(HelmFlags):
Expand Down
3 changes: 1 addition & 2 deletions kpops/component_handlers/schema_handler/schema_provider.py
Original file line number Diff line number Diff line change
Expand Up @@ -15,5 +15,4 @@ class SchemaProvider(ABC):
@abstractmethod
def provide_schema(
self, schema_class: str, models: dict[ModelName, ModelVersion]
) -> Schema:
...
) -> Schema: ...
6 changes: 3 additions & 3 deletions kpops/components/base_components/helm_app.py
Original file line number Diff line number Diff line change
Expand Up @@ -40,9 +40,9 @@ class HelmAppValues(KubernetesAppValues):
:param name_override: Helm chart name override, assigned automatically
"""

name_override: Annotated[
str, pydantic.StringConstraints(max_length=K8S_LABEL_MAX_LEN)
] | None = Field(
name_override: (
Annotated[str, pydantic.StringConstraints(max_length=K8S_LABEL_MAX_LEN)] | None
) = Field(
default=None,
title="Nameoverride",
description=describe_attr("name_override", __doc__),
Expand Down
3 changes: 1 addition & 2 deletions kpops/utils/gen_schema.py
Original file line number Diff line number Diff line change
Expand Up @@ -34,8 +34,7 @@ class SchemaScope(str, Enum):
CONFIG = "config"


class MultiComponentGenerateJsonSchema(GenerateJsonSchema):
...
class MultiComponentGenerateJsonSchema(GenerateJsonSchema): ...


log = logging.getLogger("")
Expand Down
54 changes: 28 additions & 26 deletions poetry.lock

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

19 changes: 11 additions & 8 deletions pyproject.toml
Original file line number Diff line number Diff line change
Expand Up @@ -23,6 +23,7 @@ kpops = "kpops.cli.main:app"

[tool.poetry.dependencies]
python = ">=3.10, <3.13"
anyio = "^4.3.0"
pydantic = "^2.5.3"
pydantic-settings = "^2.0.3"
rich = "^12.4.4"
Expand All @@ -42,7 +43,7 @@ pytest-mock = "^3.10.0"
pytest-timeout = "^2.1.0"
pytest-snapshot = "^0.9.0"
pre-commit = "^2.19.0"
ruff = "^0.1.7"
ruff = "^0.3.4"
typer-cli = "^0.0.13"
pyright = "^1.1.352"
pytest-rerunfailures = "^11.1.2"
Expand Down Expand Up @@ -73,6 +74,12 @@ reportIncompatibleMethodOverride = false
# reportIncompatibleMethodOverride = "warning"

[tool.ruff]
output-format = "grouped"
show-fixes = true
target-version = "py310"
extend-exclude = ["tests/*snapshots/*"]

[tool.ruff.lint]
ignore = [
# Rules in conflict with `ruff-format` -- START
"W191", # Checks for indentation that uses tabs. Spaces are preferred.
Expand Down Expand Up @@ -161,19 +168,15 @@ select = [
# "FURB", # refurb, add when out of nursery
# "LOG", # flake8-logging, add when out of nursery
]
output-format = "grouped"
show-fixes = true
task-tags = ["TODO", "HACK", "FIXME", "XXX"]
target-version = "py310"
extend-exclude = ["tests/*snapshots/*"]

[tool.ruff.extend-per-file-ignores]
[tool.ruff.lint.extend-per-file-ignores]
"tests/*/__init__.py" = ["F401"]

[tool.ruff.flake8-bugbear]
[tool.ruff.lint.flake8-bugbear]
extend-immutable-calls = ["typer.Argument"]

[tool.ruff.flake8-type-checking]
[tool.ruff.lint.flake8-type-checking]
runtime-evaluated-base-classes = ["pydantic.BaseModel"]

[build-system]
Expand Down
6 changes: 4 additions & 2 deletions tests/cli/test_init.py
Original file line number Diff line number Diff line change
Expand Up @@ -15,8 +15,10 @@ def test_create_config(tmp_path: Path):
req_conf_name = "config_with_only_required"
create_config(opt_conf_name, tmp_path, True)
create_config(req_conf_name, tmp_path, False)
assert (opt_conf := Path(tmp_path / (opt_conf_name + ".yaml"))).exists()
assert (req_conf := Path(tmp_path / (req_conf_name + ".yaml"))).exists()
opt_conf = (tmp_path / opt_conf_name).with_suffix(".yaml")
assert opt_conf.exists()
req_conf = (tmp_path / req_conf_name).with_suffix(".yaml")
assert req_conf.exists()
assert len(opt_conf.read_text()) > len(req_conf.read_text())


Expand Down
6 changes: 2 additions & 4 deletions tests/cli/test_registry.py
Original file line number Diff line number Diff line change
Expand Up @@ -8,12 +8,10 @@
from tests.cli.resources.custom_module import CustomSchemaProvider


class SubComponent(PipelineComponent):
...
class SubComponent(PipelineComponent): ...


class SubSubComponent(SubComponent):
...
class SubSubComponent(SubComponent): ...


class Unrelated:
Expand Down
15 changes: 5 additions & 10 deletions tests/cli/test_schema_generation.py
Original file line number Diff line number Diff line change
Expand Up @@ -29,29 +29,24 @@ class EmptyPipelineComponent(PipelineComponent):


# abstract component inheriting from ABC should be excluded
class AbstractBaseComponent(PipelineComponent, ABC):
...
class AbstractBaseComponent(PipelineComponent, ABC): ...


# abstract component with abstractmethods should be excluded
class AbstractPipelineComponent(AbstractBaseComponent):
@abstractmethod
def not_implemented(self) -> None:
...
def not_implemented(self) -> None: ...


class SubPipelineComponent(EmptyPipelineComponent):
...
class SubPipelineComponent(EmptyPipelineComponent): ...


# type is inherited from SubPipelineComponent
class SubPipelineComponentNoSchemaTypeNoType(SubPipelineComponent):
...
class SubPipelineComponentNoSchemaTypeNoType(SubPipelineComponent): ...


# Correctly defined
class SubPipelineComponentCorrect(SubPipelineComponent):
...
class SubPipelineComponentCorrect(SubPipelineComponent): ...


# Correctly defined, docstr test
Expand Down
Original file line number Diff line number Diff line change
@@ -1,10 +1,10 @@
import json
import sys
from pathlib import Path
from unittest.mock import AsyncMock, MagicMock, patch

import pytest
import pytest_asyncio
from anyio import Path
from pytest_httpx import HTTPXMock

from kpops.component_handlers.kafka_connect.connect_wrapper import ConnectWrapper
Expand Down Expand Up @@ -508,10 +508,10 @@ async def test_should_create_correct_validate_connector_config_and_name_gets_add

@pytest.mark.asyncio()
async def test_should_parse_validate_connector_config(self, httpx_mock: HTTPXMock):
with Path(
content = await Path(
RESOURCES_PATH / "connect_validation_response.json",
).open() as f:
actual_response = json.load(f)
).read_text()
actual_response = json.loads(content)

httpx_mock.add_response(
method="PUT",
Expand Down
8 changes: 4 additions & 4 deletions tests/component_handlers/topic/test_proxy_wrapper.py
Original file line number Diff line number Diff line change
@@ -1,10 +1,10 @@
import json
from pathlib import Path
from typing import Any
from unittest.mock import AsyncMock, MagicMock, patch

import pytest
import pytest_asyncio
from anyio import Path
from pydantic import AnyUrl
from pytest_httpx import HTTPXMock
from pytest_mock import MockerFixture
Expand Down Expand Up @@ -35,10 +35,10 @@ def log_debug_mock(self, mocker: MockerFixture) -> MagicMock:
async def _setup(self, httpx_mock: HTTPXMock):
config = KpopsConfig()
self.proxy_wrapper = ProxyWrapper(config.kafka_rest)
with Path(
content = await Path(
RESOURCES_PATH / "kafka_rest_proxy_responses" / "cluster-info.json",
).open() as f:
cluster_response = json.load(f)
).read_text()
cluster_response = json.loads(content)

httpx_mock.add_response(
method="GET",
Expand Down
Loading

0 comments on commit 6d42170

Please sign in to comment.