Skip to content

Commit

Permalink
chore: ruff config added. Make use of ruff formatter
Browse files Browse the repository at this point in the history
  • Loading branch information
marcosschroh committed Jan 3, 2024
1 parent d25bdb1 commit 2afb711
Show file tree
Hide file tree
Showing 10 changed files with 50 additions and 10 deletions.
2 changes: 1 addition & 1 deletion README.md
Original file line number Diff line number Diff line change
Expand Up @@ -96,7 +96,7 @@ Run test:
./scripts/test
```

Run code formatting (`black` and `isort`)
Run code formatting with ruff:

```bash
./scripts/format
Expand Down
Original file line number Diff line number Diff line change
@@ -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")
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -7,6 +7,7 @@
@dataclass
class User(AvroModel):
"An User"

name: str
age: int
pets: typing.List[str]
Expand All @@ -25,6 +26,7 @@ class Meta:
@dataclass
class Address(AvroModel):
"An Address"

street: str
street_number: int

Expand Down
2 changes: 2 additions & 0 deletions kstreams/clients.py
Original file line number Diff line number Diff line change
Expand Up @@ -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()
Expand All @@ -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")
Expand Down
1 change: 0 additions & 1 deletion kstreams/create.py
Original file line number Diff line number Diff line change
Expand Up @@ -16,7 +16,6 @@ def create_engine(
deserializer: Optional[Deserializer] = None,
monitor: Optional[PrometheusMonitor] = None,
) -> StreamEngine:

if monitor is None:
monitor = PrometheusMonitor()

Expand Down
3 changes: 2 additions & 1 deletion kstreams/engine.py
Original file line number Diff line number Diff line change
Expand Up @@ -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

Expand Down
45 changes: 41 additions & 4 deletions pyproject.toml
Original file line number Diff line number Diff line change
Expand Up @@ -65,10 +65,6 @@ exclude = '''
)/
'''

[tool.isort]
profile = "black"
known_first_party = ["kstreams", "tests", "examples"]

[tool.commitizen]
version = "0.15.1"
tag_format = "$version"
Expand All @@ -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 = []
1 change: 1 addition & 0 deletions scripts/format
Original file line number Diff line number Diff line change
Expand Up @@ -7,4 +7,5 @@ fi

set -x

${PREFIX}ruff format .
${PREFIX}ruff kstreams tests --fix
1 change: 0 additions & 1 deletion tests/test_backend_kafka.py
Original file line number Diff line number Diff line change
Expand Up @@ -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
)
Expand Down
1 change: 0 additions & 1 deletion tests/test_monitor.py
Original file line number Diff line number Diff line change
Expand Up @@ -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(
Expand Down

0 comments on commit 2afb711

Please sign in to comment.