From 7691d3ced892f80aa0ee374f2697b11b557b67c0 Mon Sep 17 00:00:00 2001 From: "Christian Y. Brenninkmeijer" Date: Tue, 29 Oct 2024 07:58:47 +0000 Subject: [PATCH] typing --- .../abstract_scp_connection.py | 2 +- spinnman/connections/connection_listener.py | 6 ++-- spinnman/connections/scp_request_pipeline.py | 28 +++++++++++-------- .../udp_packet_connections/bmp_connection.py | 2 +- .../udp_packet_connections/boot_connection.py | 4 +-- .../eieio_connection.py | 4 +-- .../ip_address_connection.py | 6 ++-- .../scamp_connection.py | 2 +- .../udp_packet_connections/sdp_connection.py | 2 +- .../udp_packet_connections/udp_connection.py | 6 ++-- spinnman/exceptions.py | 8 +++--- spinnman/extended/de_alloc_sdram_process.py | 12 ++++---- spinnman/extended/read_adc.py | 2 +- .../extended/write_memory_flood_process.py | 9 +++--- spinnman/messages/scp/impl/app_copy_run.py | 2 +- spinnman/messages/scp/impl/app_stop.py | 2 +- .../messages/scp/impl/check_ok_response.py | 7 +++-- spinnman/messages/scp/impl/iptag_set.py | 5 +++- .../abstract_multi_connection_process.py | 6 ++-- .../processes/application_copy_run_process.py | 4 +-- spinnman/processes/application_run_process.py | 2 +- spinnman/processes/get_cpu_info_process.py | 3 +- spinnman/processes/get_heap_process.py | 8 +++--- spinnman/processes/get_machine_process.py | 23 +++++++++------ .../processes/get_n_cores_in_state_process.py | 15 ++++++---- spinnman/processes/get_routes_process.py | 4 +-- spinnman/processes/get_tags_process.py | 7 +++-- spinnman/processes/get_version_process.py | 2 +- .../load_fixed_route_routing_entry_process.py | 2 +- spinnman/processes/load_routes_process.py | 5 ++-- spinnman/processes/malloc_sdram_process.py | 5 ++-- .../read_fixed_route_routing_entry_process.py | 2 +- spinnman/processes/read_iobuf_process.py | 13 +++++---- spinnman/processes/read_memory_process.py | 2 +- .../read_router_diagnostics_process.py | 6 ++-- .../processes/send_single_command_process.py | 2 +- spinnman/utilities/utility_functions.py | 7 +++-- 37 files changed, 128 insertions(+), 99 deletions(-) diff --git a/spinnman/connections/abstract_classes/abstract_scp_connection.py b/spinnman/connections/abstract_classes/abstract_scp_connection.py index 8b05f40a4..b81471614 100644 --- a/spinnman/connections/abstract_classes/abstract_scp_connection.py +++ b/spinnman/connections/abstract_classes/abstract_scp_connection.py @@ -26,7 +26,7 @@ class AbstractSCPConnection(Connection, metaclass=AbstractBase): __slots__ = () @abstractmethod - def is_ready_to_receive(self, timeout: float = 0): + def is_ready_to_receive(self, timeout: float = 0) -> bool: """ Determines if there is an SCP packet to be read without blocking. diff --git a/spinnman/connections/connection_listener.py b/spinnman/connections/connection_listener.py index 01b51f388..f0ea79cac 100644 --- a/spinnman/connections/connection_listener.py +++ b/spinnman/connections/connection_listener.py @@ -58,7 +58,7 @@ def __init__(self, connection: Listenable[T], self.__done = False self.__callbacks: List[Callable[[T], None]] = [] - def __run_step(self, handler: Callable[[], T]): + def __run_step(self, handler: Callable[[], T]) -> None: """ :param ~collections.abc.Callable handler: """ @@ -69,7 +69,7 @@ def __run_step(self, handler: Callable[[], T]): callback, message) future.add_done_callback(self.__done_callback) - def __done_callback(self, future: Future[None]): + def __done_callback(self, future: Future[None]) -> None: """ :param ~concurrent.futures.Future future: """ @@ -94,7 +94,7 @@ def run(self) -> None: logger.warning("problem when dispatching message", exc_info=True) - def add_callback(self, callback: Callable[[T], None]): + def add_callback(self, callback: Callable[[T], None]) -> None: """ Add a callback to be called when a message is received. diff --git a/spinnman/connections/scp_request_pipeline.py b/spinnman/connections/scp_request_pipeline.py index f234cf87c..dfe972bfb 100644 --- a/spinnman/connections/scp_request_pipeline.py +++ b/spinnman/connections/scp_request_pipeline.py @@ -16,7 +16,8 @@ from threading import RLock import time from types import TracebackType -from typing import Callable, Dict, Generic, List, Optional, TypeVar, cast +from typing import (Callable, Dict, Generic, List, Optional, Set, TypeVar, + cast) from typing_extensions import TypeAlias from spinnman.messages.scp.enums import SCPResult from spinnman.exceptions import SpinnmanTimeoutException, SpinnmanIOException @@ -77,10 +78,11 @@ class SCPRequestPipeLine(Generic[R]): "_retries", "_send_time") - def __init__(self, connection: SCAMPConnection, n_channels=1, - intermediate_channel_waits=0, - n_retries=N_RETRIES, packet_timeout=SCP_TIMEOUT, - non_fail_retry_codes=None): + def __init__(self, connection: SCAMPConnection, n_channels: int = 1, + intermediate_channel_waits: int = 0, + n_retries: int = N_RETRIES, + packet_timeout: float = SCP_TIMEOUT, + non_fail_retry_codes: Optional[Set[SCPResult]] = None): """ :param SCAMPConnection connection: The connection over which the communication is to take place @@ -134,10 +136,11 @@ def __init__(self, connection: SCAMPConnection, n_channels=1, # The number of packets that have been resent self._n_resent = 0 self._n_retry_code_resent = 0 - self._non_fail_retry_codes = non_fail_retry_codes - if self._non_fail_retry_codes is None: + self._non_fail_retry_codes: Set[SCPResult] + if non_fail_retry_codes is None: self._non_fail_retry_codes = set() - + else: + self._non_fail_retry_codes = non_fail_retry_codes # self._token_bucket = TokenBucket(43750, 4375000) # self._token_bucket = TokenBucket(3408, 700000) @@ -159,7 +162,7 @@ def __get_next_sequence_number() -> int: def send_request( self, request: AbstractSCPRequest[R], callback: Optional[CB], - error_callback: ECB): + error_callback: ECB) -> None: """ Add an SCP request to the set to be sent. @@ -260,7 +263,7 @@ def _remove_record(self, seq: int) -> None: del self._error_callbacks[seq] del self._retry_reason[seq] - def _single_retrieve(self, timeout: float): + def _single_retrieve(self, timeout: float) -> None: # Receive the next response result, seq, raw_data, offset = \ self._connection.receive_scp_response(timeout) @@ -320,7 +323,8 @@ def _handle_receive_timeout(self) -> None: for seq in to_remove: self._remove_record(seq) - def _resend(self, seq: int, request_sent, reason: str): + def _resend(self, seq: int, request_sent: AbstractSCPRequest, + reason: str) -> None: if self._retries[seq] <= 0: # Report timeouts as timeout exception @@ -346,7 +350,7 @@ def _resend(self, seq: int, request_sent, reason: str): self._connection.send(self._request_data[seq]) self._n_resent += 1 - def _do_retrieve(self, n_packets: int, timeout: float): + def _do_retrieve(self, n_packets: int, timeout: float) -> None: """ Receives responses until there are only n_packets responses left. diff --git a/spinnman/connections/udp_packet_connections/bmp_connection.py b/spinnman/connections/udp_packet_connections/bmp_connection.py index 4b123b85b..12d8583b5 100644 --- a/spinnman/connections/udp_packet_connections/bmp_connection.py +++ b/spinnman/connections/udp_packet_connections/bmp_connection.py @@ -83,7 +83,7 @@ def receive_scp_response(self, timeout: Optional[float] = 1.0) -> Tuple[ result, sequence = _TWO_SHORTS.unpack_from(data, 10) return SCPResult(result), sequence, data, 2 - def __repr__(self): + def __repr__(self) -> str: return ( f"BMPConnection(" f"boards={self._boards}, local_host={self.local_ip_address}, " diff --git a/spinnman/connections/udp_packet_connections/boot_connection.py b/spinnman/connections/udp_packet_connections/boot_connection.py index f7c41536c..a5c39473c 100644 --- a/spinnman/connections/udp_packet_connections/boot_connection.py +++ b/spinnman/connections/udp_packet_connections/boot_connection.py @@ -44,7 +44,7 @@ def __init__(self, remote_host: Optional[str] = None): super().__init__(remote_host=remote_host, remote_port=UDP_BOOT_CONNECTION_DEFAULT_PORT) - def send_boot_message(self, boot_message: SpinnakerBootMessage): + def send_boot_message(self, boot_message: SpinnakerBootMessage) -> None: """ Sends a SpiNNaker boot message using this connection. @@ -80,7 +80,7 @@ def receive_boot_message( data = self.receive(timeout) return SpinnakerBootMessage.from_bytestring(data, 0) - def __repr__(self): + def __repr__(self) -> str: return self._REPR_TEMPLATE.format( self.local_ip_address, self.local_port, self.remote_ip_address, self.remote_port) diff --git a/spinnman/connections/udp_packet_connections/eieio_connection.py b/spinnman/connections/udp_packet_connections/eieio_connection.py index c3b228b2e..d774c76b8 100644 --- a/spinnman/connections/udp_packet_connections/eieio_connection.py +++ b/spinnman/connections/udp_packet_connections/eieio_connection.py @@ -61,7 +61,7 @@ def receive_eieio_message( return read_eieio_command_message(data, 0) return read_eieio_data_message(data, 0) - def send_eieio_message(self, eieio_message: AbstractEIEIOMessage): + def send_eieio_message(self, eieio_message: AbstractEIEIOMessage) -> None: """ Sends an EIEIO message down this connection. @@ -74,7 +74,7 @@ def send_eieio_message(self, eieio_message: AbstractEIEIOMessage): def send_eieio_message_to( self, eieio_message: AbstractEIEIOMessage, - ip_address: str, port: int): + ip_address: str, port: int) -> None: """ :param AbstractEIEIOMessage eieio_message: diff --git a/spinnman/connections/udp_packet_connections/ip_address_connection.py b/spinnman/connections/udp_packet_connections/ip_address_connection.py index 42b6ed142..f13d032a3 100644 --- a/spinnman/connections/udp_packet_connections/ip_address_connection.py +++ b/spinnman/connections/udp_packet_connections/ip_address_connection.py @@ -26,8 +26,8 @@ class IPAddressesConnection(UDPConnection): """ __slots__ = () - def __init__(self, local_host=None, - local_port=UDP_BOOT_CONNECTION_DEFAULT_PORT): + def __init__(self, local_host: Optional[str] = None, + local_port: int = UDP_BOOT_CONNECTION_DEFAULT_PORT): super().__init__(local_host=local_host, local_port=local_port) def receive_ip_address(self, timeout: Optional[float] = None @@ -44,6 +44,6 @@ def receive_ip_address(self, timeout: Optional[float] = None return ip_address return None - def __repr__(self): + def __repr__(self) -> str: return f"IPAddressesConnection(local_host={self.local_ip_address}," \ f" local_port={self.local_port})" diff --git a/spinnman/connections/udp_packet_connections/scamp_connection.py b/spinnman/connections/udp_packet_connections/scamp_connection.py index 738317d4d..7d9875cae 100644 --- a/spinnman/connections/udp_packet_connections/scamp_connection.py +++ b/spinnman/connections/udp_packet_connections/scamp_connection.py @@ -68,7 +68,7 @@ def chip_x(self) -> int: def chip_y(self) -> int: return self._chip_y - def update_chip_coordinates(self, x: int, y: int): + def update_chip_coordinates(self, x: int, y: int) -> None: """ Sets the coordinates without checking they are valid. diff --git a/spinnman/connections/udp_packet_connections/sdp_connection.py b/spinnman/connections/udp_packet_connections/sdp_connection.py index f5e1d3467..e9457af50 100644 --- a/spinnman/connections/udp_packet_connections/sdp_connection.py +++ b/spinnman/connections/udp_packet_connections/sdp_connection.py @@ -84,7 +84,7 @@ def receive_sdp_message( data = self.receive(timeout) return SDPMessage.from_bytestring(data, 2) - def send_sdp_message(self, sdp_message: SDPMessage): + def send_sdp_message(self, sdp_message: SDPMessage) -> None: """ Sends an SDP message down this connection. diff --git a/spinnman/connections/udp_packet_connections/udp_connection.py b/spinnman/connections/udp_packet_connections/udp_connection.py index bf8f87101..3aae551d1 100644 --- a/spinnman/connections/udp_packet_connections/udp_connection.py +++ b/spinnman/connections/udp_packet_connections/udp_connection.py @@ -219,7 +219,7 @@ def receive_with_address(self, timeout: Optional[float] = None) -> Tuple[ raise SpinnmanEOFException() return receive_message_and_address(self._socket, timeout, _MSG_MAX) - def send(self, data: bytes): + def send(self, data: bytes) -> None: """ Send data down this connection. @@ -237,7 +237,7 @@ def send(self, data: bytes): if self.__is_closed: raise SpinnmanEOFException() - def send_to(self, data: bytes, address: Tuple[str, int]): + def send_to(self, data: bytes, address: Tuple[str, int]) -> None: """ Send data down this connection. @@ -261,7 +261,7 @@ def close(self) -> None: self._socket.shutdown(socket.SHUT_WR) self._socket.close() - def is_ready_to_receive(self, timeout: float = 0): + def is_ready_to_receive(self, timeout: float = 0) -> bool: if self.__is_closed: return True return len(select.select([self._socket], [], [], timeout)[0]) == 1 diff --git a/spinnman/exceptions.py b/spinnman/exceptions.py index a89962eb7..628bf8630 100644 --- a/spinnman/exceptions.py +++ b/spinnman/exceptions.py @@ -14,7 +14,7 @@ from __future__ import annotations import traceback from types import TracebackType -from typing import List, Optional, FrozenSet, Union, TYPE_CHECKING +from typing import Any, List, Optional, FrozenSet, Union, TYPE_CHECKING if TYPE_CHECKING: from spinnman.messages.scp.enums import SCPResult from spinnman.model.enums import CPUState @@ -192,11 +192,11 @@ class SpinnmanTimeoutException(SpinnmanException): could finish. """ - def __init__(self, operation: str, timeout: Optional[float], + def __init__(self, operation: Any, timeout: Optional[float], msg: Optional[str] = None): """ - :param str operation: The operation being performed - :param float timeout: The timeout value in seconds + :param operation: The operation being performed + :param timeout: The timeout value in seconds """ if msg is None: msg = f"Operation {operation} timed out after {timeout} seconds" diff --git a/spinnman/extended/de_alloc_sdram_process.py b/spinnman/extended/de_alloc_sdram_process.py index b70cca50d..331338b33 100644 --- a/spinnman/extended/de_alloc_sdram_process.py +++ b/spinnman/extended/de_alloc_sdram_process.py @@ -13,7 +13,8 @@ # See the License for the specific language governing permissions and # limitations under the License. from typing import Optional -from spinnman.messages.scp.impl import SDRAMDeAlloc +from spinnman.messages.scp.impl.sdram_de_alloc import ( + SDRAMDeAlloc, _SCPSDRAMDeAllocResponse) from spinnman.processes import AbstractMultiConnectionProcess from spinnman.processes import ConnectionSelector @@ -27,14 +28,14 @@ class DeAllocSDRAMProcess(AbstractMultiConnectionProcess): """ __slots__ = ("_no_blocks_freed", ) - def __init__(self, connection_selector: ConnectionSelector): + def __init__(self, connection_selector: ConnectionSelector) -> None: """ :param ConnectionSelector connection_selector: """ super().__init__(connection_selector) self._no_blocks_freed: Optional[int] = None - def de_alloc_all_app_sdram(self, x: int, y: int, app_id: int): + def de_alloc_all_app_sdram(self, x: int, y: int, app_id: int) -> None: """ :param int x: :param int y: @@ -47,7 +48,7 @@ def de_alloc_all_app_sdram(self, x: int, y: int, app_id: int): self._send_request(SDRAMDeAlloc(x, y, app_id=app_id), callback=self.__handle_sdram_alloc_response) - def de_alloc_sdram(self, x: int, y: int, base_address: int): + def de_alloc_sdram(self, x: int, y: int, base_address: int) -> None: """ :param int x: :param int y: @@ -57,7 +58,8 @@ def de_alloc_sdram(self, x: int, y: int, base_address: int): self._send_request(SDRAMDeAlloc(x, y, base_address=base_address), callback=None) - def __handle_sdram_alloc_response(self, response): + def __handle_sdram_alloc_response( + self, response: _SCPSDRAMDeAllocResponse) -> None: self._no_blocks_freed = response.number_of_blocks_freed @property diff --git a/spinnman/extended/read_adc.py b/spinnman/extended/read_adc.py index 2c82978e5..c82b8ca26 100644 --- a/spinnman/extended/read_adc.py +++ b/spinnman/extended/read_adc.py @@ -62,7 +62,7 @@ def _parse_payload(self, data: bytes, offset: int) -> ADCInfo: return ADCInfo(data, offset) @property - def adc_info(self): + def adc_info(self) -> ADCInfo: """ The ADC information. """ diff --git a/spinnman/extended/write_memory_flood_process.py b/spinnman/extended/write_memory_flood_process.py index 6cecb6297..f3b3349bd 100644 --- a/spinnman/extended/write_memory_flood_process.py +++ b/spinnman/extended/write_memory_flood_process.py @@ -32,20 +32,21 @@ def __init__(self, next_connection_selector: ConnectionSelector): self, next_connection_selector, n_channels=3, intermediate_channel_waits=2) - def _start_flood_fill(self, n_bytes: int, nearest_neighbour_id: int): + def _start_flood_fill( + self, n_bytes: int, nearest_neighbour_id: int) -> None: n_blocks = int(math.ceil(math.ceil(n_bytes / 4.0) / UDP_MESSAGE_MAX_SIZE)) with self._collect_responses(): self._send_request( FloodFillStart(nearest_neighbour_id, n_blocks)) - def _end_flood_fill(self, nearest_neighbour_id: int): + def _end_flood_fill(self, nearest_neighbour_id: int) -> None: with self._collect_responses(): self._send_request(FloodFillEnd(nearest_neighbour_id)) def write_memory_from_bytearray( self, nearest_neighbour_id: int, base_address: int, - data: bytes, offset: int, n_bytes: Optional[int] = None): + data: bytes, offset: int, n_bytes: Optional[int] = None) -> None: """ :param int nearest_neighbour_id: :param int base_address: @@ -79,7 +80,7 @@ def write_memory_from_bytearray( def write_memory_from_reader( self, nearest_neighbour_id: int, base_address: int, - reader: BinaryIO, n_bytes: int): + reader: BinaryIO, n_bytes: int) -> None: """ :param int nearest_neighbour_id: :param int base_address: diff --git a/spinnman/messages/scp/impl/app_copy_run.py b/spinnman/messages/scp/impl/app_copy_run.py index 4e52403f3..c09456a84 100644 --- a/spinnman/messages/scp/impl/app_copy_run.py +++ b/spinnman/messages/scp/impl/app_copy_run.py @@ -70,7 +70,7 @@ def __init__(self, x: int, y: int, link: int, size: int, app_id: int, SCPRequestHeader(command=SCPCommand.CMD_APP_COPY_RUN), argument_1=arg1, argument_2=size, argument_3=processor_mask) - def __repr__(self): + def __repr__(self) -> str: return f"{super(AppCopyRun, self).__repr__()} (Link {self.__link})" @overrides(AbstractSCPRequest.get_scp_response) diff --git a/spinnman/messages/scp/impl/app_stop.py b/spinnman/messages/scp/impl/app_stop.py index 263009d73..aae57f064 100644 --- a/spinnman/messages/scp/impl/app_stop.py +++ b/spinnman/messages/scp/impl/app_stop.py @@ -22,7 +22,7 @@ _APP_MASK = 0xFF -def _get_data(app_id, signal): +def _get_data(app_id: int, signal: Signal) -> int: data = (_APP_MASK << 8) | app_id data += signal.value << 16 return data diff --git a/spinnman/messages/scp/impl/check_ok_response.py b/spinnman/messages/scp/impl/check_ok_response.py index 4f4a140b0..be627c42f 100644 --- a/spinnman/messages/scp/impl/check_ok_response.py +++ b/spinnman/messages/scp/impl/check_ok_response.py @@ -12,6 +12,9 @@ # See the License for the specific language governing permissions and # limitations under the License. +from enum import Enum +from typing import Union + from spinn_utilities.overrides import overrides from spinnman.messages.scp.abstract_messages import AbstractSCPResponse from spinnman.messages.scp.enums import SCPResult @@ -26,7 +29,7 @@ class CheckOKResponse(AbstractSCPResponse): "_command", "_operation") - def __init__(self, operation: str, command): + def __init__(self, operation: str, command: Union[Enum, int, str]): """ :param str operation: The operation being performed :param command: The command that was sent @@ -37,7 +40,7 @@ def __init__(self, operation: str, command): self._command = command @overrides(AbstractSCPResponse.read_data_bytestring) - def read_data_bytestring(self, data: bytes, offset: int): + def read_data_bytestring(self, data: bytes, offset: int) -> None: result = self.scp_response_header.result if result != SCPResult.RC_OK: raise SpinnmanUnexpectedResponseCodeException( diff --git a/spinnman/messages/scp/impl/iptag_set.py b/spinnman/messages/scp/impl/iptag_set.py index 92f4b7ffc..bf9eff044 100644 --- a/spinnman/messages/scp/impl/iptag_set.py +++ b/spinnman/messages/scp/impl/iptag_set.py @@ -12,6 +12,8 @@ # See the License for the specific language governing permissions and # limitations under the License. +from typing import List, Union + from spinn_utilities.overrides import overrides from spinnman.messages.scp import SCPRequestHeader from spinnman.messages.scp.abstract_messages import AbstractSCPRequest @@ -28,7 +30,8 @@ class IPTagSet(AbstractSCPRequest[CheckOKResponse]): """ __slots__ = () - def __init__(self, x: int, y: int, host, port: int, tag: int, *, + def __init__(self, x: int, y: int, host: Union[bytearray, List[int]], + port: int, tag: int, *, strip: bool = False, use_sender: bool = False): """ :param int x: The x-coordinate of a chip, between 0 and 255 diff --git a/spinnman/processes/abstract_multi_connection_process.py b/spinnman/processes/abstract_multi_connection_process.py index 406c744f6..46be758cd 100644 --- a/spinnman/processes/abstract_multi_connection_process.py +++ b/spinnman/processes/abstract_multi_connection_process.py @@ -101,7 +101,7 @@ def __init__(self, next_connection_selector: ConnectionSelector, def _send_request(self, request: AbstractSCPRequest[R], callback: Optional[Callable[[R], None]] = None, - error_callback: Optional[ECB] = None): + error_callback: Optional[ECB] = None) -> None: if error_callback is None: error_callback = self._receive_error connection = self._conn_selector.get_next_connection(request) @@ -117,7 +117,7 @@ def _send_request(self, request: AbstractSCPRequest[R], def _receive_error( self, request: AbstractSCPRequest[R], exception: Exception, - tb: TracebackType, connection: SCAMPConnection): + tb: TracebackType, connection: SCAMPConnection) -> None: self._error_requests.append(request) self._exceptions.append(exception) self._tracebacks.append(tb) @@ -171,7 +171,7 @@ def connection_selector(self) -> ConnectionSelector: """ return self._conn_selector - def check_for_error(self, print_exception: bool = False): + def check_for_error(self, print_exception: bool = False) -> None: """ Check if any errors have been cached and raises them diff --git a/spinnman/processes/application_copy_run_process.py b/spinnman/processes/application_copy_run_process.py index 33c80a538..03d4884db 100644 --- a/spinnman/processes/application_copy_run_process.py +++ b/spinnman/processes/application_copy_run_process.py @@ -23,7 +23,7 @@ APP_COPY_RUN_TIMEOUT = 6.0 -def _on_same_board(chip_1: Chip, chip_2: Chip): +def _on_same_board(chip_1: Chip, chip_2: Chip) -> bool: return (chip_1.nearest_ethernet_x == chip_2.nearest_ethernet_x and chip_1.nearest_ethernet_y == chip_2.nearest_ethernet_y) @@ -104,7 +104,7 @@ def __init__(self, next_connection_selector: ConnectionSelector, self, next_connection_selector, timeout=timeout) def run(self, size: int, app_id: int, core_subsets: CoreSubsets, - checksum: int, wait: bool): + checksum: int, wait: bool) -> None: """ Run the process. diff --git a/spinnman/processes/application_run_process.py b/spinnman/processes/application_run_process.py index 2057f1211..87c5f8486 100644 --- a/spinnman/processes/application_run_process.py +++ b/spinnman/processes/application_run_process.py @@ -23,7 +23,7 @@ class ApplicationRunProcess(AbstractMultiConnectionProcess[CheckOKResponse]): """ __slots__ = () - def run(self, app_id: int, core_subsets: CoreSubsets, wait: bool): + def run(self, app_id: int, core_subsets: CoreSubsets, wait: bool) -> None: """ Runs the application. diff --git a/spinnman/processes/get_cpu_info_process.py b/spinnman/processes/get_cpu_info_process.py index c825c6392..c78a0b7b4 100644 --- a/spinnman/processes/get_cpu_info_process.py +++ b/spinnman/processes/get_cpu_info_process.py @@ -44,7 +44,8 @@ def _is_desired(self, cpu_info: CPUInfo) -> bool: # pylint: disable=unused-argument return True - def __handle_response(self, x: int, y: int, p: int, response: Response): + def __handle_response( + self, x: int, y: int, p: int, response: Response) -> None: cpu_data = cast(_vcpu_t, _VCPU_PATTERN.unpack_from( response.data, response.offset)) cpu_info = CPUInfo(x, y, p, cpu_data) diff --git a/spinnman/processes/get_heap_process.py b/spinnman/processes/get_heap_process.py index c9cd7663c..813c103cc 100644 --- a/spinnman/processes/get_heap_process.py +++ b/spinnman/processes/get_heap_process.py @@ -51,15 +51,15 @@ def __init__(self, connection_selector: ConnectionSelector): self._next_block_address = 0 self._blocks: List[HeapElement] = list() - def _read_heap_address_response(self, response: Response): + def _read_heap_address_response(self, response: Response) -> None: self._heap_address = _ADDRESS.unpack_from( response.data, response.offset)[0] - def _read_heap_pointer(self, response: Response): + def _read_heap_pointer(self, response: Response) -> None: self._next_block_address = _HEAP_POINTER.unpack_from( response.data, response.offset)[0] - def _read_next_block(self, block_address: int, response: Response): + def _read_next_block(self, block_address: int, response: Response) -> None: self._next_block_address, free = _ELEMENT_HEADER.unpack_from( response.data, response.offset) if self._next_block_address != 0: @@ -68,7 +68,7 @@ def _read_next_block(self, block_address: int, response: Response): def __read_address( self, core_coords: XYP, address: int, size: int, - callback: Callable[[Response], None]): + callback: Callable[[Response], None]) -> None: with self._collect_responses(): self._send_request( ReadMemory(core_coords, address, size), callback) diff --git a/spinnman/processes/get_machine_process.py b/spinnman/processes/get_machine_process.py index 00b104300..fef163b21 100644 --- a/spinnman/processes/get_machine_process.py +++ b/spinnman/processes/get_machine_process.py @@ -17,12 +17,14 @@ import logging import functools from os.path import join -from typing import Dict, List, Optional, Set, Tuple, cast +from types import TracebackType +from typing import Any, Dict, List, Optional, Set, Tuple, cast from spinn_utilities.config_holder import ( get_config_bool, get_config_int_or_none, get_config_str_or_none) from spinn_utilities.data import UtilsDataView from spinn_utilities.log import FormatAdapter +from spinn_utilities.overrides import overrides from spinn_utilities.progress_bar import ProgressBar from spinn_utilities.typing.coords import XY @@ -30,6 +32,7 @@ from spinn_machine.ignores import IgnoreChip, IgnoreCore, IgnoreLink from spinn_machine.machine_factory import machine_repair +from spinnman.connections.udp_packet_connections import SCAMPConnection from spinnman.constants import ( ROUTER_REGISTER_P2P_ADDRESS, SYSTEM_VARIABLE_BASE_ADDRESS) from spinnman.data import SpiNNManDataView @@ -176,7 +179,7 @@ def _make_router( chip_info.n_free_multicast_routing_entries)) def __receive_p2p_data( - self, column: int, scp_read_response: Response): + self, column: int, scp_read_response: Response) -> None: """ :param int column: :param Response scp_read_response: @@ -185,7 +188,7 @@ def __receive_p2p_data( scp_read_response.data, scp_read_response.offset) def _receive_chip_info( - self, scp_read_chip_info_response: GetChipInfoResponse): + self, scp_read_chip_info_response: GetChipInfoResponse) -> None: """ :param GetChipInfoResponse scp_read_chip_info_response: """ @@ -195,7 +198,7 @@ def _receive_chip_info( self._progress.update() def _receive_p_maps( - self, x: int, y: int, scp_read_response: Response): + self, x: int, y: int, scp_read_response: Response) -> None: """ Receive the physical-to-virtual and virtual-to-physical maps. @@ -207,8 +210,10 @@ def _receive_p_maps( off += _P_TO_V_SIZE self._virtual_to_physical_map[x, y] = data[off:] + @overrides(AbstractMultiConnectionProcess._receive_error) def _receive_error( - self, request: AbstractSCPRequest, exception, tb, connection): + self, request: AbstractSCPRequest, exception: Exception, + tb: TracebackType, connection: SCAMPConnection) -> None: """ :param AbstractSCPRequest request: :param Exception exception: @@ -307,7 +312,7 @@ def _fill_machine(self, machine: Machine) -> Machine: # Stuff below here is purely for dealing with ignores - def _process_ignore_links(self, machine: Machine): + def _process_ignore_links(self, machine: Machine) -> None: """ Processes the collection of ignore links to remove then from chip info. @@ -356,7 +361,7 @@ def _process_ignore_links(self, machine: Machine): "Discarding ignore link {} on chip {} as it is not/" "no longer in info", link, global_xy) - def _preprocess_ignore_cores(self, machine: Machine): + def _preprocess_ignore_cores(self, machine: Machine) -> None: """ Converts the collection of ignore cores into a map of ignore by x,y. @@ -382,7 +387,7 @@ def _preprocess_ignore_cores(self, machine: Machine): if p is not None: self._ignore_cores_map[global_xy].add(p) - def _preprocess_ignore_chips(self, machine: Machine): + def _preprocess_ignore_chips(self, machine: Machine) -> None: """ Processes the collection of ignore chips and discards their chip info. @@ -494,7 +499,7 @@ def _get_virtual_p(self, xy: XY, p: int) -> Optional[int]: "core {}", xy, virtual_p, physical) return virtual_p - def _report_ignore(self, message: str, *args): + def _report_ignore(self, message: str, *args: Any) -> None: """ Writes the ignore message by either creating or appending the report. diff --git a/spinnman/processes/get_n_cores_in_state_process.py b/spinnman/processes/get_n_cores_in_state_process.py index 7183fc00b..1710d9b07 100644 --- a/spinnman/processes/get_n_cores_in_state_process.py +++ b/spinnman/processes/get_n_cores_in_state_process.py @@ -12,9 +12,15 @@ # See the License for the specific language governing permissions and # limitations under the License. +from typing import Iterable, Tuple + +from spinnman.model.enums import CPUState from spinnman.messages.scp.impl import CountState +from spinnman.messages.scp.impl.count_state_response import CountStateResponse from spinnman.messages.scp.enums.scp_result import SCPResult from .abstract_multi_connection_process import AbstractMultiConnectionProcess +from .abstract_multi_connection_process_connection_selector import ( + ConnectionSelector) # Timeout for getting core state count; higher due to more waiting needed GET_CORE_COUNT_TIMEOUT = 2.0 @@ -27,20 +33,19 @@ class GetNCoresInStateProcess(AbstractMultiConnectionProcess): __slots__ = [ "_n_cores"] - def __init__(self, connection_selector): + def __init__(self, connection_selector: ConnectionSelector): """ :param connection_selector: - :type connection_selector: - AbstractMultiConnectionProcessConnectionSelector """ super().__init__(connection_selector, timeout=GET_CORE_COUNT_TIMEOUT, non_fail_retry_codes={SCPResult.RC_P2P_NOREPLY}) self._n_cores = 0 - def __handle_response(self, response): + def __handle_response(self, response: CountStateResponse) -> None: self._n_cores += response.count - def get_n_cores_in_state(self, xys, app_id, state): + def get_n_cores_in_state(self, xys: Iterable[Tuple[int, int]], + app_id: int, state: CPUState) -> int: """ :param list(int,int) xys: :param int app_id: diff --git a/spinnman/processes/get_routes_process.py b/spinnman/processes/get_routes_process.py index 971c41f91..932c787a7 100644 --- a/spinnman/processes/get_routes_process.py +++ b/spinnman/processes/get_routes_process.py @@ -57,7 +57,7 @@ def __init__(self, connection_selector: ConnectionSelector, def _add_routing_entry( self, route_no: int, offset: int, app_id: int, route: int, - key: int, mask: int): + key: int, mask: int) -> None: # pylint: disable=too-many-arguments if route >= 0xFF000000: return @@ -67,7 +67,7 @@ def _add_routing_entry( self._entries[route_no + offset] = MulticastRoutingEntry( key, mask, RoutingEntry(spinnaker_route=route)) - def __handle_response(self, offset: int, response: Response): + def __handle_response(self, offset: int, response: Response) -> None: for route_no in range(_ENTRIES_PER_READ): entry = _ROUTE_ENTRY_PATTERN.unpack_from( response.data, diff --git a/spinnman/processes/get_tags_process.py b/spinnman/processes/get_tags_process.py index e51973379..d6a7c92f3 100644 --- a/spinnman/processes/get_tags_process.py +++ b/spinnman/processes/get_tags_process.py @@ -44,11 +44,12 @@ def __init__(self, connection_selector: ConnectionSelector): self._tag_info: Optional[IPTagGetInfoResponse] = None self._tags: List[Optional[AbstractTag]] = [] - def __handle_tag_info_response(self, response: IPTagGetInfoResponse): + def __handle_tag_info_response( + self, response: IPTagGetInfoResponse) -> None: self._tag_info = response - def __handle_get_tag_response( - self, tag: int, board_address, response: IPTagGetResponse): + def __handle_get_tag_response(self, tag: int, board_address: Optional[str], + response: IPTagGetResponse) -> None: if response.in_use: ip = response.ip_address host = f"{ip[0]}.{ip[1]}.{ip[2]}.{ip[3]}" diff --git a/spinnman/processes/get_version_process.py b/spinnman/processes/get_version_process.py index 1abcb1e7b..96ad4cea1 100644 --- a/spinnman/processes/get_version_process.py +++ b/spinnman/processes/get_version_process.py @@ -38,7 +38,7 @@ def __init__(self, connection_selector: ConnectionSelector, super().__init__(connection_selector, n_retries) self._version_info: Optional[VersionInfo] = None - def _get_response(self, version_response: GetVersionResponse): + def _get_response(self, version_response: GetVersionResponse) -> None: """ :param GetVersionResponse version_response: """ diff --git a/spinnman/processes/load_fixed_route_routing_entry_process.py b/spinnman/processes/load_fixed_route_routing_entry_process.py index b9c24fb12..a4cd0ef21 100644 --- a/spinnman/processes/load_fixed_route_routing_entry_process.py +++ b/spinnman/processes/load_fixed_route_routing_entry_process.py @@ -25,7 +25,7 @@ class LoadFixedRouteRoutingEntryProcess(AbstractMultiConnectionProcess): def load_fixed_route( self, x: int, y: int, fixed_route: RoutingEntry, - app_id: int = 0): + app_id: int = 0) -> None: """ :param int x: The x-coordinate of the chip, between 0 and 255; this is not checked due to speed restrictions. diff --git a/spinnman/processes/load_routes_process.py b/spinnman/processes/load_routes_process.py index 50bacd523..accfb55db 100644 --- a/spinnman/processes/load_routes_process.py +++ b/spinnman/processes/load_routes_process.py @@ -45,12 +45,13 @@ def __init__(self, connection_selector: ConnectionSelector): super().__init__(connection_selector) self._base_address = 0 - def __handle_router_alloc_response(self, response: RouterAllocResponse): + def __handle_router_alloc_response( + self, response: RouterAllocResponse) -> None: self._base_address = response.base_address def load_routes( self, x: int, y: int, routes: Collection[MulticastRoutingEntry], - app_id: int): + app_id: int) -> None: """ :param int x: :param int y: diff --git a/spinnman/processes/malloc_sdram_process.py b/spinnman/processes/malloc_sdram_process.py index 35567509c..1bfc03350 100644 --- a/spinnman/processes/malloc_sdram_process.py +++ b/spinnman/processes/malloc_sdram_process.py @@ -31,10 +31,11 @@ def __init__(self, connection_selector: ConnectionSelector): super().__init__(connection_selector) self._base_address = 0 - def __handle_sdram_alloc_response(self, response: _AllocResponse): + def __handle_sdram_alloc_response(self, response: _AllocResponse) -> None: self._base_address = response.base_address - def malloc_sdram(self, x: int, y: int, size: int, app_id: int, tag: int): + def malloc_sdram( + self, x: int, y: int, size: int, app_id: int, tag: int) -> None: """ Allocate space in the SDRAM space. diff --git a/spinnman/processes/read_fixed_route_routing_entry_process.py b/spinnman/processes/read_fixed_route_routing_entry_process.py index 9c9b8b9c8..4f5f56f0f 100644 --- a/spinnman/processes/read_fixed_route_routing_entry_process.py +++ b/spinnman/processes/read_fixed_route_routing_entry_process.py @@ -41,7 +41,7 @@ def __init__(self, connection_selector: ConnectionSelector): super().__init__(connection_selector) self._route: Optional[RoutingEntry] = None - def __handle_read_response(self, response: _FixedRouteResponse): + def __handle_read_response(self, response: _FixedRouteResponse) -> None: self._route = response.route def read_fixed_route( diff --git a/spinnman/processes/read_iobuf_process.py b/spinnman/processes/read_iobuf_process.py index 510c3d836..94f4a786d 100644 --- a/spinnman/processes/read_iobuf_process.py +++ b/spinnman/processes/read_iobuf_process.py @@ -108,7 +108,8 @@ def __init__(self, connection_selector: ConnectionSelector) -> None: # read = list of (x, y, p, n, next_address, first_read_size) self._next_reads: List[_NextRegion] = list() - def _request_iobuf_address(self, iobuf_size: int, x: int, y: int, p: int): + def _request_iobuf_address( + self, iobuf_size: int, x: int, y: int, p: int) -> None: scamp_coords = (x, y, 0) base_address = get_vcpu_address(p) + CPU_IOBUF_ADDRESS_OFFSET self._send_request( @@ -118,34 +119,34 @@ def _request_iobuf_address(self, iobuf_size: int, x: int, y: int, p: int): def __handle_iobuf_address_response( self, iobuf_size: int, scamp_coords: XYP, xyp: XYP, - response: Response): + response: Response) -> None: iobuf_address, = _ONE_WORD.unpack_from(response.data, response.offset) if iobuf_address != 0: first_read_size = min((iobuf_size + 16, UDP_MESSAGE_MAX_SIZE)) self._next_reads.append(_NextRegion( scamp_coords, xyp, 0, iobuf_address, first_read_size)) - def _request_iobuf_region_tail(self, tail: _RegionTail): + def _request_iobuf_region_tail(self, tail: _RegionTail) -> None: self._send_request( ReadMemory(tail.scamp_coords, tail.base_address, tail.size), functools.partial( self.__handle_extra_iobuf_response, tail)) def __handle_extra_iobuf_response( - self, tail: _RegionTail, response: Response): + self, tail: _RegionTail, response: Response) -> None: view = self._iobuf_view[tail.core_coords][tail.n] base = tail.offset view[base:base + response.length] = response.data[ response.offset:response.offset + response.length] - def _request_iobuf_region(self, region: _NextRegion): + def _request_iobuf_region(self, region: _NextRegion) -> None: self._send_request( ReadMemory(region.scamp_coords, region.next_address, region.first_read_size), functools.partial(self.__handle_first_iobuf_response, region)) def __handle_first_iobuf_response( - self, region: _NextRegion, response: Response): + self, region: _NextRegion, response: Response) -> None: base_address = region.next_address # Unpack the iobuf header diff --git a/spinnman/processes/read_memory_process.py b/spinnman/processes/read_memory_process.py index a3a8776f7..c5bf36b2a 100644 --- a/spinnman/processes/read_memory_process.py +++ b/spinnman/processes/read_memory_process.py @@ -40,7 +40,7 @@ def __init__(self, connection_selector: ConnectionSelector): super().__init__(connection_selector) self._view = memoryview(b'') - def __handle_response(self, offset: int, response: Response): + def __handle_response(self, offset: int, response: Response) -> None: self._view[offset:offset + response.length] = response.data[ response.offset:response.offset + response.length] diff --git a/spinnman/processes/read_router_diagnostics_process.py b/spinnman/processes/read_router_diagnostics_process.py index 1f7f0a138..7dff03343 100644 --- a/spinnman/processes/read_router_diagnostics_process.py +++ b/spinnman/processes/read_router_diagnostics_process.py @@ -42,15 +42,15 @@ def __init__(self, connection_selector: ConnectionSelector): self._error_status = 0 self._register_values = [0] * _N_REGISTERS - def __handle_control_register_response(self, response: Response): + def __handle_control_register_response(self, response: Response) -> None: self._control_register = _ONE_WORD.unpack_from( response.data, response.offset)[0] - def __handle_error_status_response(self, response: Response): + def __handle_error_status_response(self, response: Response) -> None: self._error_status = _ONE_WORD.unpack_from( response.data, response.offset)[0] - def __handle_register_response(self, response: Response): + def __handle_register_response(self, response: Response) -> None: for register in range(_N_REGISTERS): self._register_values[register] = _ONE_WORD.unpack_from( response.data, response.offset + (register * 4))[0] diff --git a/spinnman/processes/send_single_command_process.py b/spinnman/processes/send_single_command_process.py index 120d4d286..8583c3b63 100644 --- a/spinnman/processes/send_single_command_process.py +++ b/spinnman/processes/send_single_command_process.py @@ -54,7 +54,7 @@ def __init__(self, connection_selector: ConnectionSelector, non_fail_retry_codes=non_fail_retry_codes) self._response: Optional[R] = None - def __handle_response(self, response: R): + def __handle_response(self, response: R) -> None: self._response = response def execute(self, request: AbstractSCPRequest[R]) -> R: diff --git a/spinnman/utilities/utility_functions.py b/spinnman/utilities/utility_functions.py index 9fc4f86e3..7dfbf6102 100644 --- a/spinnman/utilities/utility_functions.py +++ b/spinnman/utilities/utility_functions.py @@ -60,7 +60,7 @@ def get_vcpu_address(p: int) -> int: def send_port_trigger_message( - connection: UDPConnection, board_address: str): + connection: UDPConnection, board_address: str) -> None: """ Sends a port trigger message using a connection to (hopefully) open a port in a NAT and/or firewall to allow incoming packets to be received. @@ -84,7 +84,8 @@ def send_port_trigger_message( trigger_message.bytestring, (board_address, SCP_SCAMP_PORT)) -def reprogram_tag(connection: SCAMPConnection, tag: int, strip: bool = True): +def reprogram_tag( + connection: SCAMPConnection, tag: int, strip: bool = True) -> None: """ Reprogram an IP Tag to send responses to a given SCAMPConnection. @@ -114,7 +115,7 @@ def reprogram_tag(connection: SCAMPConnection, tag: int, strip: bool = True): def reprogram_tag_to_listener( connection: UDPConnection, x: int, y: int, ip_address: str, tag: int, - strip: bool = True, read_response: bool = True): + strip: bool = True, read_response: bool = True) -> None: """ Reprogram an IP Tag to send responses to a given connection that is not connected to a specific board. Such connections are normally