Skip to content

Commit

Permalink
Merge pull request #386 from SpiNNakerManchester/overrides_check
Browse files Browse the repository at this point in the history
Overrides check
  • Loading branch information
Christian-B authored Jan 15, 2024
2 parents 27fdd40 + 8c24a05 commit 6c58d1d
Show file tree
Hide file tree
Showing 14 changed files with 48 additions and 35 deletions.
4 changes: 2 additions & 2 deletions spinnman/connections/udp_packet_connections/bmp_connection.py
Original file line number Diff line number Diff line change
Expand Up @@ -13,7 +13,7 @@
# limitations under the License.

import struct
from typing import Sequence, Tuple
from typing import Optional, Sequence, Tuple
from spinn_utilities.overrides import overrides
from .udp_connection import UDPConnection
from spinnman.constants import SCP_SCAMP_PORT
Expand Down Expand Up @@ -74,7 +74,7 @@ def get_scp_data(self, scp_request: AbstractSCPRequest) -> bytes:
return _TWO_SKIP.pack() + scp_request.bytestring

@overrides(AbstractSCPConnection.receive_scp_response)
def receive_scp_response(self, timeout=1.0) -> Tuple[
def receive_scp_response(self, timeout: Optional[float] = 1.0) -> Tuple[
SCPResult, int, bytes, int]:
data = self.receive(timeout)
result, sequence = _TWO_SHORTS.unpack_from(data, 10)
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -13,6 +13,7 @@
# limitations under the License.
from spinn_utilities.overrides import overrides
from spinnman.messages.eieio import AbstractEIEIOMessage
from spinnman.messages.eieio.command_messages import EIEIOCommandHeader


class EIEIOCommandMessage(AbstractEIEIOMessage):
Expand All @@ -24,7 +25,8 @@ class EIEIOCommandMessage(AbstractEIEIOMessage):
"_eieio_command_header",
"_offset")

def __init__(self, eieio_command_header, data=None, offset=0):
def __init__(self, eieio_command_header: EIEIOCommandHeader, data=None,
offset=0):
"""
:param EIEIOCommandHeader eieio_command_header:
The header of the message
Expand All @@ -40,7 +42,7 @@ def __init__(self, eieio_command_header, data=None, offset=0):

@property
@overrides(AbstractEIEIOMessage.eieio_header)
def eieio_header(self):
def eieio_header(self) -> EIEIOCommandHeader:
"""
:rtype: EIEIOCommandHeader
"""
Expand All @@ -60,7 +62,7 @@ def from_bytestring(command_header, data, offset):

@property
@overrides(AbstractEIEIOMessage.bytestring)
def bytestring(self):
def bytestring(self) -> bytes:
return self._eieio_command_header.bytestring

@staticmethod
Expand Down
2 changes: 1 addition & 1 deletion spinnman/messages/scp/impl/check_ok_response.py
Original file line number Diff line number Diff line change
Expand Up @@ -37,7 +37,7 @@ def __init__(self, operation: str, command):
self._command = command

@overrides(AbstractSCPResponse.read_data_bytestring)
def read_data_bytestring(self, data: bytes, offset: int) -> None:
def read_data_bytestring(self, data: bytes, offset: int):
result = self.scp_response_header.result
if result != SCPResult.RC_OK:
raise SpinnmanUnexpectedResponseCodeException(
Expand Down
2 changes: 1 addition & 1 deletion spinnman/messages/scp/impl/sdram_alloc.py
Original file line number Diff line number Diff line change
Expand Up @@ -42,7 +42,7 @@ def __init__(self, size: int):
self._base_address: Optional[int] = None

@overrides(AbstractSCPResponse.read_data_bytestring)
def read_data_bytestring(self, data, offset):
def read_data_bytestring(self, data: bytes, offset: int):
result = self.scp_response_header.result
if result != SCPResult.RC_OK:
raise SpinnmanUnexpectedResponseCodeException(
Expand Down
2 changes: 1 addition & 1 deletion spinnman/processes/get_exclude_cpu_info_process.py
Original file line number Diff line number Diff line change
Expand Up @@ -30,5 +30,5 @@ def __init__(self, connection_selector: ConnectionSelector,
self.__states = states

@overrides(GetCPUInfoProcess._is_desired)
def _is_desired(self, cpu_info: CPUInfo):
def _is_desired(self, cpu_info: CPUInfo) -> bool:
return cpu_info.state not in self.__states
2 changes: 1 addition & 1 deletion spinnman/processes/get_include_cpu_info_process.py
Original file line number Diff line number Diff line change
Expand Up @@ -35,5 +35,5 @@ def __init__(self, connection_selector: ConnectionSelector,
self.__states = states

@overrides(GetCPUInfoProcess._is_desired)
def _is_desired(self, cpu_info: CPUInfo):
def _is_desired(self, cpu_info: CPUInfo) -> bool:
return cpu_info.state in self.__states
26 changes: 17 additions & 9 deletions spinnman/spalloc/spalloc_client.py
Original file line number Diff line number Diff line change
Expand Up @@ -212,8 +212,11 @@ def create_job_rect(

@overrides(AbstractSpallocClient.create_job_board)
def create_job_board(
self, triad=None, physical=None, ip_address=None,
machine_name=None, keepalive=45) -> SpallocJob:
self, triad: Optional[Tuple[int, int, int]] = None,
physical: Optional[Tuple[int, int, int]] = None,
ip_address: Optional[str] = None,
machine_name: Optional[str] = None,
keepalive: int = 45) -> SpallocJob:
board: JsonObject
if triad:
x, y, z = triad
Expand All @@ -233,8 +236,13 @@ def create_job_board(

@overrides(AbstractSpallocClient.create_job_rect_at_board)
def create_job_rect_at_board(
self, width, height, triad=None, physical=None, ip_address=None,
machine_name=None, keepalive=45, max_dead_boards=0):
self, width: int, height: int,
triad: Optional[Tuple[int, int, int]] = None,
physical: Optional[Tuple[int, int, int]] = None,
ip_address: Optional[str] = None,
machine_name: Optional[str] = None, keepalive: int = 45,
max_dead_boards: int = 0) -> SpallocJob:
board: JsonObject
if triad:
x, y, z = triad
board = {"x": int(x), "y": int(y), "z": int(z)}
Expand Down Expand Up @@ -510,7 +518,7 @@ def __init__(self, session: Session, job_handle: str):
self.__proxy_ping: Optional[_ProxyPing] = None

@overrides(SpallocJob.get_session_credentials_for_db)
def get_session_credentials_for_db(self):
def get_session_credentials_for_db(self) -> Mapping[Tuple[str, str], str]:
config = {}
config["SPALLOC", "service uri"] = self._service_url
config["SPALLOC", "job uri"] = self._url
Expand Down Expand Up @@ -634,7 +642,7 @@ def wait_until_ready(self, timeout: Optional[int] = None,
raise SpallocException("job was unexpectedly destroyed")

@overrides(SpallocJob.destroy)
def destroy(self, reason: str = "finished") -> None:
def destroy(self, reason: str = "finished"):
if self.__keepalive_handle:
self.__keepalive_handle.close()
self.__keepalive_handle = None
Expand Down Expand Up @@ -871,7 +879,7 @@ def __init__(
super().__init__(ws, receiver)

@overrides(_ProxiedConnection._open_connection)
def _open_connection(self):
def _open_connection(self) -> int:
handle, = self._call(
ProxyProtocol.OPEN, _open_req, _open_close_res,
*self.__connect_args)
Expand All @@ -882,7 +890,7 @@ def is_connected(self) -> bool:
return self._connected

@overrides(Connection.close)
def close(self):
def close(self) -> None:
self._close()

@overrides(SpallocProxiedConnection.send)
Expand Down Expand Up @@ -941,7 +949,7 @@ def close(self) -> None:
self._close()

@overrides(SpallocProxiedConnection.send)
def send(self, data: bytes) -> None:
def send(self, data: bytes):
self._throw_if_closed()
raise IOError("socket is not open for sending")

Expand Down
2 changes: 1 addition & 1 deletion spinnman/spalloc/spalloc_eieio_connection.py
Original file line number Diff line number Diff line change
Expand Up @@ -45,7 +45,7 @@ class SpallocEIEIOConnection(
__slots__ = ()

@overrides(EIEIOConnection.send_eieio_message)
def send_eieio_message(self, eieio_message):
def send_eieio_message(self, eieio_message: AbstractEIEIOMessage):
# Not normally used, as packets need headers to go to SpiNNaker
self.send(eieio_message.bytestring)

Expand Down
2 changes: 1 addition & 1 deletion spinnman/spalloc/spalloc_eieio_listener.py
Original file line number Diff line number Diff line change
Expand Up @@ -57,7 +57,7 @@ def receive_eieio_message(
return read_eieio_data_message(data, 0)

@overrides(SpallocProxiedConnection.send)
def send(self, data):
def send(self, data: bytes):
"""
.. note::
This class does not allow sending.
Expand Down
4 changes: 2 additions & 2 deletions spinnman/spalloc/spalloc_job.py
Original file line number Diff line number Diff line change
Expand Up @@ -34,7 +34,7 @@ class SpallocJob(object, metaclass=AbstractBase):
__slots__ = ()

@abstractmethod
def get_state(self, wait_for_change=False) -> SpallocState:
def get_state(self, wait_for_change: bool = False) -> SpallocState:
"""
Get the current state of the machine.
Expand Down Expand Up @@ -183,7 +183,7 @@ def destroy(self, reason: str = "finished"):
raise NotImplementedError()

@abstractmethod
def keepalive(self):
def keepalive(self) -> None:
"""
Signal the job that we want it to stay alive for a while longer.
"""
Expand Down
7 changes: 4 additions & 3 deletions spinnman/spalloc/spalloc_scp_connection.py
Original file line number Diff line number Diff line change
Expand Up @@ -55,8 +55,8 @@ def send_sdp_message(self, sdp_message: SDPMessage):
self.send(_TWO_SKIP + sdp_message.bytestring)

@overrides(SCAMPConnection.receive_scp_response)
def receive_scp_response(
self, timeout=1.0) -> Tuple[SCPResult, int, bytes, int]:
def receive_scp_response(self, timeout: Optional[float] = 1.0) -> Tuple[
SCPResult, int, bytes, int]:
data = self.receive(timeout)
result, sequence = _TWO_SHORTS.unpack_from(data, 10)
return SCPResult(result), sequence, data, 2
Expand All @@ -67,7 +67,8 @@ def send_scp_request(self, scp_request: AbstractSCPRequest):

@overrides(SCAMPConnection.get_scp_data)
def get_scp_data(
self, scp_request: AbstractSCPRequest, x=None, y=None) -> bytes:
self, scp_request: AbstractSCPRequest,
x: Optional[int] = None, y: Optional[int] = None) -> bytes:
if x is None:
x = self.chip_x
if y is None:
Expand Down
6 changes: 3 additions & 3 deletions spinnman/transceiver/base_transceiver.py
Original file line number Diff line number Diff line change
Expand Up @@ -25,7 +25,7 @@
import time
from typing import (
BinaryIO, Collection, Dict, FrozenSet, Iterable, Iterator, List, Optional,
Sequence, Tuple, TypeVar, Union, cast)
Sequence, Set, Tuple, TypeVar, Union, cast)
from spinn_utilities.abstract_base import (
AbstractBase, abstractmethod)
from spinn_utilities.config_holder import get_config_bool
Expand Down Expand Up @@ -422,7 +422,7 @@ def add_scamp_connections(self, connections: Dict[XY, str]):
self._scamp_connections)

@overrides(Transceiver.get_connections)
def get_connections(self):
def get_connections(self) -> Set[Connection]:
return self._all_connections

def _get_machine_dimensions(self) -> MachineDimensions:
Expand Down Expand Up @@ -1232,7 +1232,7 @@ def get_tags(self, connection: Optional[SCAMPConnection] = None

@overrides(Transceiver.malloc_sdram)
def malloc_sdram(
self, x: int, y: int, size: int, app_id: int, tag=0) -> int:
self, x: int, y: int, size: int, app_id: int, tag: int = 0) -> int:
try:
process = MallocSDRAMProcess(self._scamp_connection_selector)
process.malloc_sdram(x, y, size, app_id, tag)
Expand Down
9 changes: 5 additions & 4 deletions spinnman/transceiver/mockable_transceiver.py
Original file line number Diff line number Diff line change
Expand Up @@ -16,14 +16,15 @@

from typing import (
BinaryIO, Collection, Dict, FrozenSet, Iterable,
List, Optional, Tuple, Union)
List, Optional, Set, Tuple, Union)
from spinn_utilities.overrides import overrides
from spinn_utilities.progress_bar import ProgressBar
from spinn_utilities.typing.coords import XY
from spinn_machine import (
CoreSubsets, FixedRouteEntry, Machine, MulticastRoutingEntry)
from spinn_machine.tags import AbstractTag, IPTag, ReverseIPTag
from spinnman.data import SpiNNManDataView
from spinnman.connections.abstract_classes import Connection
from spinnman.connections.udp_packet_connections import BMPConnection
from spinnman.connections.udp_packet_connections import (
SCAMPConnection, SDPConnection)
Expand Down Expand Up @@ -69,7 +70,7 @@ def get_machine_details(self) -> Machine:
return SpiNNManDataView.get_machine()

@overrides(Transceiver.get_connections)
def get_connections(self):
def get_connections(self) -> Set[Connection]:
raise NotImplementedError("Needs to be mocked")

@overrides(Transceiver.get_cpu_infos)
Expand All @@ -80,7 +81,7 @@ def get_cpu_infos(
raise NotImplementedError("Needs to be mocked")

@overrides(Transceiver.get_clock_drift)
def get_clock_drift(self, x, y):
def get_clock_drift(self, x: int, y: int) -> float:
raise NotImplementedError("Needs to be mocked")

@overrides(Transceiver.read_user)
Expand Down Expand Up @@ -196,7 +197,7 @@ def get_tags(self, connection: Optional[SCAMPConnection] = None

@overrides(Transceiver.malloc_sdram)
def malloc_sdram(
self, x: int, y: int, size: int, app_id: int, tag=0) -> int:
self, x: int, y: int, size: int, app_id: int, tag: int = 0) -> int:
raise NotImplementedError("Needs to be mocked")

@overrides(Transceiver.load_multicast_routes)
Expand Down
7 changes: 4 additions & 3 deletions spinnman/transceiver/transceiver.py
Original file line number Diff line number Diff line change
Expand Up @@ -16,13 +16,14 @@

from typing import (
BinaryIO, Collection, Dict, FrozenSet, Iterable,
List, Optional, Tuple, Union)
List, Optional, Set, Tuple, Union)
from spinn_utilities.abstract_base import abstractmethod
from spinn_utilities.progress_bar import ProgressBar
from spinn_utilities.typing.coords import XY
from spinn_machine import (
CoreSubsets, FixedRouteEntry, Machine, MulticastRoutingEntry)
from spinn_machine.tags import AbstractTag, IPTag, ReverseIPTag
from spinnman.connections.abstract_classes import Connection
from spinnman.connections.udp_packet_connections import (
SCAMPConnection, SDPConnection)
from spinnman.messages.scp.enums import Signal
Expand Down Expand Up @@ -111,7 +112,7 @@ def add_scamp_connections(self, connections: Dict[XY, str]):
raise NotImplementedError("abstractmethod")

@abstractmethod
def get_connections(self):
def get_connections(self) -> Set[Connection]:
"""
Get the currently known connections to the board, made up of those
passed in to the transceiver and those that are discovered during
Expand Down Expand Up @@ -732,7 +733,7 @@ def get_tags(self, connection: Optional[SCAMPConnection] = None

@abstractmethod
def malloc_sdram(
self, x: int, y: int, size: int, app_id: int, tag=0) -> int:
self, x: int, y: int, size: int, app_id: int, tag: int = 0) -> int:
"""
Allocates a chunk of SDRAM on a chip on the machine.
Expand Down

0 comments on commit 6c58d1d

Please sign in to comment.