Skip to content

Commit

Permalink
Merge pull request #1520 from fetchai/develop
Browse files Browse the repository at this point in the history
Release 0.5.2
  • Loading branch information
DavidMinarsch authored Jul 21, 2020
2 parents b59aa24 + 59f66e2 commit 68ea55d
Show file tree
Hide file tree
Showing 333 changed files with 10,228 additions and 6,784 deletions.
10 changes: 10 additions & 0 deletions HISTORY.md
Original file line number Diff line number Diff line change
@@ -1,5 +1,15 @@
# Release History

## 0.5.2 (2020-07-21)

- Transitions demos to agent-land test network, P2P and SOEF connections
- Adds full test coverage for helpers modules
- Adds full test coverage for core modules
- Adds CLI functionality to upload README.md files with packages
- Adds full test coverage for registries module
- Multiple docs updates
- Multiple additional tests and test stability fixes

## 0.5.1 (2020-07-14)

- Adds support for agent name being appended to all log statements
Expand Down
2 changes: 1 addition & 1 deletion MANIFEST.in
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
include README.md LICENSE HISTORY.md AUTHORS.md SECURITY.md CODE_OF_CONDUCT.md Pipfile mkdocs.yml tox.ini pytest.ini strategy.ini

recursive-include aea *.json *.yaml *.proto
recursive-include aea *.json *.yaml *.proto *.ico *png *.html *.js *.css
recursive-include docs *
recursive-include examples *
recursive-include packages *
Expand Down
2 changes: 1 addition & 1 deletion Pipfile
Original file line number Diff line number Diff line change
Expand Up @@ -39,7 +39,7 @@ openapi-spec-validator = "==0.2.8"
pexpect = "==4.8.0"
psutil = "==5.7.0"
pydocstyle = "==3.0.0"
pydoc-markdown = "==3.1.0"
pydoc-markdown = "==3.3.0"
pygments = "==2.5.2"
pylint = "==2.5.2"
pymdown-extensions = "==6.3"
Expand Down
2 changes: 1 addition & 1 deletion aea/__version__.py
Original file line number Diff line number Diff line change
Expand Up @@ -22,7 +22,7 @@
__title__ = "aea"
__description__ = "Autonomous Economic Agent framework"
__url__ = "https://github.com/fetchai/agents-aea.git"
__version__ = "0.5.1"
__version__ = "0.5.2"
__author__ = "Fetch.AI Limited"
__license__ = "Apache-2.0"
__copyright__ = "2019 Fetch.AI Limited"
17 changes: 10 additions & 7 deletions aea/aea.py
Original file line number Diff line number Diff line change
Expand Up @@ -75,7 +75,7 @@ def __init__(
default_connection: Optional[PublicId] = None,
default_routing: Optional[Dict[PublicId, PublicId]] = None,
connection_ids: Optional[Collection[PublicId]] = None,
search_service_address: str = "oef",
search_service_address: str = "fetchai/soef:*",
**kwargs,
) -> None:
"""
Expand Down Expand Up @@ -164,7 +164,7 @@ def task_manager(self) -> TaskManager:
return self._task_manager

def setup_multiplexer(self) -> None:
"""Set up the multiplexer"""
"""Set up the multiplexer."""
connections = self.resources.get_all_connections()
if self._connection_ids is not None:
connections = [
Expand Down Expand Up @@ -245,6 +245,10 @@ def _react_one(self) -> None:
if envelope is not None:
self._handle(envelope)

def _get_error_handler(self) -> Optional[Handler]:
"""Get error hadnler."""
return self.resources.get_handler(DefaultMessage.protocol_id, DEFAULT_SKILL)

def _handle(self, envelope: Envelope) -> None:
"""
Handle an envelope.
Expand All @@ -256,9 +260,7 @@ def _handle(self, envelope: Envelope) -> None:
protocol = self.resources.get_protocol(envelope.protocol_id)

# TODO specify error handler in config and make this work for different skill/protocol versions.
error_handler = self.resources.get_handler(
DefaultMessage.protocol_id, DEFAULT_SKILL
)
error_handler = self._get_error_handler()

if error_handler is None:
logger.warning("ErrorHandler not initialized. Stopping AEA!")
Expand All @@ -285,6 +287,7 @@ def _handle(self, envelope: Envelope) -> None:
handlers = self.filter.get_active_handlers(
protocol.public_id, envelope.skill_id
)

if len(handlers) == 0:
error_handler.send_unsupported_skill(envelope)
return
Expand Down Expand Up @@ -366,7 +369,7 @@ def update(self) -> None:
:return None
"""
self.filter.handle_internal_messages()
self.filter.handle_internal_messages() # pragma: nocover

def teardown(self) -> None:
"""
Expand All @@ -388,7 +391,7 @@ def teardown(self) -> None:
ExecTimeoutThreadGuard.stop()

def _setup_loggers(self):
"""Setup logger with agent name. """
"""Set up logger with agent name."""
for element in [
self.main_loop,
self.multiplexer,
Expand Down
93 changes: 32 additions & 61 deletions aea/aea_builder.py
Original file line number Diff line number Diff line change
Expand Up @@ -65,6 +65,7 @@
)
from aea.configurations.constants import (
DEFAULT_CONNECTION,
DEFAULT_LEDGER,
DEFAULT_PROTOCOL,
DEFAULT_SKILL,
)
Expand Down Expand Up @@ -208,6 +209,7 @@ def remove_component(self, component_id: ComponentId):
component = self._dependencies.pop(component_id)
# remove from the index of all dependencies grouped by type
self._all_dependencies_by_type[component_id.component_type].pop(component_id)

if len(self._all_dependencies_by_type[component_id.component_type]) == 0:
self._all_dependencies_by_type.pop(component_id.component_type)
# remove from prefix to id index
Expand Down Expand Up @@ -236,14 +238,6 @@ def pypi_dependencies(self) -> Dependencies:
)
return all_pypi_dependencies

@staticmethod
def _build_dotted_part(component, relative_import_path) -> str:
"""Given a component, build a dotted path for import."""
if relative_import_path == "":
return component.prefix_import_path
else:
return component.prefix_import_path + "." + relative_import_path


class AEABuilder:
"""
Expand Down Expand Up @@ -302,7 +296,7 @@ class AEABuilder:
DEFAULT_SKILL_EXCEPTION_POLICY = ExceptionPolicyEnum.propagate
DEFAULT_LOOP_MODE = "async"
DEFAULT_RUNTIME_MODE = "threaded"
DEFAULT_SEARCH_SERVICE_ADDRESS = "oef"
DEFAULT_SEARCH_SERVICE_ADDRESS = "fetchai/soef:*"

# pylint: disable=attribute-defined-outside-init

Expand Down Expand Up @@ -352,10 +346,7 @@ def _reset(self, is_full_reset: bool = False) -> None:
self._build_called: bool = False
if not is_full_reset:
return
self._ledger_apis_configs = {} # type: Dict[str, Dict[str, Union[str, int]]]
self._default_ledger = (
"fetchai" # set by the user, or instantiate a default one.
)
self._default_ledger = DEFAULT_LEDGER
self._default_connection: PublicId = DEFAULT_CONNECTION
self._context_namespace = {} # type: Dict[str, Any]
self._timeout: Optional[float] = None
Expand Down Expand Up @@ -430,7 +421,7 @@ def set_decision_maker_handler(
try:
_class = getattr(module, class_name)
self._decision_maker_handler_class = _class
except Exception as e:
except Exception as e: # pragma: nocover
logger.error(
"Could not locate decision maker handler for dotted path '{}', class name '{}' and file path '{}'. Error message: {}".format(
dotted_path, class_name, file_path, e
Expand All @@ -442,7 +433,7 @@ def set_decision_maker_handler(

def set_skill_exception_policy(
self, skill_exception_policy: Optional[ExceptionPolicyEnum]
) -> "AEABuilder":
) -> "AEABuilder": # pragma: nocover
"""
Set skill exception policy.
Expand All @@ -465,10 +456,12 @@ def set_default_routing(
:return: self
"""
self._default_routing = default_routing
self._default_routing = default_routing # pragma: nocover
return self

def set_loop_mode(self, loop_mode: Optional[str]) -> "AEABuilder":
def set_loop_mode(
self, loop_mode: Optional[str]
) -> "AEABuilder": # pragma: nocover
"""
Set the loop mode.
Expand All @@ -478,7 +471,9 @@ def set_loop_mode(self, loop_mode: Optional[str]) -> "AEABuilder":
self._loop_mode = loop_mode
return self

def set_runtime_mode(self, runtime_mode: Optional[str]) -> "AEABuilder":
def set_runtime_mode(
self, runtime_mode: Optional[str]
) -> "AEABuilder": # pragma: nocover
"""
Set the runtime mode.
Expand All @@ -488,7 +483,9 @@ def set_runtime_mode(self, runtime_mode: Optional[str]) -> "AEABuilder":
self._runtime_mode = runtime_mode
return self

def set_search_service_address(self, search_service_address: str) -> "AEABuilder":
def set_search_service_address(
self, search_service_address: str
) -> "AEABuilder": # pragma: nocover
"""
Set the search service address.
Expand Down Expand Up @@ -533,7 +530,7 @@ def _check_can_add(self, configuration: ComponentConfiguration) -> None:
self._check_package_dependencies(configuration)
self._check_pypi_dependencies(configuration)

def set_name(self, name: str) -> "AEABuilder":
def set_name(self, name: str) -> "AEABuilder": # pragma: nocover
"""
Set the name of the agent.
Expand All @@ -543,7 +540,9 @@ def set_name(self, name: str) -> "AEABuilder":
self._name = name
return self

def set_default_connection(self, public_id: PublicId) -> "AEABuilder":
def set_default_connection(
self, public_id: PublicId
) -> "AEABuilder": # pragma: nocover
"""
Set the default connection.
Expand Down Expand Up @@ -606,33 +605,7 @@ def connection_private_key_paths(self) -> Dict[str, Optional[str]]:
"""Get the connection private key paths."""
return self._connection_private_key_paths

def add_ledger_api_config(self, identifier: str, config: Dict) -> "AEABuilder":
"""
Add a configuration for a ledger API to be supported by the agent.
:param identifier: the identifier of the ledger api
:param config: the configuration of the ledger api
:return: the AEABuilder
"""
self._ledger_apis_configs[identifier] = config
return self

def remove_ledger_api_config(self, identifier: str) -> "AEABuilder":
"""
Remove a ledger API configuration.
:param identifier: the identifier of the ledger api
:return: the AEABuilder
"""
self._ledger_apis_configs.pop(identifier, None)
return self

@property
def ledger_apis_config(self) -> Dict[str, Dict[str, Union[str, int]]]:
"""Get the ledger api configurations."""
return self._ledger_apis_configs

def set_default_ledger(self, identifier: str) -> "AEABuilder":
def set_default_ledger(self, identifier: str) -> "AEABuilder": # pragma: nocover
"""
Set a default ledger API to use.
Expand Down Expand Up @@ -689,7 +662,9 @@ def add_component_instance(self, component: Component) -> "AEABuilder":
] = component
return self

def set_context_namespace(self, context_namespace: Dict[str, Any]) -> "AEABuilder":
def set_context_namespace(
self, context_namespace: Dict[str, Any]
) -> "AEABuilder": # pragma: nocover
"""Set the context namespace."""
self._context_namespace = context_namespace
return self
Expand Down Expand Up @@ -1123,13 +1098,13 @@ def _try_to_load_agent_configuration_file(aea_project_path: Path) -> None:
loader = ConfigLoader.from_configuration_type(PackageType.AGENT)
agent_configuration = loader.load(fp)
logging.config.dictConfig(agent_configuration.logging_config) # type: ignore
except FileNotFoundError:
except FileNotFoundError: # pragma: nocover
raise Exception(
"Agent configuration file '{}' not found in the current directory.".format(
DEFAULT_AEA_CONFIG_FILE
)
)
except jsonschema.exceptions.ValidationError:
except jsonschema.exceptions.ValidationError: # pragma: nocover
raise Exception(
"Agent configuration file '{}' is invalid. Please check the documentation.".format(
DEFAULT_AEA_CONFIG_FILE
Expand Down Expand Up @@ -1198,13 +1173,6 @@ def set_from_configuration(
ledger_identifier, private_key_path, is_connection=True
)

# load ledger API configurations
for (
ledger_identifier,
ledger_api_conf,
) in agent_configuration.ledger_apis_dict.items():
self.add_ledger_api_config(ledger_identifier, ledger_api_conf)

component_ids = itertools.chain(
[
ComponentId(ComponentType.PROTOCOL, p_id)
Expand Down Expand Up @@ -1284,6 +1252,7 @@ def _find_import_order(

if len(configuration.skills) != 0:
roots.remove(skill_id)

depends_on[skill_id].update(
[
ComponentId(ComponentType.SKILL, skill)
Expand All @@ -1300,7 +1269,9 @@ def _find_import_order(
while len(queue) > 0:
current = queue.pop()
order.append(current)
for node in supports[current]:
for node in supports[
current
]: # pragma: nocover # TODO: extract method and test properly
depends_on[node].discard(current)
if len(depends_on[node]) == 0:
queue.append(node)
Expand Down Expand Up @@ -1405,7 +1376,7 @@ def _populate_contract_registry(self):
class_kwargs={"contract_interface": contract_interface},
contract_config=configuration, # TODO: resolve configuration being applied globally
)
except AEAException as e:
except AEAException as e: # pragma: nocover
if "Cannot re-register id:" in str(e):
logger.warning(
"Already registered: {}".format(configuration.class_name)
Expand Down Expand Up @@ -1452,7 +1423,7 @@ def _verify_or_create_private_keys(aea_project_path: Path) -> None:

for identifier, _value in agent_configuration.private_key_paths.read_all():
if identifier not in crypto_registry.supported_ids:
ValueError("Unsupported identifier in private key paths.")
raise ValueError(f"Item not registered with id '{identifier}'.")

for identifier, private_key_path in IDENTIFIER_TO_KEY_FILES.items():
config_private_key_path = agent_configuration.private_key_paths.read(identifier)
Expand Down
10 changes: 3 additions & 7 deletions aea/agent_loop.py
Original file line number Diff line number Diff line change
Expand Up @@ -96,7 +96,7 @@ async def _gather_tasks(self) -> None:
await asyncio.gather(*self._tasks, loop=self._loop)

@abstractmethod
def _set_tasks(self) -> None:
def _set_tasks(self) -> None: # pragma: nocover
"""Set run loop tasks."""
raise NotImplementedError

Expand Down Expand Up @@ -219,7 +219,7 @@ def _unregister_behaviour(self, behaviour: Behaviour) -> None:
:return: None
"""
periodic_caller = self._behaviours_registry.pop(behaviour, None)
if periodic_caller is None:
if periodic_caller is None: # pragma: nocover
return
periodic_caller.stop()

Expand Down Expand Up @@ -260,13 +260,9 @@ def _create_tasks(self) -> List[Task]:
async def _task_process_inbox(self) -> None:
"""Process incoming messages."""
inbox: InBox = self._agent.inbox
self.logger.info("[{}]: Start processing messages...".format(self._agent.name))
self.logger.info("Start processing messages...")
while self.is_running:
await inbox.async_wait()

if not self.is_running: # make it close faster
return

self._agent.react()

async def _task_process_internal_messages(self) -> None:
Expand Down
Loading

0 comments on commit 68ea55d

Please sign in to comment.