Skip to content

Commit

Permalink
pre-commit fixes
Browse files Browse the repository at this point in the history
  • Loading branch information
rajan-chari committed Oct 21, 2024
1 parent 9d0c04f commit ba2a18d
Show file tree
Hide file tree
Showing 7 changed files with 23 additions and 8 deletions.
1 change: 1 addition & 0 deletions samples/apps/cap/py/autogencap/actor.py
Original file line number Diff line number Diff line change
Expand Up @@ -3,6 +3,7 @@
from .actor_runtime import IMsgActor, IRuntime, IMessageReceiver
from .debug_log import Debug, Info


class Actor(IMsgActor):
def __init__(self, agent_name: str, description: str, start_thread: bool = True):
"""Initialize the Actor with a name, description, and threading option."""
Expand Down
9 changes: 7 additions & 2 deletions samples/apps/cap/py/autogencap/actor_connector.py
Original file line number Diff line number Diff line change
@@ -1,6 +1,7 @@
from abc import ABC, abstractmethod
from typing import Any, Tuple, Optional


class IActorConnector(ABC):
@abstractmethod
def send_txt_msg(self, msg: str) -> None:
Expand All @@ -15,11 +16,15 @@ def send_proto_msg(self, msg: Any) -> None:
pass

@abstractmethod
def send_recv_proto_msg(self, msg: Any, num_attempts: int = 5) -> Tuple[Optional[str], Optional[str], Optional[bytes]]:
def send_recv_proto_msg(
self, msg: Any, num_attempts: int = 5
) -> Tuple[Optional[str], Optional[str], Optional[bytes]]:
pass

@abstractmethod
def send_recv_msg(self, msg_type: str, msg: bytes, num_attempts: int = 5) -> Tuple[Optional[str], Optional[str], Optional[bytes]]:
def send_recv_msg(
self, msg_type: str, msg: bytes, num_attempts: int = 5
) -> Tuple[Optional[str], Optional[str], Optional[bytes]]:
pass

@abstractmethod
Expand Down
9 changes: 6 additions & 3 deletions samples/apps/cap/py/autogencap/actor_runtime.py
Original file line number Diff line number Diff line change
Expand Up @@ -3,9 +3,10 @@
from .actor_connector import IActorConnector
from .proto.CAP_pb2 import ActorInfo


class IMsgActor(ABC):
@abstractmethod
def on_connect(self, runtime: 'IRuntime'):
def on_connect(self, runtime: "IRuntime"):
"""Called when the actor connects to the runtime."""
pass

Expand Down Expand Up @@ -34,13 +35,14 @@ def dispatch_message(self, message):
"""Dispatch the received message based on its type."""
pass


# Abstract base class for message receivers
class IMessageReceiver(ABC):
@abstractmethod
def init(self, actor_name: str):
"""Initialize the message receiver."""
pass

@abstractmethod
def add_listener(self, topic: str):
"""Add a topic to the message receiver."""
Expand All @@ -56,6 +58,7 @@ def stop(self):
"""Stop the message receiver."""
pass


# Abstract base class for the runtime environment
class IRuntime(ABC):
@abstractmethod
Expand Down Expand Up @@ -94,6 +97,6 @@ def find_termination(self) -> IActorConnector:
pass

@abstractmethod
def find_by_name_regex(self, name_regex) -> List['ActorInfo']:
def find_by_name_regex(self, name_regex) -> List["ActorInfo"]:
"""Find actors by name using a regular expression."""
pass
3 changes: 2 additions & 1 deletion samples/apps/cap/py/autogencap/ag_adapter/ag_actor.py
Original file line number Diff line number Diff line change
Expand Up @@ -2,9 +2,10 @@
from autogencap.constants import Termination_Topic
from autogencap.debug_log import Debug


class AGActor(Actor):
def on_start(self, runtime):
super().on_start(runtime)
str_topic = Termination_Topic
self._msg_receiver.add_listener(str_topic)
Debug(self.actor_name, f"subscribe to: {str_topic}")
Debug(self.actor_name, f"subscribe to: {str_topic}")
4 changes: 3 additions & 1 deletion samples/apps/cap/py/autogencap/zmq_directory_svc.py
Original file line number Diff line number Diff line change
Expand Up @@ -120,7 +120,9 @@ def start(self, runtime):
Debug("DirectorySvc", "Starting.")
self._directory_connector = ZMQActorConnector(self._context, Directory_Svc_Topic)
if self._no_other_directory():
self._directory_actor = ZMQDirectoryActor(Directory_Svc_Topic, "Directory Service", self._context) # Update this line
self._directory_actor = ZMQDirectoryActor(
Directory_Svc_Topic, "Directory Service", self._context
) # Update this line
self._directory_actor.on_start(runtime)
Info("DirectorySvc", "Directory service started.")
else:
Expand Down
3 changes: 2 additions & 1 deletion samples/apps/cap/py/autogencap/zmq_msg_receiver.py
Original file line number Diff line number Diff line change
Expand Up @@ -5,6 +5,7 @@
import zmq
import threading


class ZMQMsgReceiver(IMessageReceiver):
def __init__(self, context: zmq.Context):
self._socket = None
Expand Down Expand Up @@ -45,4 +46,4 @@ def stop(self):
"""Stop the ZMQ message receiver."""
self.run = False
self._socket.setsockopt(zmq.LINGER, 0)
self._socket.close()
self._socket.close()
2 changes: 2 additions & 0 deletions samples/apps/cap/py/autogencap/zmq_runtime.py
Original file line number Diff line number Diff line change
Expand Up @@ -38,6 +38,7 @@ def _init_runtime(self):
self._broker = None
if self._directory_svc is None:
from .zmq_directory_svc import ZMQDirectorySvc

self._directory_svc = ZMQDirectorySvc(self._context)
self._directory_svc.start(self)
time.sleep(0.25) # Process queued thread events in Broker and Directory
Expand All @@ -51,6 +52,7 @@ def register(self, actor: Actor):

def get_new_msg_receiver(self) -> IMessageReceiver:
from .zmq_msg_receiver import ZMQMsgReceiver

return ZMQMsgReceiver(self._context)

def connect(self):
Expand Down

0 comments on commit ba2a18d

Please sign in to comment.