Skip to content

Commit

Permalink
Merge pull request #95 from nrempel/master
Browse files Browse the repository at this point in the history
Configure flake8 to check docstrings

Signed-off-by: Nicholas Rempel <[email protected]>

* Add logging up to messages

Signed-off-by: Nicholas Rempel <[email protected]>

* More docs

Signed-off-by: Nicholas Rempel <[email protected]>

* More docs

Signed-off-by: Nicholas Rempel <[email protected]>

* Update docs

Signed-off-by: Nicholas Rempel <[email protected]>

* More docs

Signed-off-by: Nicholas Rempel <[email protected]>

* Docstring cleanup

Signed-off-by: Nicholas Rempel <[email protected]>

* More docs

Signed-off-by: Nicholas Rempel <[email protected]>
  • Loading branch information
andrewwhitehead authored Feb 26, 2019
2 parents 047abb6 + d04d5e3 commit 3486077
Show file tree
Hide file tree
Showing 71 changed files with 2,684 additions and 553 deletions.
38 changes: 33 additions & 5 deletions agent/indy_catalyst_agent/classloader.py
Original file line number Diff line number Diff line change
@@ -1,3 +1,5 @@
"""The classloader provides utilties to dynamically load classes and modules."""

import inspect
import logging

Expand All @@ -22,6 +24,13 @@ class ClassLoader:
"""Class used to load classes from modules dynamically."""

def __init__(self, base_path, super_class):
"""
Initialize a ClassLoader instance.
Args:
base_path: The base dotted path to look for a relative import
super_class: Look for a class that inherits from this class
"""
self.logger = logging.getLogger(__name__)
self.base_path = base_path
self.super_class = super_class
Expand All @@ -30,9 +39,18 @@ def load(self, module_path, load_relative=False):
"""
Load module by module path.
:param module_path: Dotted path to module
:param load_relative: (Default value = False) Should the method check in the
Args:
module_path: Dotted path to module
load_relative: Should the method check in the
configured base path for relative import
Return:
The loaded class
Raises:
ModuleLoadError: If there is an error loading the class
ClassNotFoundError: If there is no class to load at specified path
"""
# We can try to load the module relative to a given base path
if load_relative:
Expand Down Expand Up @@ -67,10 +85,20 @@ def load(self, module_path, load_relative=False):

@classmethod
def load_class(cls, class_name: str, default_module: str = None):
"""Resolve a complete class path (ie. typing.Dict) to the class itself
"""
Resolve a complete class path (ie. typing.Dict) to the class itself.
Args:
class_name: Class name
default_module: (Default value = None)
Returns:
The resolved class
Raises:
ClassNotFoundError: If the class could not be resolved at path
ModuleLoadError: If there was an error loading the module
:param class_name: str: Class name
:param default_module: str: (Default value = None)
"""
if "." in class_name:
# import module and find class
Expand Down
33 changes: 31 additions & 2 deletions agent/indy_catalyst_agent/conductor.py
Original file line number Diff line number Diff line change
@@ -1,7 +1,11 @@
"""
The Conductor.
The conductor is responsible for coordinating messages that are received
over the network, communicating with the ledger, passing messages to handlers,
and storing data in the wallet.
instantiating concrete implementations of required modules and storing data in the
wallet.
"""

import logging
Expand Down Expand Up @@ -31,6 +35,8 @@ class ConductorError(BaseError):

class Conductor:
"""
Conductor class.
Class responsible for initalizing concrete implementations
of our require interfaces and routing inbound and outbound message data.
"""
Expand All @@ -51,6 +57,16 @@ def __init__(
message_factory: MessageFactory,
settings: dict,
) -> None:
"""
Initialize an instance of Conductor.
Args:
transport_configs: Configuration for inbound transport
outbound_transports: Configuration for outbound transport
message_factory: Message factory for discovering and deserializing messages
settings: Dictionary of various settings
"""
self.context = None
self.connection_mgr = None
self.logger = logging.getLogger(__name__)
Expand Down Expand Up @@ -155,7 +171,13 @@ async def inbound_message_router(
reply: Coroutine = None,
):
"""
Routes inbound messages.
Route inbound messages.
Args:
message_body: Body of the incoming message
transport_type: Type of transport this message came from
reply: Function to reply to this message
"""
context = await self.connection_mgr.expand_message(message_body, transport_type)
result = await self.dispatcher.dispatch(
Expand All @@ -168,5 +190,12 @@ async def inbound_message_router(
async def outbound_message_router(
self, message: AgentMessage, target: ConnectionTarget
) -> None:
"""
Route an outbound message.
Args:
message: An agent message to be sent
target: Target to send message to
"""
payload = await self.connection_mgr.compact_message(message, target)
await self.outbound_transport_manager.send_message(payload, target.endpoint)
Loading

0 comments on commit 3486077

Please sign in to comment.