diff --git a/README.md b/README.md index 593295dd..63b6a9d8 100644 --- a/README.md +++ b/README.md @@ -96,7 +96,7 @@ Run test: ./scripts/test ``` -Run code formatting (`black` and `isort`) +Run code formatting with ruff: ```bash ./scripts/format diff --git a/examples/confluent-example/confluent_example/streaming/engine.py b/examples/confluent-example/confluent_example/streaming/engine.py index e782a731..bad97064 100644 --- a/examples/confluent-example/confluent_example/streaming/engine.py +++ b/examples/confluent-example/confluent_example/streaming/engine.py @@ -1,6 +1,6 @@ -from confluent_example import serializers from schema_registry.client import AsyncSchemaRegistryClient +from confluent_example import serializers from kstreams import create_engine client = AsyncSchemaRegistryClient("http://localhost:8081") diff --git a/examples/dataclasses-avroschema-example/dataclasses_avroschema_example/models.py b/examples/dataclasses-avroschema-example/dataclasses_avroschema_example/models.py index 0a2ab6d8..b88c5217 100644 --- a/examples/dataclasses-avroschema-example/dataclasses_avroschema_example/models.py +++ b/examples/dataclasses-avroschema-example/dataclasses_avroschema_example/models.py @@ -7,6 +7,7 @@ @dataclass class User(AvroModel): "An User" + name: str age: int pets: typing.List[str] @@ -25,6 +26,7 @@ class Meta: @dataclass class Address(AvroModel): "An Address" + street: str street_number: int diff --git a/kstreams/clients.py b/kstreams/clients.py index 90f9d6b6..a6011605 100644 --- a/kstreams/clients.py +++ b/kstreams/clients.py @@ -16,6 +16,7 @@ def __init__( self.config = kwargs if key_deserializer is None: + def key_deserializer(key): if key is not None: return key.decode() @@ -33,6 +34,7 @@ def __init__( self.config = kwargs if key_serializer is None: + def key_serializer(key): if key is not None: return key.encode("utf-8") diff --git a/kstreams/create.py b/kstreams/create.py index f88eeaaf..eda4b339 100644 --- a/kstreams/create.py +++ b/kstreams/create.py @@ -16,7 +16,6 @@ def create_engine( deserializer: Optional[Deserializer] = None, monitor: Optional[PrometheusMonitor] = None, ) -> StreamEngine: - if monitor is None: monitor = PrometheusMonitor() diff --git a/kstreams/engine.py b/kstreams/engine.py index 3e48f399..c3b15d5e 100644 --- a/kstreams/engine.py +++ b/kstreams/engine.py @@ -12,7 +12,8 @@ from .prometheus.monitor import PrometheusMonitor from .rebalance_listener import MetricsRebalanceListener, RebalanceListener from .serializers import Deserializer, Serializer -from .streams import Stream, StreamFunc, stream as stream_func +from .streams import Stream, StreamFunc +from .streams import stream as stream_func from .types import Headers from .utils import encode_headers diff --git a/pyproject.toml b/pyproject.toml index 07551122..96dbec5d 100644 --- a/pyproject.toml +++ b/pyproject.toml @@ -65,10 +65,6 @@ exclude = ''' )/ ''' -[tool.isort] -profile = "black" -known_first_party = ["kstreams", "tests", "examples"] - [tool.commitizen] version = "0.15.1" tag_format = "$version" @@ -89,3 +85,44 @@ ignore_missing_imports = true [[tool.mypy.overrides]] module = "prometheus_client.*" ignore_missing_imports = true + +[tool.ruff] +line-length = 88 +exclude = [ + ".bzr", + ".direnv", + ".eggs", + ".git", + ".hg", + ".mypy_cache", + ".nox", + ".pants.d", + ".ruff_cache", + ".svn", + ".tox", + ".venv", + "__pypackages__", + "_build", + "buck-out", + "build", + "dist", + "node_modules", + ".venv", +] + +[tool.ruff.lint] +select = [ + # pycodestyle" + "E4", + "E7", + "E9", + "E501", + # Pyflakes + "F", + # isort + "I001" +] + +# Allow fix for all enabled rules (when `--fix`) is provided. +fixable = ["ALL"] +unfixable = [] diff --git a/scripts/format b/scripts/format index ff2b0335..c4d6c549 100755 --- a/scripts/format +++ b/scripts/format @@ -7,4 +7,5 @@ fi set -x +${PREFIX}ruff format . ${PREFIX}ruff kstreams tests --fix diff --git a/tests/test_backend_kafka.py b/tests/test_backend_kafka.py index 4deec292..8e510787 100644 --- a/tests/test_backend_kafka.py +++ b/tests/test_backend_kafka.py @@ -18,7 +18,6 @@ def test_plaintext_ok(): def test_ssl_ok(ssl_context): - kafka_backend = Kafka( security_protocol=SecurityProtocol.SSL, ssl_context=ssl_context ) diff --git a/tests/test_monitor.py b/tests/test_monitor.py index f286225a..bab525fc 100644 --- a/tests/test_monitor.py +++ b/tests/test_monitor.py @@ -24,7 +24,6 @@ async def my_coroutine(_): consumer = stream.consumer for topic_partition in consumer.assignment(): - # super ugly notation but for now is the only way to get the metrics met_committed = ( stream_engine.monitor.MET_COMMITTED.labels(