Skip to content

Commit

Permalink
type fixes
Browse files Browse the repository at this point in the history
  • Loading branch information
Christian-B committed Nov 26, 2024
1 parent fdd75f7 commit 60d2d79
Show file tree
Hide file tree
Showing 6 changed files with 16 additions and 9 deletions.
4 changes: 4 additions & 0 deletions spalloc_client/_utils.py
Original file line number Diff line number Diff line change
Expand Up @@ -17,6 +17,10 @@
from typing import Optional


def time_left_float(timestamp: float) -> float:
return max(0.0, timestamp - time.time())


def time_left(timestamp: Optional[float]) -> Optional[float]:
""" Convert a timestamp into how long to wait for it.
"""
Expand Down
8 changes: 4 additions & 4 deletions spalloc_client/job.py
Original file line number Diff line number Diff line change
Expand Up @@ -32,7 +32,7 @@
from .protocol_client import ProtocolClient, ProtocolTimeoutError
from .spalloc_config import SpallocConfig, SEARCH_PATH
from .states import JobState
from ._utils import time_left, timed_out, make_timeout
from ._utils import time_left, time_left_float, timed_out, make_timeout

logger = logging.getLogger(__name__)

Expand Down Expand Up @@ -249,8 +249,8 @@ def __init__(self, *args: int, **kwargs: Union[float, str, None]):
hostname = cast(str, kwargs.get("hostname", config.hostname))
owner = kwargs.get("owner", config.owner)
port = cast(int, kwargs.get("port", config.port))
self._reconnect_delay = kwargs.get("reconnect_delay",
config.reconnect_delay)
self._reconnect_delay = cast(float, kwargs.get("reconnect_delay",
config.reconnect_delay))
self._timeout = cast(float, kwargs.get("timeout", config.timeout))
if hostname is None:
raise ValueError("A hostname must be specified.")
Expand Down Expand Up @@ -671,7 +671,7 @@ def _do_reconnect(self, finish_time: Optional[float]) -> None:
"""
self._client.close()
if finish_time is not None:
delay = min(time_left(finish_time), self._reconnect_delay)
delay = min(time_left_float(finish_time), self._reconnect_delay)
else:
delay = self._reconnect_delay
time.sleep(max(0.0, delay))
Expand Down
3 changes: 2 additions & 1 deletion spalloc_client/scripts/job.py
Original file line number Diff line number Diff line change
Expand Up @@ -86,6 +86,7 @@
Terminal, render_definitions, render_boards, DEFAULT_BOARD_EDGES)
from spalloc_client import ProtocolClient
from spalloc_client._utils import render_timestamp
from spalloc_client.spalloc_config import SpallocConfig
from spalloc_client.scripts.support import Terminate, Script


Expand Down Expand Up @@ -340,7 +341,7 @@ def get_job_id(self, client: ProtocolClient,
return cast(int, job_ids[0])

@overrides(Script.get_parser)
def get_parser(self, cfg: Dict[str, str]) -> argparse.ArgumentParser:
def get_parser(self, cfg: SpallocConfig) -> argparse.ArgumentParser:
parser = argparse.ArgumentParser(
description="Manage running jobs.")
parser.add_argument(
Expand Down
3 changes: 2 additions & 1 deletion spalloc_client/scripts/machine.py
Original file line number Diff line number Diff line change
Expand Up @@ -38,6 +38,7 @@
from spinn_utilities.typing.json import JsonObject, JsonObjectArray

from spalloc_client import __version__, ProtocolClient
from spalloc_client.spalloc_config import SpallocConfig
from spalloc_client.term import (
Terminal, render_table, render_definitions, render_boards, render_cells,
DEFAULT_BOARD_EDGES, TableRow, TableType)
Expand Down Expand Up @@ -257,7 +258,7 @@ def get_and_display_machine_info(
show_machine(t, machines, jobs, args.machine, not args.detailed)

@overrides(Script.get_parser)
def get_parser(self, cfg: Dict[str, str]) -> argparse.ArgumentParser:
def get_parser(self, cfg: SpallocConfig) -> argparse.ArgumentParser:
parser = argparse.ArgumentParser(
description="Get the state of individual machines.")
parser.add_argument(
Expand Down
3 changes: 2 additions & 1 deletion spalloc_client/scripts/ps.py
Original file line number Diff line number Diff line change
Expand Up @@ -33,6 +33,7 @@
from spinn_utilities.typing.json import JsonObjectArray

from spalloc_client import __version__, JobState, ProtocolClient
from spalloc_client.spalloc_config import SpallocConfig
from spalloc_client.term import Terminal, render_table, TableColumn, TableType
from spalloc_client._utils import render_timestamp
from .support import Script
Expand Down Expand Up @@ -128,7 +129,7 @@ class ProcessListScript(Script):
An object form Job scripts.
"""
@overrides(Script.get_parser)
def get_parser(self, cfg: Dict[str, str]) -> argparse.ArgumentParser:
def get_parser(self, cfg: SpallocConfig) -> argparse.ArgumentParser:
parser = argparse.ArgumentParser(description="List all active jobs.")
parser.add_argument(
"--version", "-V", action="version", version=__version__)
Expand Down
4 changes: 2 additions & 2 deletions spalloc_client/scripts/where_is.py
Original file line number Diff line number Diff line change
Expand Up @@ -72,8 +72,8 @@

from spalloc_client import __version__, ProtocolClient
from spalloc_client.term import render_definitions

from spalloc_client.scripts.support import Terminate, Script
from spalloc_client.spalloc_config import SpallocConfig


class WhereIsScript(Script):
Expand All @@ -88,7 +88,7 @@ def __init__(self) -> None:
self.show_board_chip = False

@overrides(Script.get_parser)
def get_parser(self, cfg: Dict[str, str]) -> argparse.ArgumentParser:
def get_parser(self, cfg: SpallocConfig) -> argparse.ArgumentParser:
parser = argparse.ArgumentParser(
description="Find out the location (physical or logical) of a "
"chip or board.")
Expand Down

0 comments on commit 60d2d79

Please sign in to comment.