Skip to content

Commit d321a8c

Browse files
committed
Fix linting issues and update dependencies
- Fix pylint warnings (too-many-arguments, exception chaining) - Fix import ordering per isort/black - Remove unused imports in tests - Update grpcio dependency to >= 1.74.0 (required by API) - Use git reference for frequenz-api-marketmetering until released - Add type: ignore comments for grpc stub type issues Signed-off-by: Mathias L. Baumann <[email protected]>
1 parent ccdb1c2 commit d321a8c

File tree

5 files changed

+34
-31
lines changed

5 files changed

+34
-31
lines changed

pyproject.toml

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -39,9 +39,9 @@ classifiers = [
3939
requires-python = ">= 3.11, < 4"
4040
dependencies = [
4141
"typing-extensions >= 4.13.0, < 5",
42-
"frequenz-api-market-metering >= 0.1.0, < 1",
42+
"frequenz-api-marketmetering @ git+https://github.com/frequenz-io/frequenz-api-market-metering[email protected]",
4343
"frequenz-client-base >= 0.11.0, < 0.12.0",
44-
"grpcio >= 1.72.1, < 2",
44+
"grpcio >= 1.74.0, < 2",
4545
]
4646
dynamic = ["version"]
4747

@@ -72,7 +72,7 @@ dev-mkdocs = [
7272
"mike == 2.1.3",
7373
"mkdocs-gen-files == 0.5.0",
7474
"mkdocs-literate-nav == 0.6.2",
75-
"frequenz-api-market-metering >= 0.1.0, < 1",
75+
"frequenz-api-marketmetering @ git+https://github.com/frequenz-io/frequenz-api-market-metering[email protected]",
7676
"mkdocs-macros-plugin == 1.4.1",
7777
"mkdocs-material == 9.6.23",
7878
"mkdocstrings[python] == 0.30.1",
@@ -91,7 +91,7 @@ dev-pylint = [
9191
"pylint == 3.3.9",
9292
# For checking the noxfile, docs/ script, and tests
9393
"frequenz-client-marketmetering[cli,dev-mkdocs,dev-noxfile,dev-pytest]",
94-
"frequenz-api-market-metering >= 0.1.0, < 1",
94+
"frequenz-api-marketmetering @ git+https://github.com/frequenz-io/frequenz-api-market-metering[email protected]",
9595
]
9696
dev-pytest = [
9797
"pytest == 8.4.2",

src/frequenz/client/marketmetering/__main__.py

Lines changed: 17 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -5,6 +5,7 @@
55

66
import asyncio
77
import os
8+
import shlex
89
from datetime import datetime, timezone
910
from pprint import pformat
1011
from typing import Any
@@ -52,7 +53,8 @@ def print_series(series: MarketLocationSeries, raw: bool = False) -> None:
5253
)
5354
click.echo(f" {click.style('Direction:', fg='cyan')} {series.direction.name}")
5455
click.echo(
55-
f" {click.style('Metric:', fg='cyan')} {series.metric_type.name} [{series.metric_unit.name}]"
56+
f" {click.style('Metric:', fg='cyan')} "
57+
f"{series.metric_type.name} [{series.metric_unit.name}]"
5658
)
5759
click.echo(f" {click.style('Resolution:', fg='cyan')} {series.resolution.name}")
5860

@@ -168,20 +170,20 @@ def parse_market_location(value: str) -> MarketLocationRef:
168170

169171
try:
170172
enterprise_id = int(parts[0])
171-
except ValueError:
172-
raise click.BadParameter(f"Invalid enterprise_id: {parts[0]}")
173+
except ValueError as exc:
174+
raise click.BadParameter(f"Invalid enterprise_id: {parts[0]}") from exc
173175

174176
location_id = parts[1]
175177

176178
try:
177179
id_type = MarketLocationIdType[parts[2].upper()]
178-
except KeyError:
180+
except KeyError as exc:
179181
valid_types = ", ".join(
180182
t.name for t in MarketLocationIdType if t.name != "UNSPECIFIED"
181183
)
182184
raise click.BadParameter(
183185
f"Invalid location type: {parts[2]}. Valid types: {valid_types}"
184-
)
186+
) from exc
185187

186188
return MarketLocationRef(
187189
enterprise_id=enterprise_id,
@@ -245,6 +247,7 @@ def convert(
245247
type=click.Choice([r.name for r in TimeResolution if r.name != "UNSPECIFIED"]),
246248
help="Resampling resolution",
247249
)
250+
# pylint: disable=too-many-arguments,too-many-positional-arguments
248251
async def stream_cmd(
249252
ctx: click.Context,
250253
market_locations: tuple[MarketLocationRef, ...],
@@ -262,6 +265,15 @@ async def stream_cmd(
262265
42:DE01234567890:MALO_ID
263266
264267
Valid types: MALO_ID, MPAN, ESI_ID, NMI, OTHER
268+
269+
Args:
270+
ctx: Click context with client and options.
271+
market_locations: Market location references to stream.
272+
direction: Energy flow directions (IMPORT/EXPORT).
273+
metric: Metric types to request.
274+
start_time: Optional start time for historical data.
275+
end_time: Optional end time.
276+
resolution: Optional resampling resolution.
265277
"""
266278
client: MarketMeteringApiClient = ctx.obj["client"]
267279
raw: bool = ctx.obj["raw"]
@@ -326,8 +338,6 @@ async def display_help() -> None:
326338
{command: None for command in user_commands}
327339
)
328340

329-
import shlex
330-
331341
while True:
332342
with patch_stdout():
333343
try:

src/frequenz/client/marketmetering/_client.py

Lines changed: 9 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -6,24 +6,22 @@
66
from __future__ import annotations
77

88
from datetime import datetime, timedelta
9-
from typing import AsyncIterator, Awaitable, cast
9+
from typing import AsyncIterator, cast
1010

1111
from frequenz.api.common.v1alpha8.types.interval_pb2 import Interval as PBInterval
1212
from frequenz.api.marketmetering.v1alpha1 import marketmetering_pb2 as pb
1313
from frequenz.api.marketmetering.v1alpha1 import marketmetering_pb2_grpc
14+
from google.protobuf.timestamp_pb2 import Timestamp
15+
16+
from frequenz import channels
1417
from frequenz.client.base.channel import ChannelOptions, SslOptions
1518
from frequenz.client.base.client import BaseApiClient
1619
from frequenz.client.base.exception import ClientNotConnected
1720
from frequenz.client.base.retry import LinearBackoff
1821
from frequenz.client.base.streaming import GrpcStreamBroadcaster
19-
from google.protobuf.timestamp_pb2 import Timestamp
20-
21-
from frequenz import channels
2222

2323
from .types import (
2424
EnergyFlowDirection,
25-
MarketLocationId,
26-
MarketLocationIdType,
2725
MarketLocationRef,
2826
MarketLocationSeries,
2927
MetricType,
@@ -92,6 +90,7 @@ class MarketMeteringApiClient(
9290
```
9391
"""
9492

93+
# pylint: disable=too-many-arguments
9594
def __init__(
9695
self,
9796
*,
@@ -114,7 +113,7 @@ def __init__(
114113
"""
115114
super().__init__(
116115
server_url,
117-
marketmetering_pb2_grpc.MarketMeteringServiceStub,
116+
marketmetering_pb2_grpc.MarketMeteringServiceStub, # type: ignore[arg-type]
118117
connect=connect,
119118
channel_defaults=ChannelOptions(
120119
port=DEFAULT_PORT,
@@ -158,6 +157,7 @@ def stub(self) -> marketmetering_pb2_grpc.MarketMeteringServiceAsyncStub:
158157
# actually exist to the eyes of the interpreter.
159158
return self._stub # type: ignore
160159

160+
# pylint: disable=too-many-arguments
161161
async def stream_samples(
162162
self,
163163
*,
@@ -237,6 +237,7 @@ async def stream_samples(
237237
for series_pb in response.series:
238238
yield MarketLocationSeries.from_protobuf(series_pb)
239239

240+
# pylint: disable=too-many-arguments
240241
def stream(
241242
self,
242243
*,
@@ -284,6 +285,7 @@ def stream(
284285
resampling=resampling,
285286
).new_receiver()
286287

288+
# pylint: disable=too-many-arguments
287289
def _get_stream(
288290
self,
289291
*,

src/frequenz/client/marketmetering/types.py

Lines changed: 2 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -8,9 +8,8 @@
88
from enum import Enum
99
from typing import Self
1010

11-
from google.protobuf.timestamp_pb2 import Timestamp
12-
1311
from frequenz.api.marketmetering.v1alpha1 import marketmetering_pb2 as pb
12+
from google.protobuf.timestamp_pb2 import Timestamp
1413

1514

1615
class MarketArea(Enum):
@@ -446,7 +445,7 @@ def to_protobuf(self) -> pb.ResamplingOptions:
446445
The protobuf representation.
447446
"""
448447
return pb.ResamplingOptions(
449-
resolution=self.resolution.value if self.resolution else 0,
448+
resolution=self.resolution.value if self.resolution else 0, # type: ignore[arg-type]
450449
downsampling_method=self.downsampling_method.value,
451450
)
452451

tests/test_marketmetering.py

Lines changed: 2 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -3,20 +3,16 @@
33

44
"""Tests for the Market Metering client."""
55

6-
from datetime import datetime, timezone
7-
from unittest.mock import AsyncMock, MagicMock, patch
8-
9-
import pytest
6+
from datetime import timedelta
107

118
from frequenz.client.marketmetering.types import (
129
DataQuality,
10+
DownsamplingMethod,
1311
EnergyFlowDirection,
1412
MarketArea,
1513
MarketLocationId,
1614
MarketLocationIdType,
1715
MarketLocationRef,
18-
MarketLocationSample,
19-
MarketLocationSeries,
2016
MetricType,
2117
MetricUnit,
2218
ResamplingMethod,
@@ -42,8 +38,6 @@ def test_market_location_id_type_enum(self) -> None:
4238

4339
def test_time_resolution_to_timedelta(self) -> None:
4440
"""Test TimeResolution.to_timedelta."""
45-
from datetime import timedelta
46-
4741
assert TimeResolution.MIN_15.to_timedelta() == timedelta(minutes=15)
4842
assert TimeResolution.MIN_60.to_timedelta() == timedelta(hours=1)
4943
assert TimeResolution.DAY_1.to_timedelta() == timedelta(days=1)
@@ -115,8 +109,6 @@ def test_default_resampling_options(self) -> None:
115109
"""Test default ResamplingOptions."""
116110
options = ResamplingOptions()
117111
assert options.resolution is None
118-
from frequenz.client.marketmetering.types import DownsamplingMethod
119-
120112
assert options.downsampling_method == DownsamplingMethod.MEAN
121113

122114
def test_resampling_options_with_resolution(self) -> None:

0 commit comments

Comments
 (0)