Skip to content

Commit

Permalink
fix: pylint
Browse files Browse the repository at this point in the history
  • Loading branch information
Alejandro-Morales committed Aug 9, 2023
1 parent 48de4a5 commit 7aab06b
Show file tree
Hide file tree
Showing 12 changed files with 122 additions and 47 deletions.
30 changes: 26 additions & 4 deletions docs/api/uagents/agent.md
Original file line number Diff line number Diff line change
Expand Up @@ -29,10 +29,12 @@ An agent that interacts within a communication environment.
- `_ledger` - The ledger for recording agent transactions.
- `_almanac_contract` - The almanac contract for agent metadata.
- `_storage` - Key-value store for agent data storage.
- `_interval_handlers` _List[Tuple[IntervalCallback, float]]_ - List of interval handlers and their periods.
- `_interval_handlers` _List[Tuple[IntervalCallback, float]]_ - List of interval
handlers and their periods.
- `_interval_messages` _Set[str]_ - Set of interval message names.
- `_signed_message_handlers` _Dict[str, MessageCallback]_ - Handlers for signed messages.
- `_unsigned_message_handlers` _Dict[str, MessageCallback]_ - Handlers for unsigned messages.
- `_unsigned_message_handlers` _Dict[str, MessageCallback]_ - Handlers for
unsigned messages.
- `_models` _Dict[str, Type[Model]]_ - Dictionary of supported data models.
- `_replies` _Dict[str, Set[Type[Model]]]_ - Dictionary of reply data models.
- `_queries` _Dict[str, asyncio.Future]_ - Dictionary of active queries.
Expand Down Expand Up @@ -428,7 +430,8 @@ Include a protocol into the agent's capabilities.

**Raises**:

- `RuntimeError` - If a duplicate model, signed message handler, or message handler is encountered.
- `RuntimeError` - If a duplicate model, signed message handler, or message handler
is encountered.

<a id="src.uagents.agent.Agent.publish_manifest"></a>

Expand Down Expand Up @@ -507,7 +510,8 @@ This class manages a collection of agents and orchestrates their execution.
**Arguments**:

- `port` _Optional[int]_ - The port number for the server.
- `endpoint` _Optional[Union[str, List[str], Dict[str, dict]]]_ - Configuration for agent endpoints.
- `endpoint` _Optional[Union[str, List[str], Dict[str, dict]]]_ - Configuration
for agent endpoints.


**Attributes**:
Expand All @@ -521,6 +525,24 @@ This class manages a collection of agents and orchestrates their execution.
- `_server` _ASGIServer_ - The ASGI server instance for handling requests.
- `_use_mailbox` _bool_ - A flag indicating whether mailbox functionality is enabled.

<a id="src.uagents.agent.Bureau.__init__"></a>

#### `__`init`__`

```python
def __init__(port: Optional[int] = None,
endpoint: Optional[Union[str, List[str], Dict[str,
dict]]] = None)
```

Initialize a Bureau instance.

**Arguments**:

- `port` _Optional[int]_ - The port number for the server.
- `endpoint` _Optional[Union[str, List[str], Dict[str, dict]]]_ - Configuration
for agent endpoints.

<a id="src.uagents.agent.Bureau.add"></a>

#### add
Expand Down
10 changes: 6 additions & 4 deletions docs/api/uagents/context.md
Original file line number Diff line number Diff line change
Expand Up @@ -56,7 +56,8 @@ Represents the context in which messages are handled and processed.

**Methods**:

- `get_message_protocol(message_schema_digest)` - Get the protocol associated with a message schema digest.
- `get_message_protocol(message_schema_digest)` - Get the protocol associated
with a message schema digest.
send(destination, message, timeout): Send a message to a destination.

<a id="src.uagents.context.Context.__init__"></a>
Expand Down Expand Up @@ -91,9 +92,9 @@ Initialize the Context instance.
- `identity` _Identity_ - The identity associated with the context.
- `wallet` _LocalWallet_ - The local wallet instance for managing identities.
- `ledger` _LedgerClient_ - The ledger client for interacting with distributed ledgers.
- `queries` _Dict[str, asyncio.Future]_ - Dictionary of query names and their asyncio Futures.
- `queries` _Dict[str, asyncio.Future]_ - Dictionary of query names and their Futures.
- `session` _Optional[uuid.UUID]_ - The optional session UUID.
- `replies` _Optional[Dict[str, Set[Type[Model]]]]_ - The optional dictionary of reply models.
- `replies` _Optional[Dict[str, Set[Type[Model]]]]_ - Optional dictionary of reply models.
- `interval_messages` _Optional[Set[str]]_ - The optional set of interval messages.
- `message_received` _Optional[MsgDigest]_ - The optional message digest received.
- `protocols` _Optional[Dict[str, Protocol]]_ - The optional dictionary of protocols.
Expand Down Expand Up @@ -191,7 +192,8 @@ Get the protocol associated with a given message schema digest.

**Returns**:

- `Optional[str]` - The protocol digest associated with the message schema digest, or None if not found.
- `Optional[str]` - The protocol digest associated with the message schema digest,
or None if not found.

<a id="src.uagents.context.Context.send"></a>

Expand Down
9 changes: 6 additions & 3 deletions docs/api/uagents/network.md
Original file line number Diff line number Diff line change
Expand Up @@ -48,8 +48,10 @@ Wait for a transaction to complete on the Ledger.
**Arguments**:

- `tx_hash` _str_ - The hash of the transaction to monitor.
- `timeout` _Optional[timedelta], optional_ - The maximum time to wait for the transaction to complete. Defaults to None.
- `poll_period` _Optional[timedelta], optional_ - The time interval to poll the Ledger for the transaction status. Defaults to None.
- `timeout` _Optional[timedelta], optional_ - The maximum time to wait for
the transaction to complete. Defaults to None.
- `poll_period` _Optional[timedelta], optional_ - The time interval to poll
the Ledger for the transaction status. Defaults to None.


**Returns**:
Expand Down Expand Up @@ -313,7 +315,8 @@ Get the registration transaction for registering a name within a domain.

**Returns**:

- `Optional[Transaction]` - The registration transaction, or None if the name is not available or not owned by the wallet address.
- `Optional[Transaction]` - The registration transaction, or None if the name is not
available or not owned by the wallet address.

<a id="src.uagents.network.NameServiceContract.register"></a>

Expand Down
21 changes: 14 additions & 7 deletions docs/api/uagents/protocol.md
Original file line number Diff line number Diff line change
Expand Up @@ -70,7 +70,8 @@ Property to access the registered replies.

**Returns**:

Dict[str, Dict[str, Type[Model]]]: Dictionary of registered replies with request schema digests as keys.
Dict[str, Dict[str, Type[Model]]]: Dictionary of registered replies with request
schema digests as keys.

<a id="src.uagents.protocol.Protocol.interval_messages"></a>

Expand Down Expand Up @@ -100,7 +101,8 @@ Property to access the signed message handlers.

**Returns**:

Dict[str, MessageCallback]: Dictionary of signed message handlers with message schema digests as keys.
Dict[str, MessageCallback]: Dictionary of signed message handlers with message schema
digests as keys.

<a id="src.uagents.protocol.Protocol.unsigned_message_handlers"></a>

Expand All @@ -115,7 +117,8 @@ Property to access the unsigned message handlers.

**Returns**:

Dict[str, MessageCallback]: Dictionary of unsigned message handlers with message schema digests as keys.
Dict[str, MessageCallback]: Dictionary of unsigned message handlers with message schema
digests as keys.

<a id="src.uagents.protocol.Protocol.name"></a>

Expand Down Expand Up @@ -192,7 +195,8 @@ Decorator to register an interval handler for the protocol.
**Arguments**:

- `period` _float_ - The interval period in seconds.
- `messages` _Optional[Union[Type[Model], Set[Type[Model]]]], optional_ - The associated message types. Defaults to None.
- `messages` _Optional[Union[Type[Model], Set[Type[Model]]]], optional_ - The associated
message types. Defaults to None.


**Returns**:
Expand All @@ -213,7 +217,8 @@ Decorator to register a query handler for the protocol.
**Arguments**:

- `model` _Type[Model]_ - The message model type.
- `replies` _Optional[Union[Type[Model], Set[Type[Model]]]], optional_ - The associated reply types. Defaults to None.
- `replies` _Optional[Union[Type[Model], Set[Type[Model]]]], optional_ - The associated
reply types. Defaults to None.


**Returns**:
Expand All @@ -235,8 +240,10 @@ Decorator to register a message handler for the protocol.
**Arguments**:

- `model` _Type[Model]_ - The message model type.
- `replies` _Optional[Union[Type[Model], Set[Type[Model]]]], optional_ - The associated reply types. Defaults to None.
- `allow_unverified` _Optional[bool], optional_ - Whether to allow unverified messages. Defaults to False.
- `replies` _Optional[Union[Type[Model], Set[Type[Model]]]], optional_ - The associated
reply types. Defaults to None.
- `allow_unverified` _Optional[bool], optional_ - Whether to allow unverified messages.
Defaults to False.


**Returns**:
Expand Down
3 changes: 2 additions & 1 deletion docs/api/uagents/query.md
Original file line number Diff line number Diff line change
Expand Up @@ -21,7 +21,8 @@ Query a remote agent with a message and retrieve the response envelope.

- `destination` _str_ - The destination address of the remote agent.
- `message` _Model_ - The message to send.
- `resolver` _Optional[Resolver], optional_ - The resolver to use for endpoint resolution. Defaults to GlobalResolver.
- `resolver` _Optional[Resolver], optional_ - The resolver to use for endpoint resolution.
Defaults to GlobalResolver.
- `timeout` _Optional[int], optional_ - The timeout for the query in seconds. Defaults to 30.


Expand Down
12 changes: 6 additions & 6 deletions generate_api_docs.py
Original file line number Diff line number Diff line change
Expand Up @@ -46,14 +46,14 @@ def replace_underscores(text: str) -> str:
return text_b


def is_relative_to(p1: Path, p2: Path) -> bool:
def is_relative_to(path_1: Path, path_2: Path) -> bool:
"""Check if a path is relative to another path."""
return str(p1).startswith(str(p2))
return str(path_1).startswith(str(path_2))


def is_not_dir(p: Path) -> bool:
def is_not_dir(path: Path) -> bool:
"""Call p.is_dir() method and negate the result."""
return not p.is_dir()
return not path.is_dir()


def should_skip(module_path: Path) -> bool:
Expand Down Expand Up @@ -94,8 +94,8 @@ def make_pydoc(dotted_path: str, destination_file: Path) -> None:
api_doc_content = run_pydoc_markdown(dotted_path)
destination_file.parent.mkdir(parents=True, exist_ok=True)
destination_file.write_text(api_doc_content)
except Exception as e: # pylint: disable=broad-except
print(f"Error: {str(e)}")
except Exception as ex: # pylint: disable=broad-except
print(f"Error: {str(ex)}")
return
print("Done!")

Expand Down
33 changes: 29 additions & 4 deletions src/uagents/agent.py
Original file line number Diff line number Diff line change
Expand Up @@ -100,10 +100,12 @@ class Agent(Sink):
_ledger: The ledger for recording agent transactions.
_almanac_contract: The almanac contract for agent metadata.
_storage: Key-value store for agent data storage.
_interval_handlers (List[Tuple[IntervalCallback, float]]): List of interval handlers and their periods.
_interval_handlers (List[Tuple[IntervalCallback, float]]): List of interval
handlers and their periods.
_interval_messages (Set[str]): Set of interval message names.
_signed_message_handlers (Dict[str, MessageCallback]): Handlers for signed messages.
_unsigned_message_handlers (Dict[str, MessageCallback]): Handlers for unsigned messages.
_unsigned_message_handlers (Dict[str, MessageCallback]): Handlers for
unsigned messages.
_models (Dict[str, Type[Model]]): Dictionary of supported data models.
_replies (Dict[str, Set[Type[Model]]]): Dictionary of reply data models.
_queries (Dict[str, asyncio.Future]): Dictionary of active queries.
Expand Down Expand Up @@ -617,7 +619,8 @@ def include(self, protocol: Protocol, publish_manifest: Optional[bool] = False):
publish_manifest (Optional[bool]): Flag to publish the protocol's manifest.
Raises:
RuntimeError: If a duplicate model, signed message handler, or message handler is encountered.
RuntimeError: If a duplicate model, signed message handler, or message handler
is encountered.
"""
for func, period in protocol.intervals:
Expand Down Expand Up @@ -818,7 +821,8 @@ class Bureau:
Args:
port (Optional[int]): The port number for the server.
endpoint (Optional[Union[str, List[str], Dict[str, dict]]]): Configuration for agent endpoints.
endpoint (Optional[Union[str, List[str], Dict[str, dict]]]): Configuration
for agent endpoints.
Attributes:
_loop (asyncio.AbstractEventLoop): The event loop.
Expand All @@ -831,6 +835,27 @@ class Bureau:
_use_mailbox (bool): A flag indicating whether mailbox functionality is enabled.
"""
def __init__(
self,
port: Optional[int] = None,
endpoint: Optional[Union[str, List[str], Dict[str, dict]]] = None,
):
"""
Initialize a Bureau instance.
Args:
port (Optional[int]): The port number for the server.
endpoint (Optional[Union[str, List[str], Dict[str, dict]]]): Configuration
for agent endpoints.
"""
self._loop = asyncio.get_event_loop_policy().get_event_loop()
self._agents: List[Agent] = []
self._endpoints = parse_endpoint_config(endpoint)
self._port = port or 8000
self._queries: Dict[str, asyncio.Future] = {}
self._logger = get_logger("bureau")
self._server = ASGIServer(self._port, self._loop, self._queries, self._logger)
self._use_mailbox = False

def add(self, agent: Agent):
"""
Expand Down
10 changes: 6 additions & 4 deletions src/uagents/context.py
Original file line number Diff line number Diff line change
Expand Up @@ -72,7 +72,8 @@ class Context:
protocols (Optional[Dict[str, Protocol]]): The dictionary of protocols.
Methods:
get_message_protocol(message_schema_digest): Get the protocol associated with a message schema digest.
get_message_protocol(message_schema_digest): Get the protocol associated
with a message schema digest.
send(destination, message, timeout): Send a message to a destination.
"""
Expand Down Expand Up @@ -105,9 +106,9 @@ def __init__(
identity (Identity): The identity associated with the context.
wallet (LocalWallet): The local wallet instance for managing identities.
ledger (LedgerClient): The ledger client for interacting with distributed ledgers.
queries (Dict[str, asyncio.Future]): Dictionary of query names and their asyncio Futures.
queries (Dict[str, asyncio.Future]): Dictionary of query names and their Futures.
session (Optional[uuid.UUID]): The optional session UUID.
replies (Optional[Dict[str, Set[Type[Model]]]]): The optional dictionary of reply models.
replies (Optional[Dict[str, Set[Type[Model]]]]): Optional dictionary of reply models.
interval_messages (Optional[Set[str]]): The optional set of interval messages.
message_received (Optional[MsgDigest]): The optional message digest received.
protocols (Optional[Dict[str, Protocol]]): The optional dictionary of protocols.
Expand Down Expand Up @@ -188,7 +189,8 @@ def get_message_protocol(self, message_schema_digest) -> Optional[str]:
message_schema_digest (str): The schema digest of the message.
Returns:
Optional[str]: The protocol digest associated with the message schema digest, or None if not found.
Optional[str]: The protocol digest associated with the message schema digest,
or None if not found.
"""
for protocol_digest, protocol in self._protocols.items():
for reply_models in protocol.replies.values():
Expand Down
9 changes: 6 additions & 3 deletions src/uagents/network.py
Original file line number Diff line number Diff line change
Expand Up @@ -73,8 +73,10 @@ async def wait_for_tx_to_complete(
Args:
tx_hash (str): The hash of the transaction to monitor.
timeout (Optional[timedelta], optional): The maximum time to wait for the transaction to complete. Defaults to None.
poll_period (Optional[timedelta], optional): The time interval to poll the Ledger for the transaction status. Defaults to None.
timeout (Optional[timedelta], optional): The maximum time to wait for
the transaction to complete. Defaults to None.
poll_period (Optional[timedelta], optional): The time interval to poll
the Ledger for the transaction status. Defaults to None.
Returns:
TxResponse: The response object containing the transaction details.
Expand Down Expand Up @@ -343,7 +345,8 @@ def get_registration_tx(
domain (str): The domain in which the name is registered.
Returns:
Optional[Transaction]: The registration transaction, or None if the name is not available or not owned by the wallet address.
Optional[Transaction]: The registration transaction, or None if the name is not
available or not owned by the wallet address.
"""
if not self.is_name_available(name, domain) and not self.is_owner(
name, domain, wallet_address
Expand Down
Loading

0 comments on commit 7aab06b

Please sign in to comment.