From 49991feefa8f076f39a20594980e9711ec84b8de Mon Sep 17 00:00:00 2001 From: Jusong Yu Date: Fri, 21 Feb 2025 23:59:33 +0100 Subject: [PATCH] misc: pre-commit --- src/plumpy/broadcast_filter.py | 1 + src/plumpy/controller.py | 3 +-- src/plumpy/coordinator.py | 8 +++++-- src/plumpy/message.py | 1 - src/plumpy/processes.py | 35 +++++++++++++------------------ src/plumpy/rmq/communications.py | 4 +++- src/plumpy/rmq/process_control.py | 3 ++- tests/utils.py | 3 ++- 8 files changed, 29 insertions(+), 29 deletions(-) diff --git a/src/plumpy/broadcast_filter.py b/src/plumpy/broadcast_filter.py index 61b27095..6ec6c41e 100644 --- a/src/plumpy/broadcast_filter.py +++ b/src/plumpy/broadcast_filter.py @@ -1,4 +1,5 @@ # -*- coding: utf-8 -*- +# type: ignore import re import typing diff --git a/src/plumpy/controller.py b/src/plumpy/controller.py index 9f2793a0..55fe4da6 100644 --- a/src/plumpy/controller.py +++ b/src/plumpy/controller.py @@ -52,8 +52,7 @@ def play_process(self, pid: 'PID_TYPE') -> ProcessResult: ... def play_all(self) -> None: - """Play all processes that are subscribed to the same coordinator - """ + """Play all processes that are subscribed to the same coordinator""" def kill_process(self, pid: 'PID_TYPE', msg_text: str | None = None) -> Any: """Kill the process diff --git a/src/plumpy/coordinator.py b/src/plumpy/coordinator.py index e647961e..fb330700 100644 --- a/src/plumpy/coordinator.py +++ b/src/plumpy/coordinator.py @@ -1,8 +1,8 @@ # -*- coding: utf-8 -*- from __future__ import annotations -from typing import TYPE_CHECKING, Any, Callable, Hashable, Protocol from re import Pattern +from typing import TYPE_CHECKING, Any, Callable, Hashable, Protocol if TYPE_CHECKING: ID_TYPE = Hashable @@ -36,7 +36,11 @@ def unhook_broadcast_receiver(self, identifier: 'ID_TYPE | None') -> None: ... def unhook_task_receiver(self, identifier: 'ID_TYPE') -> None: ... - def rpc_send(self, recipient_id: Hashable, msg: Any,) -> Any: ... + def rpc_send( + self, + recipient_id: Hashable, + msg: Any, + ) -> Any: ... def broadcast_send( self, diff --git a/src/plumpy/message.py b/src/plumpy/message.py index 098277e1..99d215ff 100644 --- a/src/plumpy/message.py +++ b/src/plumpy/message.py @@ -7,7 +7,6 @@ import logging from typing import TYPE_CHECKING, Any, Dict, Optional, Sequence, Union, cast -from plumpy.coordinator import Coordinator from plumpy.exceptions import PersistenceError, TaskRejectedError from . import loaders, persistence diff --git a/src/plumpy/processes.py b/src/plumpy/processes.py index 75737574..123fed32 100644 --- a/src/plumpy/processes.py +++ b/src/plumpy/processes.py @@ -34,9 +34,7 @@ cast, ) -import kiwipy - -from plumpy.broadcast_filter import BroadcastFilter +from plumpy.broadcast_filter import BroadcastFilter # type: ignore from plumpy.coordinator import Coordinator try: @@ -944,19 +942,16 @@ def _fire_event(self, evt: Callable[..., Any], *args: Any, **kwargs: Any) -> Non # region Communication def message_receive(self, msg: MessageType) -> Any: - """ - Coroutine called when the process receives a message from the communicator + """Coroutine called when the process receives a message from the communicator - :param _comm: the communicator that sent the message :param msg: the message :return: the outcome of processing the message, the return value will be sent back as a response to the sender """ - # self.logger.debug( - # "Process<%s>: received RPC message with communicator '%s': %r", - # self.pid, - # _comm, - # msg, - # ) + self.logger.debug( + "Process<%s>: received RPC message: %r", + self.pid, + msg, + ) intent = msg[message.INTENT_KEY] @@ -977,19 +972,17 @@ def message_receive(self, msg: MessageType) -> Any: def broadcast_receive( self, msg: MessageType, sender: Any, subject: Any, correlation_id: Any ) -> Optional[concurrent.futures.Future]: - """ - Coroutine called when the process receives a message from the communicator + """Coroutine called when the process receives a message from the communicator :param msg: the message """ + self.logger.debug( + "Process<%s>: received broadcast message '%s': %r", + self.pid, + subject, + msg, + ) - # self.logger.debug( - # "Process<%s>: received broadcast message '%s' with communicator '%s': %r", - # self.pid, - # subject, - # _comm, - # msg, - # ) # If we get a message we recognise then action it, otherwise ignore fn = None if subject == message.Intent.PLAY: diff --git a/src/plumpy/rmq/communications.py b/src/plumpy/rmq/communications.py index 3ed3877a..e9f227b0 100644 --- a/src/plumpy/rmq/communications.py +++ b/src/plumpy/rmq/communications.py @@ -82,7 +82,9 @@ def converted(communicator: kiwipy.Communicator, *args: Any, **kwargs: Any) -> k CommT = TypeVar('CommT', bound=kiwipy.Communicator) -def wrap_communicator(communicator: CommT, loop: Optional[asyncio.AbstractEventLoop] = None) -> 'LoopCommunicator[CommT]': +def wrap_communicator( + communicator: CommT, loop: Optional[asyncio.AbstractEventLoop] = None +) -> 'LoopCommunicator[CommT]': """ Wrap a communicator such that all callbacks made to any subscribers are scheduled on the given event loop. diff --git a/src/plumpy/rmq/process_control.py b/src/plumpy/rmq/process_control.py index 02eb8853..7de397d1 100644 --- a/src/plumpy/rmq/process_control.py +++ b/src/plumpy/rmq/process_control.py @@ -29,7 +29,8 @@ ProcessStatus = Any -# FIXME: the class not fit typing of ProcessController protocol +# This class not conform with typing of ProcessController protocol. +# Does't matter too much, since this controller is not directly used as the controller by downstream. class RemoteProcessController: """ Control remote processes using coroutines that will send messages and wait diff --git a/tests/utils.py b/tests/utils.py index c0cf0f52..fe8f9900 100644 --- a/tests/utils.py +++ b/tests/utils.py @@ -1,5 +1,6 @@ # -*- coding: utf-8 -*- """Utilities for tests""" +from __future__ import annotations import asyncio import collections @@ -105,7 +106,7 @@ def hook_broadcast_receiver( self._broadcast_receivers[identifier] = receiver return identifier - def unhook_broadcast_receiver(self, identifier: 'ID_TYPE | None') -> None: + def unhook_broadcast_receiver(self, identifier: 'ID_TYPE | None') -> None: self._ensure_open() try: del self._broadcast_receivers[identifier]