Skip to content

Commit

Permalink
remote: make start_session() args more explicit
Browse files Browse the repository at this point in the history
During the move to gRPC, start_session()'s arguments changed. Since this
is one of the functions used from outside of labgrid, add typing hints
and force the kwargs to be passed with names. This should make users
aware of the changes, so their code can be adapted.

Signed-off-by: Bastian Krause <bst@pengutronix.de>
  • Loading branch information
Bastian-Krause committed Aug 13, 2024
1 parent 545d240 commit 37a92b5
Show file tree
Hide file tree
Showing 2 changed files with 15 additions and 2 deletions.
15 changes: 14 additions & 1 deletion labgrid/remote/client.py
Original file line number Diff line number Diff line change
Expand Up @@ -23,6 +23,7 @@
from collections import defaultdict, OrderedDict
from datetime import datetime
from pprint import pformat
from typing import Any, Dict

import attr
import grpc
Expand Down Expand Up @@ -1566,7 +1567,19 @@ def ensure_event_loop(external_loop=None):
return loop


def start_session(address, extra=None, debug=False, loop=None):
def start_session(
address: str, *, extra: Dict[str, Any] = None, debug: bool = False, loop: "asyncio.AbstractEventLoop | None" = None
):
"""
Starts a ClientSession.
Args:
address: coordinator address as HOST[:PORT], PORT defaults to 20408
extra: additional kwargs for ClientSession
debug: set debug mode of the event loop
loop: explicit event loop to use (otherwise a previously stashed loop,
if retrievable the current thread's loop or a new loop is used)
"""
loop = ensure_event_loop(loop)

if extra is None:
Expand Down
2 changes: 1 addition & 1 deletion labgrid/resource/remote.py
Original file line number Diff line number Diff line change
Expand Up @@ -22,7 +22,7 @@ def _start(self):

from ..remote.client import start_session
try:
self.session = start_session(self.url, {'env': self.env})
self.session = start_session(self.url, extra={'env': self.env})
except ConnectionRefusedError as e:
raise ConnectionRefusedError(f"Could not connect to coordinator {self.url}") \
from e
Expand Down

0 comments on commit 37a92b5

Please sign in to comment.