Skip to content

Commit

Permalink
flake8
Browse files Browse the repository at this point in the history
  • Loading branch information
Christian-B committed Nov 26, 2024
1 parent f89f1b9 commit c508187
Show file tree
Hide file tree
Showing 8 changed files with 21 additions and 16 deletions.
2 changes: 1 addition & 1 deletion spalloc_client/_keepalive_process.py
Original file line number Diff line number Diff line change
Expand Up @@ -36,7 +36,7 @@ def wait_for_exit(stop_event: threading.Event) -> None:


def keep_job_alive(
hostname: str, port: int, job_id: int, keepalive_period:float,
hostname: str, port: int, job_id: int, keepalive_period: float,
timeout: float, reconnect_delay: float,
stop_event: threading.Event) -> None:
""" Keeps a Spalloc job alive. Run as a separate process to the main\
Expand Down
3 changes: 2 additions & 1 deletion spalloc_client/job.py
Original file line number Diff line number Diff line change
Expand Up @@ -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[int] = None) -> None:
""" Block until the job is allocated and ready.
Parameters
Expand Down Expand Up @@ -740,6 +740,7 @@ def where_is_machine(
[cabinet, frame, board] = cast(list, result['physical'])
return (cast(int, cabinet), cast(int, frame), cast(int, board))


class StateChangeTimeoutError(Exception):
""" Thrown when a state change takes too long to occur.
"""
Expand Down
13 changes: 7 additions & 6 deletions spalloc_client/protocol_client.py
Original file line number Diff line number Diff line change
Expand Up @@ -185,7 +185,7 @@ def _connect(self, timeout: Optional[float]) -> socket.socket:
# Pass on the exception
raise

def _close(self, key: Optional[Thread]=None) -> None:
def _close(self, key: Optional[Thread] = None) -> None:
if key is None:
key = current_thread()
with self._socks_lock:
Expand All @@ -208,7 +208,7 @@ def close(self) -> None:
self._close(key)
self._local = _ProtocolThreadLocal()

def _recv_json(self, timeout:Optional[float]=None) -> JsonObject:
def _recv_json(self, timeout: Optional[float] = None) -> JsonObject:
""" Receive a line of JSON from the server.
Parameters
Expand Down Expand Up @@ -249,7 +249,7 @@ def _recv_json(self, timeout:Optional[float]=None) -> JsonObject:
return json.loads(line.decode("utf-8"))

def _send_json(
self, obj: JsonObject, timeout:Optional[float] = None) -> None:
self, obj: JsonObject, timeout: Optional[float] = None) -> None:
""" Attempt to send a line of JSON to the server.
Parameters
Expand Down Expand Up @@ -278,7 +278,7 @@ def _send_json(
except socket.timeout as e:
raise ProtocolTimeoutError("send timed out.") from e

def call(self, name:str, timeout: Optional[float] = None,
def call(self, name: str, timeout: Optional[float] = None,
*args: Union[int, str, None],
**kwargs: JsonValue) -> JsonValue:
""" Send a command to the server and return the reply.
Expand Down Expand Up @@ -330,7 +330,7 @@ def call(self, name:str, timeout: Optional[float] = None,
raise ProtocolError(str(e)) from e

def wait_for_notification(
self, timeout:Optional[float] = None) -> Optional[JsonObject]:
self, timeout: Optional[float] = None) -> Optional[JsonObject]:
""" Return the next notification to arrive.
Parameters
Expand Down Expand Up @@ -387,7 +387,7 @@ def create_job(self, *args: int, **kwargs: str) -> int:
if "owner" not in kwargs:
raise SpallocServerException(
"owner must be specified for all jobs.")
return cast(int, self.call("create_job", None,*args, **kwargs))
return cast(int, self.call("create_job", None, *args, **kwargs))

def job_keepalive(self, job_id: int,
timeout: Optional[float] = None) -> JsonObject:
Expand Down Expand Up @@ -423,6 +423,7 @@ def destroy_job(self, job_id: int, reason: Optional[str] = None,
""" 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:
""" Turn on notification of job status changes. """
Expand Down
8 changes: 5 additions & 3 deletions spalloc_client/scripts/job.py
Original file line number Diff line number Diff line change
Expand Up @@ -90,7 +90,9 @@


def _state_name(mapping: JsonObject) -> str:
return JobState(cast(int, mapping["state"])).name # pylint: disable=no-member
state = JobState(cast(int, mapping["state"]))
return state.name # pylint: disable=no-member


def show_job_info(t: Terminal, client: ProtocolClient, timeout: Optional[int],
job_id: int) -> None:
Expand Down Expand Up @@ -254,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[int],
job_id: int) -> None:
""" Print a CSV of board hostnames for all boards allocated to a job.
Expand Down Expand Up @@ -288,7 +290,7 @@ def list_ips(client: ProtocolClient, timeout:Optional[int],


def destroy_job(client: ProtocolClient, timeout: Optional[int],
job_id:int, reason:Optional[str] = None) -> None:
job_id: int, reason: Optional[str] = None) -> None:
""" Destroy a running job.
Parameters
Expand Down
1 change: 1 addition & 0 deletions spalloc_client/scripts/machine.py
Original file line number Diff line number Diff line change
Expand Up @@ -100,6 +100,7 @@ def list_machines(t: Terminal, machines: JsonObjectArray,

print(render_table(table))


def _get_machine(machines: JsonObjectArray, machine_name: str) -> JsonObject:
for machine in machines:
if machine["name"] == machine_name:
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 @@ -143,7 +143,8 @@ def get_parser(self, cfg: Dict[str, Any]) -> argparse.ArgumentParser:
help="list only jobs belonging to a particular owner")
return parser

def one_shot(self, client: ProtocolClient, args: argparse.Namespace) -> None:
def one_shot(self, client: ProtocolClient,
args: argparse.Namespace) -> None:
""" Gets info on the job list once. """
t = Terminal(stream=sys.stderr)
jobs = client.list_jobs(timeout=args.timeout)
Expand Down
1 change: 0 additions & 1 deletion spalloc_client/scripts/support.py
Original file line number Diff line number Diff line change
Expand Up @@ -122,4 +122,3 @@ def __call__(self, argv: Optional[str] = None) -> int:
except Terminate as t:
t.exit()
return 1

6 changes: 3 additions & 3 deletions spalloc_client/term.py
Original file line number Diff line number Diff line change
Expand Up @@ -23,7 +23,7 @@
from functools import partial
from typing import (
Callable, Dict, Iterable, List, Optional, TextIO, Tuple, Union)
from typing_extensions import Self, TypeAlias
from typing_extensions import TypeAlias

# pylint: disable=wrong-spelling-in-docstring

Expand Down Expand Up @@ -155,7 +155,7 @@ def update(self, string: str = "", start_again: bool = False) -> str:
# Restore to previous location and clear line.
return "".join((self("\0338\033[K"), str(string)))

def set_attrs(self, attrs:List = []) -> str:
def set_attrs(self, attrs: List = []) -> str:
""" Construct an ANSI control sequence which sets the given attribute\
numbers.
"""
Expand Down Expand Up @@ -379,7 +379,7 @@ def _board_to_cartesian(x: int, y: int, z: int) -> Tuple[int, int]:

def render_boards(
board_groups: List[Tuple[List[Tuple[int, int, int]], str,
Tuple[str, str, str], Tuple[str, str, str]]],
Tuple[str, str, str], Tuple[str, str, str]]],
dead_links: List = [],
dead_edge: Tuple[str, str, str] = ("XXX", "X", "X"),
blank_label: str = " ",
Expand Down

0 comments on commit c508187

Please sign in to comment.