diff --git a/spalloc_client/job.py b/spalloc_client/job.py index 8d3df752c..9ef4b1e55 100644 --- a/spalloc_client/job.py +++ b/spalloc_client/job.py @@ -246,12 +246,12 @@ def __init__(self, *args: int, **kwargs: Union[float, str, None]): config = SpallocConfig(config_filenames) # Get protocol client options - hostname = kwargs.get("hostname", config.hostname) + hostname = cast(str, kwargs.get("hostname", config.hostname)) owner = kwargs.get("owner", config.owner) - port = kwargs.get("port", config.port) + port = cast(int, kwargs.get("port", config.port)) self._reconnect_delay = kwargs.get("reconnect_delay", config.reconnect_delay) - self._timeout = kwargs.get("timeout", config.timeout) + self._timeout = cast(float, kwargs.get("timeout", config.timeout)) if hostname is None: raise ValueError("A hostname must be specified.") @@ -677,7 +677,7 @@ def _do_reconnect(self, finish_time: Optional[float]) -> None: time.sleep(max(0.0, delay)) self._reconnect() - def wait_until_ready(self, timeout: Optional[int] = None) -> None: + def wait_until_ready(self, timeout: Optional[float] = None) -> None: """ Block until the job is allocated and ready. Parameters diff --git a/spalloc_client/protocol_client.py b/spalloc_client/protocol_client.py index 00ce2ffff..5eaa375e6 100644 --- a/spalloc_client/protocol_client.py +++ b/spalloc_client/protocol_client.py @@ -19,7 +19,7 @@ import json import socket from types import TracebackType -from typing import cast, Dict, Literal, Optional, Type, Union +from typing import Any, cast, Dict, List, Literal, Optional, Type, Union from threading import current_thread, RLock, local, Thread from typing_extensions import Self @@ -281,7 +281,7 @@ def _send_json( def call(self, name: str, timeout: Optional[float], *args: Union[int, str, None], - **kwargs: JsonValue) -> JsonValue: + **kwargs: Any) -> JsonValue: """ Send a command to the server and return the reply. Parameters @@ -376,11 +376,12 @@ def wait_for_notification( # The bindings of the Spalloc protocol methods themselves; simplifies use # from IDEs. - def version(self, timeout: Optional[int] = None) -> str: + def version(self, timeout: Optional[float] = None) -> str: """ Ask what version of spalloc is running. """ return cast(str, self.call("version", timeout)) - def create_job(self, *args: int, **kwargs: str) -> int: + def create_job(self, *args: int, + **kwargs: Union[float, str, List[str], None]) -> int: """ Start a new job """ @@ -400,55 +401,55 @@ def job_keepalive(self, job_id: int, return cast(dict, self.call("job_keepalive", timeout, job_id)) def get_job_state(self, job_id: int, - timeout: Optional[int] = None) -> JsonObject: + timeout: Optional[float] = None) -> JsonObject: """Get the state for this job """ return cast(dict, self.call("get_job_state", timeout, job_id)) def get_job_machine_info(self, job_id: int, - timeout: Optional[int] = None) -> JsonObject: + timeout: Optional[float] = None) -> JsonObject: """ Get info for this job. """ return cast(dict, self.call("get_job_machine_info", timeout, job_id)) def power_on_job_boards(self, job_id: int, - timeout: Optional[int] = None) -> JsonObject: + timeout: Optional[float] = None) -> JsonObject: """ Turn on the power on the jobs boards. """ return cast(dict, self.call("power_on_job_boards", timeout, job_id)) def power_off_job_boards(self, job_id: int, - timeout: Optional[int] = None) -> JsonObject: + timeout: Optional[float] = None) -> JsonObject: """ Turn off the power on the jobs boards. """ return cast(dict, self.call("power_off_job_boards", timeout, job_id)) def destroy_job(self, job_id: int, reason: Optional[str] = None, - timeout: Optional[int] = None) -> JsonObject: + timeout: Optional[float] = None) -> JsonObject: """ Destroy the job """ return cast(dict, self.call("destroy_job", timeout, job_id, reason=reason)) def notify_job(self, job_id: Optional[int] = None, - timeout: Optional[int] = None) -> JsonObject: + timeout: Optional[float] = None) -> JsonObject: """ Turn on notification of job status changes. """ return cast(dict, self.call("notify_job", timeout, job_id)) def no_notify_job(self, job_id: Optional[int] = None, - timeout: Optional[int] = None) -> JsonObject: + timeout: Optional[float] = None) -> JsonObject: """ Turn off notification of job status changes. """ return cast(dict, self.call("no_notify_job", timeout, job_id)) def notify_machine(self, machine_name: Optional[str] = None, - timeout: Optional[int] = None) -> JsonObject: + timeout: Optional[float] = None) -> JsonObject: """ Turn on notification of machine status changes. """ return cast(dict, self.call("notify_machine", timeout, machine_name)) def no_notify_machine(self, machine_name: Optional[str] = None, - timeout: Optional[int] = None) -> JsonObject: + timeout: Optional[float] = None) -> JsonObject: """ Turn off notification of machine status changes. """ return cast(dict, self.call("no_notify_machine", timeout, machine_name)) - def list_jobs(self, timeout: Optional[int] = None) -> JsonObjectArray: + def list_jobs(self, timeout: Optional[float] = None) -> JsonObjectArray: """ Obtains a list of jobs currently running. """ return cast(list, self.call("list_jobs", timeout)) @@ -459,14 +460,14 @@ def list_machines(self, def get_board_position( self, machine_name: str, x: int, y: int, z: int, - timeout: Optional[int] = None) -> JsonObject: # pragma: no cover + timeout: Optional[float] = None) -> JsonObject: # pragma: no cover """ Gets the position of board x, y, z on the given machine. """ # pylint: disable=too-many-arguments return cast(dict, self.call("get_board_position", timeout, machine_name, x, y, z)) def get_board_at_position(self, machine_name: str, x: int, y: int, z: int, - timeout: Optional[int] = None + timeout: Optional[float] = None ) -> JsonObject: # pragma: no cover """ Gets the board x, y, z on the requested machine. """ # pylint: disable=too-many-arguments @@ -480,7 +481,7 @@ def get_board_at_position(self, machine_name: str, x: int, y: int, z: int, frozenset("job_id chip_x chip_y".split())]) def where_is(self, job_id: int, chip_x: int, chip_y: int, - timeout: Optional[int] = None) -> JsonObject: + timeout: Optional[float] = None) -> JsonObject: """ Reports where ion the Machine a job is running """ # Test for whether sane arguments are passed. return cast(dict, self.call("where_is", timeout, job_id=job_id, diff --git a/spalloc_client/scripts/job.py b/spalloc_client/scripts/job.py index 0388fb947..ec80177c6 100644 --- a/spalloc_client/scripts/job.py +++ b/spalloc_client/scripts/job.py @@ -94,7 +94,7 @@ def _state_name(mapping: JsonObject) -> str: return state.name # pylint: disable=no-member -def show_job_info(t: Terminal, client: ProtocolClient, timeout: Optional[int], +def show_job_info(t: Terminal, client: ProtocolClient, timeout: Optional[float], job_id: int) -> None: """ Print a human-readable overview of a Job's attributes. @@ -173,7 +173,7 @@ def show_job_info(t: Terminal, client: ProtocolClient, timeout: Optional[int], print(render_definitions(info)) -def watch_job(t: Terminal, client: ProtocolClient, timeout: Optional[int], +def watch_job(t: Terminal, client: ProtocolClient, timeout: Optional[float], job_id: int) -> int: """ Re-print a job's information whenever the job changes. @@ -207,7 +207,7 @@ def watch_job(t: Terminal, client: ProtocolClient, timeout: Optional[int], print("") -def power_job(client: ProtocolClient, timeout: Optional[int], +def power_job(client: ProtocolClient, timeout: Optional[float], job_id: int, power: bool) -> None: """ Power a job's boards on/off and wait for the action to complete. @@ -256,7 +256,7 @@ def power_job(client: ProtocolClient, timeout: Optional[int], f"job {job_id} in state {_state_name(state)}")) -def list_ips(client: ProtocolClient, timeout: Optional[int], +def list_ips(client: ProtocolClient, timeout: Optional[float], job_id: int) -> None: """ Print a CSV of board hostnames for all boards allocated to a job. @@ -289,7 +289,7 @@ def list_ips(client: ProtocolClient, timeout: Optional[int], print(f"{x},{y},{hostname}") -def destroy_job(client: ProtocolClient, timeout: Optional[int], +def destroy_job(client: ProtocolClient, timeout: Optional[float], job_id: int, reason: Optional[str] = None) -> None: """ Destroy a running job. diff --git a/spalloc_client/scripts/support.py b/spalloc_client/scripts/support.py index be4f51753..49e3a2a56 100644 --- a/spalloc_client/scripts/support.py +++ b/spalloc_client/scripts/support.py @@ -41,7 +41,7 @@ def exit(self) -> None: sys.exit(self._code) -def version_verify(client: ProtocolClient, timeout: Optional[int]) -> None: +def version_verify(client: ProtocolClient, timeout: Optional[float]) -> None: """ Verify that the current version of the client is compatible """