Skip to content

Commit

Permalink
fix types
Browse files Browse the repository at this point in the history
  • Loading branch information
Christian-B committed Jun 27, 2024
1 parent fa611b9 commit a29be98
Show file tree
Hide file tree
Showing 14 changed files with 32 additions and 30 deletions.
3 changes: 2 additions & 1 deletion spalloc_client/config.py
Original file line number Diff line number Diff line change
Expand Up @@ -82,6 +82,7 @@
import configparser
import os.path
import appdirs
from typing import Any, Dict, List, Optional

# The application name to use in config file names
_name = "spalloc"
Expand Down Expand Up @@ -138,7 +139,7 @@ def _read_none_or_str(parser, option):
return parser.get(SECTION, option)


def read_config(filenames=None):
def read_config(filenames: Optional[List[str]] = None) -> Dict[str, Any]:
""" Attempt to read local configuration files to determine spalloc client
settings.
Expand Down
3 changes: 1 addition & 2 deletions spalloc_client/job.py
Original file line number Diff line number Diff line change
Expand Up @@ -790,5 +790,4 @@ class _JobMachineInfoTuple(namedtuple("_JobMachineInfoTuple",
None if none allocated yet.
"""

# Python 3.4 Workaround: https://bugs.python.org/issue24931
__slots__ = tuple()
__slots__ = ()
17 changes: 10 additions & 7 deletions spalloc_client/scripts/alloc.py
Original file line number Diff line number Diff line change
Expand Up @@ -121,8 +121,8 @@
from spalloc_client.term import Terminal, render_definitions

# pylint: disable=invalid-name
arguments = None
t = None
arguments: Optional[argparse.Namespace] = None
t: Optional[Terminal] = None
_input = input # This is so we can monkey patch input during testing


Expand Down Expand Up @@ -231,7 +231,7 @@ def run_command(
logging.info("All board IPs listed in: %s", ip_file_filename)

# Make substitutions in command arguments
command = [arg.format(root_hostname,
commands = [arg.format(root_hostname,
hostname=root_hostname,
w=width,
width=width,
Expand All @@ -243,7 +243,7 @@ def run_command(

# NB: When using shell=True, commands should be given as a string rather
# than the usual list of arguments.
command = " ".join(map(quote, command))
command = " ".join(map(quote, commands))
p = subprocess.Popen(command, shell=True)

# Pass through keyboard interrupts
Expand All @@ -258,6 +258,7 @@ def info(msg: str):
"""
Writes a message to the terminal
"""
assert t is not None
if not arguments.quiet:
t.stream.write(f"{msg}\n")

Expand All @@ -273,6 +274,7 @@ def wait_for_job_ready(job: Job):
"""
Wait for it to become ready, keeping the user informed along the way
"""
assert t is not None
old_state = None
cur_state = job.state
try:
Expand Down Expand Up @@ -432,6 +434,7 @@ def run_job(job_args: List[str], job_kwargs: Dict[str, str],
"""
Run a job
"""
assert arguments is not None
# Reason for destroying the job
reason = None

Expand Down Expand Up @@ -470,14 +473,14 @@ def run_job(job_args: List[str], job_kwargs: Dict[str, str],
job.destroy(reason)


def _minzero(value: Optional[float]) -> Optional[float]:
def _minzero(value: float) -> Optional[float]:
"""
Makes sure a value is not negative.
Replaces a negative value with None
"""
return value if value >= 0.0 else None


def main(argv: List[str] = None):
def main(argv: Optional[List[str]] = None):
"""
The main method run
"""
Expand Down
8 changes: 4 additions & 4 deletions spalloc_client/scripts/job.py
Original file line number Diff line number Diff line change
Expand Up @@ -76,7 +76,7 @@
"""
import argparse
import sys
from typing import List
from typing import Dict

from spalloc_client import __version__, JobState
from spalloc_client.term import (
Expand Down Expand Up @@ -307,7 +307,7 @@ def __init__(self):
super().__init__()
self.parser = None

def get_job_id(self, client: ProtocolClient, args: List[str]):
def get_job_id(self, client: ProtocolClient, args: argparse.Namespace):
"""
get a job for the owner named in the args
"""
Expand All @@ -324,7 +324,7 @@ def get_job_id(self, client: ProtocolClient, args: List[str]):
raise Terminate(3, msg)
return job_ids[0]

def get_parser(self, cfg):
def get_parser(self, cfg: Dict[str, Any]) -> argparse.ArgumentParser:
parser = argparse.ArgumentParser(
description="Manage running jobs.")
parser.add_argument(
Expand Down Expand Up @@ -359,7 +359,7 @@ def get_parser(self, cfg):
self.parser = parser
return parser

def verify_arguments(self, args):
def verify_arguments(self, args: argparse.Namespace):
if args.job_id is None and args.owner is None:
self.parser.error("job ID (or --owner) not specified")

Expand Down
6 changes: 3 additions & 3 deletions spalloc_client/scripts/machine.py
Original file line number Diff line number Diff line change
Expand Up @@ -220,8 +220,8 @@ def __init__(self):
super().__init__()
self.parser = None

def get_and_display_machine_info(
self, client: ProtocolClient, args: List[object], t: Terminal):
def get_and_display_machine_info(self, client: ProtocolClient,
args: argparse.Namespace, t: Terminal):
""" Gets and displays info for the machine(s) """
# Get all information
machines = client.list_machines(timeout=args.timeout)
Expand Down Expand Up @@ -264,7 +264,7 @@ def one_shot(self, client: ProtocolClient, args: List[object]):
# Get all information and display accordingly
self.get_and_display_machine_info(client, args, t)

def recurring(self, client: ProtocolClient, args: List[object]):
def recurring(self, client: ProtocolClient, args: argparse.Namespace):
"""
Repeatedly display the machine info
"""
Expand Down
8 changes: 4 additions & 4 deletions spalloc_client/scripts/ps.py
Original file line number Diff line number Diff line change
Expand Up @@ -26,15 +26,15 @@
"""
import argparse
import sys
from typing import List

from spalloc_client import __version__, JobState, ProtocolClient
from spalloc_client.term import Terminal, render_table
from spalloc_client._utils import render_timestamp
from spinn_utilities.typing.json import JsonObject
from .support import Script


def render_job_list(t, jobs, args):
def render_job_list(t: Terminal, jobs: JsonObject, args: argparse.Namespace):
""" Return a human-readable process listing.
Parameters
Expand Down Expand Up @@ -132,13 +132,13 @@ def get_parser(self, cfg):
help="list only jobs belonging to a particular owner")
return parser

def one_shot(self, client: ProtocolClient, args: List[object]):
def one_shot(self, client: ProtocolClient, args: argparse.Namespace):
""" Gets info on the job list once. """
t = Terminal(stream=sys.stderr)
jobs = client.list_jobs(timeout=args.timeout)
print(render_job_list(t, jobs, args))

def recurring(self, client: ProtocolClient, args: List[object]):
def recurring(self, client: ProtocolClient, args: argparse.Namespace):
""" Repeatedly gets info on the job list. """
client.notify_job(timeout=args.timeout)
t = Terminal(stream=sys.stderr)
Expand Down
2 changes: 1 addition & 1 deletion tests/conftest.py
Original file line number Diff line number Diff line change
Expand Up @@ -17,7 +17,7 @@
import threading
import tempfile
import pytest
from mock import Mock
from mock import Mock # type: ignore[import]
from spalloc_client import ProtocolClient
from spalloc_client.config import SEARCH_PATH
from .common import MockServer
Expand Down
3 changes: 1 addition & 2 deletions tests/scripts/test_alloc.py
Original file line number Diff line number Diff line change
Expand Up @@ -15,11 +15,10 @@
import os
import tempfile
import pytest
from mock import Mock, PropertyMock
from mock import Mock, PropertyMock # type: ignore[import]
from spalloc_client import JobState, JobDestroyedError
from spalloc_client.scripts.alloc import (
write_ips_to_csv, print_info, run_command, main)
# pylint: disable=redefined-outer-name, unused-argument


@pytest.yield_fixture
Expand Down
2 changes: 1 addition & 1 deletion tests/scripts/test_job_script.py
Original file line number Diff line number Diff line change
Expand Up @@ -14,7 +14,7 @@

import datetime
import pytest
from mock import Mock, MagicMock
from mock import Mock, MagicMock # type: ignore[import]
from spalloc_client import JobState, ProtocolError
from spalloc_client.term import Terminal
from spalloc_client.scripts.job import (
Expand Down
2 changes: 1 addition & 1 deletion tests/scripts/test_machine.py
Original file line number Diff line number Diff line change
Expand Up @@ -13,7 +13,7 @@
# limitations under the License.

import pytest
from mock import Mock, MagicMock
from mock import Mock, MagicMock # type: ignore[import]
from spalloc_client.term import Terminal
from spalloc_client.scripts.machine import (
main, generate_keys, list_machines, show_machine)
Expand Down
2 changes: 1 addition & 1 deletion tests/scripts/test_ps.py
Original file line number Diff line number Diff line change
Expand Up @@ -14,7 +14,7 @@

import collections
import datetime
from mock import Mock, MagicMock
from mock import Mock, MagicMock# type: ignore[import]
import pytest
from spalloc_client.scripts.ps import main, render_job_list
from spalloc_client.scripts.support import (
Expand Down
2 changes: 1 addition & 1 deletion tests/scripts/test_where_is.py
Original file line number Diff line number Diff line change
Expand Up @@ -13,7 +13,7 @@
# limitations under the License.

import pytest
from mock import Mock, MagicMock
from mock import Mock, MagicMock # type: ignore[import]
from spalloc_client.scripts.where_is import main
from spalloc_client.scripts.support import (
VERSION_RANGE_START, VERSION_RANGE_STOP)
Expand Down
2 changes: 1 addition & 1 deletion tests/test_job.py
Original file line number Diff line number Diff line change
Expand Up @@ -15,7 +15,7 @@
import time
from threading import Thread, Event
import pytest
from mock import Mock
from mock import Mock # type: ignore[import]
from spalloc_client import (
Job, JobState, JobDestroyedError, ProtocolTimeoutError)
from spalloc_client._keepalive_process import keep_job_alive
Expand Down
2 changes: 1 addition & 1 deletion tests/test_protocol_client.py
Original file line number Diff line number Diff line change
Expand Up @@ -17,7 +17,7 @@
import time
import logging
import pytest
from mock import Mock
from mock import Mock # type: ignore[import]
from spalloc_client import (
ProtocolClient, SpallocServerException, ProtocolTimeoutError,
ProtocolError)
Expand Down

0 comments on commit a29be98

Please sign in to comment.