Skip to content

Commit

Permalink
Merge remote-tracking branch 'origin/main' into tests/ipfs_download_r…
Browse files Browse the repository at this point in the history
…etries
  • Loading branch information
Karrenbelt committed Dec 23, 2022
2 parents 05e6949 + bee3c9c commit cb15961
Show file tree
Hide file tree
Showing 42 changed files with 860 additions and 160 deletions.
3 changes: 3 additions & 0 deletions aea/cli/test.py
Original file line number Diff line number Diff line change
Expand Up @@ -62,6 +62,9 @@
COVERAGERC_CONFIG = """[run]
omit =
*/tests/*
*/.tox/*
*/*_pb2.py
*/*_pb2_*.py
[html]
directory = {root_dir}/htmlcov
Expand Down
6 changes: 3 additions & 3 deletions aea/helpers/env_vars.py
Original file line number Diff line number Diff line change
Expand Up @@ -22,7 +22,7 @@
import json
import re
from collections.abc import Mapping as MappingType
from typing import Any, Dict, List, Mapping, Optional, Union, cast
from typing import Any, Dict, List, Mapping, Optional, Tuple, Union, cast

from aea.configurations.data_types import PublicId
from aea.helpers.constants import (
Expand Down Expand Up @@ -181,7 +181,7 @@ def apply_env_variables_on_agent_config(
return [cast(Dict, agent_config_new), *overrides_new]


def is_strict_list(data: List) -> bool:
def is_strict_list(data: Union[List, Tuple]) -> bool:
"""
Check if a data list is an strict list
Expand All @@ -208,7 +208,7 @@ def is_strict_list(data: List) -> bool:
for obj in data:
if isinstance(obj, dict):
return False
if isinstance(obj, list):
if isinstance(obj, (list, tuple)):
if not is_strict_list(data=obj):
return False
return is_strict
Expand Down
25 changes: 23 additions & 2 deletions aea/package_manager/base.py
Original file line number Diff line number Diff line change
Expand Up @@ -45,7 +45,7 @@
from aea_cli_ipfs.registry import fetch_ipfs # type: ignore

IS_IPFS_PLUGIN_INSTALLED = True
except (ImportError, ModuleNotFoundError):
except (ImportError, ModuleNotFoundError): # pragma: nocover # cause obvious
IS_IPFS_PLUGIN_INSTALLED = False

PACKAGES_FILE = "packages.json"
Expand Down Expand Up @@ -119,7 +119,6 @@ def _sync(

for package_id in packages:
package_path = self.package_path_from_package_id(package_id)

if package_path.exists():
package_hash = IPFSHashOnly.get(str(package_path))
expected_hash = packages[package_id]
Expand Down Expand Up @@ -181,6 +180,28 @@ def check_dependencies(
)
return mismatches

def is_dependencies_hashes_match(
self, package_id: PackageId, configuration_obj: PackageConfiguration
) -> bool:
"""Check dependecies hashes match and print errors"""
dependencies_with_mismatched_hashes = self.check_dependencies(
configuration=configuration_obj,
)
for dep, failure in dependencies_with_mismatched_hashes:
if failure == DepedencyMismatchErrors.HASH_NOT_FOUND:
self._logger.error(
f"Package contains a dependency that is not defined in the `packages.json`"
f"\n\tPackage: {package_id}\n\tDependency: {dep.without_hash()}"
)
continue

if failure == DepedencyMismatchErrors.HASH_DOES_NOT_MATCH:
self._logger.error(
f"Dependency check failed\nHash does not match for {dep.without_hash()} in {package_id} configuration."
)
continue
return not dependencies_with_mismatched_hashes

def _get_package_configuration(self, package_id: PackageId) -> PackageConfiguration:
"""Get package configuration by package_id."""
package_path = self.package_path_from_package_id(package_id)
Expand Down
20 changes: 2 additions & 18 deletions aea/package_manager/v0.py
Original file line number Diff line number Diff line change
Expand Up @@ -32,7 +32,6 @@
from aea.package_manager.base import (
BasePackageManager,
ConfigLoaderCallableType,
DepedencyMismatchErrors,
PACKAGES_FILE,
PackageIdToHashMapping,
load_configuration,
Expand Down Expand Up @@ -171,24 +170,9 @@ def verify(
failed = True
continue

dependencies_with_mismatched_hashes = self.check_dependencies(
configuration=configuration_obj,
)
if len(dependencies_with_mismatched_hashes) > 0:
for dep, failure in dependencies_with_mismatched_hashes:
if failure == DepedencyMismatchErrors.HASH_NOT_FOUND:
self._logger.error(
f"Package contains a dependency that is not defined in the `packages.json`"
f"\n\tPackage: {package_id}\n\tDependency: {dep.without_hash()}"
)
continue

if failure == DepedencyMismatchErrors.HASH_DOES_NOT_MATCH:
self._logger.error(
f"Dependency check failed\nHash does not match for {dep.without_hash()} in {package_id} configuration."
)
continue
if not self.is_dependencies_hashes_match(package_id, configuration_obj):
failed = True

except Exception: # pylint: disable=broad-except
traceback.print_exc()
failed = True
Expand Down
46 changes: 16 additions & 30 deletions aea/package_manager/v1.py
Original file line number Diff line number Diff line change
Expand Up @@ -23,17 +23,16 @@
import traceback
from collections import OrderedDict
from pathlib import Path
from typing import Optional
from typing import Dict, Optional
from typing import OrderedDict as OrderedDictType
from typing import Union, cast

from aea.configurations.data_types import PackageId
from aea.helpers.fingerprint import check_fingerprint
from aea.helpers.io import open_file
from aea.helpers.ipfs.base import IPFSHashOnly
from aea.package_manager.base import (
BasePackageManager,
ConfigLoaderCallableType,
DepedencyMismatchErrors,
PACKAGES_FILE,
PackageFileNotValid,
PackageIdToHashMapping,
Expand Down Expand Up @@ -219,6 +218,11 @@ def update_package_hashes(self) -> "PackageManagerV1":

return self

@staticmethod
def _calculate_hash(package_path: Union[Path, str]) -> str:
"""Calculate hash for path."""
return IPFSHashOnly.get(str(package_path))

def verify(
self,
) -> int:
Expand All @@ -232,9 +236,10 @@ def verify(
configuration_obj = self._get_package_configuration(
package_id=package_id
)
calculated_hash = IPFSHashOnly.get(str(package_path))

calculated_hash = self._calculate_hash(str(package_path))
fingerprint_check = check_fingerprint(configuration_obj)

if not fingerprint_check:
failed = True
self._logger.error(
Expand All @@ -251,7 +256,6 @@ def verify(
failed = True
self._logger.error(f"Cannot find hash for {package_id}")
continue

if calculated_hash != expected_hash:
# this update is required for further dependency checks for
# packages where this package is a dependency
Expand All @@ -265,29 +269,7 @@ def verify(
failed = True
continue

dependencies_with_mismatched_hashes = self.check_dependencies(
configuration_obj
)
if len(dependencies_with_mismatched_hashes) > 0:
package_type = (
"Third party"
if self.is_third_party_package(package_id)
else "Dev"
)
for dep, failure in dependencies_with_mismatched_hashes:
if failure == DepedencyMismatchErrors.HASH_NOT_FOUND:
self._logger.error(
f"{package_type} package contains a dependency that is not defined in the `packages.json`"
f"\n\tPackage: {package_id}\n\tDependency: {dep.without_hash()}"
)
continue

if failure == DepedencyMismatchErrors.HASH_DOES_NOT_MATCH:
self._logger.error(
f"Dependency check failed\nHash does not match for {dep.without_hash()} in {package_id} configuration."
)
continue

if not self.is_dependencies_hashes_match(package_id, configuration_obj):
failed = True

except Exception: # pylint: disable=broad-except
Expand All @@ -314,6 +296,11 @@ def json(

return data

@staticmethod
def _load_packages(packages_file: Path) -> Dict[str, Dict[str, str]]:
"""Load packages json file."""
return cast(Dict, json.loads(packages_file.read_text()))

@classmethod
def from_dir(
cls,
Expand All @@ -322,8 +309,7 @@ def from_dir(
) -> "PackageManagerV1":
"""Initialize from packages directory."""
packages_file = packages_dir / PACKAGES_FILE
with open_file(packages_file, "r") as fp:
_packages = json.load(fp)
_packages = cls._load_packages(packages_file)

if "dev" not in _packages or "third_party" not in _packages:
raise PackageFileNotValid("Package file not valid.")
Expand Down
8 changes: 2 additions & 6 deletions aea/runtime.py
Original file line number Diff line number Diff line change
Expand Up @@ -389,12 +389,8 @@ async def _start_agent_loop(self) -> None:
)

self._state.set(RuntimeStates.running)
try:
await self.agent_loop.wait_completed()
except asyncio.CancelledError:
self.agent_loop.stop()
await self.agent_loop.wait_completed()
raise
# loop will be stopped in wait completed
await self.agent_loop.wait_completed()


class ThreadedRuntime(AsyncRuntime):
Expand Down
2 changes: 1 addition & 1 deletion docs/api/helpers/env_vars.md
Original file line number Diff line number Diff line change
Expand Up @@ -69,7 +69,7 @@ Create new resulting dict with env variables applied.
#### is`_`strict`_`list

```python
def is_strict_list(data: List) -> bool
def is_strict_list(data: Union[List, Tuple]) -> bool
```

Check if a data list is an strict list
Expand Down
10 changes: 10 additions & 0 deletions docs/api/package_manager/base.md
Original file line number Diff line number Diff line change
Expand Up @@ -73,6 +73,16 @@ def check_dependencies(configuration: PackageConfiguration) -> List[Tuple[Packag

Verify hashes for package dependecies againts the available hashes.

<a id="aea.package_manager.base.BasePackageManager.is_dependencies_hashes_match"></a>

#### is`_`dependencies`_`hashes`_`match

```python
def is_dependencies_hashes_match(package_id: PackageId, configuration_obj: PackageConfiguration) -> bool
```

Check dependecies hashes match and print errors

<a id="aea.package_manager.base.BasePackageManager.get_package_dependencies"></a>

#### get`_`package`_`dependencies
Expand Down
4 changes: 2 additions & 2 deletions docs/gym-skill.md
Original file line number Diff line number Diff line change
Expand Up @@ -19,7 +19,7 @@ Follow the <a href="../quickstart/#preliminaries">Preliminaries</a> and <a href=

First, fetch the gym AEA:
``` bash
aea fetch open_aea/gym_aea:0.1.0:bafybeidkfolcgqh5mmdcmd7vee74avhicgiahdyiflyylanowxmqc7bxni --remote
aea fetch open_aea/gym_aea:0.1.0:bafybeidgnc6yoyzyjpekrcijhioe4orcfw325yjb4hw7mmfocbnd6z4rja --remote
cd gym_aea
aea install
```
Expand All @@ -36,7 +36,7 @@ cd my_gym_aea

### Add the gym skill
``` bash
aea add skill fetchai/gym:0.20.0:bafybeid53vlpk2jwdzqf7a5xh4q5653wg46h7eg7pq66c3pmmgwnwjnsja --remote
aea add skill fetchai/gym:0.20.0:bafybeiejzgnbm3mprvt3riytwbnlrl3bdqduubr5qqc7tfthheu36yoqua --remote
```

### Set gym connection as default
Expand Down
2 changes: 1 addition & 1 deletion docs/http-connection-and-skill.md
Original file line number Diff line number Diff line change
Expand Up @@ -29,7 +29,7 @@ Add the http server connection package:
mkdir packages
aea create my_aea
cd my_aea
aea add connection fetchai/http_server:0.22.0:bafybeiaf2w3jfemqu4zrtfzewexh5ttqytvhv4tqfzcrv6qxsqnxrv7eu4 --remote
aea add connection fetchai/http_server:0.22.0:bafybeidxb5gk3samqoflbztqnlnqtvtph5emobaojx3w47674ay5d7pmeu --remote
aea push connection fetchai/http_server --local
aea add protocol fetchai/default:1.0.0:bafybeihzesahyayexkhk26fg7rqnjuqaab3bmcijtjekvskvs4xw6ecyuu --remote
aea push protocol fetchai/default --local
Expand Down
2 changes: 1 addition & 1 deletion docs/http-echo-demo.md
Original file line number Diff line number Diff line change
Expand Up @@ -16,7 +16,7 @@ The easiest way to get started with the http server is to use our pre-built exam

``` bash
pipenv shell
aea fetch open_aea/http_echo:0.1.0:bafybeihxe5mk2gs6k3xxf5rgaqqa5ij2ff74gebcwxskc2dpxvt5rcnyxi --remote
aea fetch open_aea/http_echo:0.1.0:bafybeifx3fqbwsggrm4ccztv56xt5xohgyf3g32ieryfxkm2jnuxo7raqq --remote
cd http_echo
aea generate-key ethereum; aea add-key ethereum
aea install
Expand Down
22 changes: 11 additions & 11 deletions docs/package_list.md
Original file line number Diff line number Diff line change
@@ -1,15 +1,15 @@
| Package name | Package hash |
| ------------------------------------------------------------- | ------------------------------------------------------------- |
| protocol/fetchai/gym/1.0.0 | `bafybeihpjm2sgnrpuwaqicikw4aybltm7xrjmf7cscpp2cy2xdoi6pekbq` |
| connection/fetchai/gym/0.19.0 | `bafybeiak5qnlo4b6ai5ep5cp5tyw26dyv5finwjcbwo3aryhtjqmdl2keu` |
| connection/fetchai/gym/0.19.0 | `bafybeicehd5z4aktwtffytkrqiq7b4ui2grdf4yvqfpiczjp3gtmmxngqu` |
| protocol/fetchai/default/1.0.0 | `bafybeihzesahyayexkhk26fg7rqnjuqaab3bmcijtjekvskvs4xw6ecyuu` |
| protocol/valory/acn/1.1.0 | `bafybeifontek6tvaecatoauiule3j3id6xoktpjubvuqi3h2jkzqg7zh7a` |
| protocol/valory/contract_api/1.0.0 | `bafybeiaxbrvgtbdrh4lslskuxyp4awyr4whcx3nqq5yrr6vimzsxg5dy64` |
| protocol/valory/http/1.0.0 | `bafybeigzqo2zaakcjtzzsm6dh4x73v72xg6ctk6muyp5uq5ueb7y34fbxy` |
| protocol/valory/ledger_api/1.0.0 | `bafybeih7rhi5zvfvwakx5ifgxsz2cfipeecsh7bm3gnudjxtvhrygpcftq` |
| connection/fetchai/http_server/0.22.0 | `bafybeiaf2w3jfemqu4zrtfzewexh5ttqytvhv4tqfzcrv6qxsqnxrv7eu4` |
| connection/fetchai/http_server/0.22.0 | `bafybeidxb5gk3samqoflbztqnlnqtvtph5emobaojx3w47674ay5d7pmeu` |
| connection/fetchai/stub/0.21.0 | `bafybeieqlozydyvdxmjxhqygwq27djecpiftoqwlcpcr4qpotomwnh66yy` |
| connection/valory/ledger/0.19.0 | `bafybeiadc25se7dgnn4mufztwpzdono4xsfs45qknzdqyi3gckn6ccuv44` |
| connection/valory/ledger/0.19.0 | `bafybeibkvdh2j4gslnaa56kwihm7l32ofqdzwhnx6r4ga4v65k6ccwgfum` |
| connection/valory/p2p_libp2p/0.1.0 | `bafybeihjlcop2vvpqfjqcwc4lqgbvktxgc3frhtsbusjypcmefrape2h3u` |
| connection/valory/p2p_libp2p_client/0.1.0 | `bafybeidkk33xbga54szmitk6uwsi3ef56hbbdbuasltqtiyki34hgfpnxa` |
| connection/valory/p2p_libp2p_mailbox/0.1.0 | `bafybeihjjsenbsgh6x2vukea7mqzsbcbqqbog6xa43raen24ewqf4qq3pm` |
Expand All @@ -20,22 +20,22 @@
| protocol/open_aea/signing/1.0.0 | `bafybeiambqptflge33eemdhis2whik67hjplfnqwieoa6wblzlaf7vuo44` |
| skill/fetchai/echo/0.19.0 | `bafybeia3ovoxmnipktwnyztie55itsuempnfeircw72jn62uojzry5pwsu` |
| skill/fetchai/error_test_skill/0.1.0 | `bafybeihsbtlpe7h6fsvoxban5rilkmwviwkokul5cqym6atoolirontiyu` |
| skill/fetchai/gym/0.20.0 | `bafybeid53vlpk2jwdzqf7a5xh4q5653wg46h7eg7pq66c3pmmgwnwjnsja` |
| skill/fetchai/gym/0.20.0 | `bafybeiejzgnbm3mprvt3riytwbnlrl3bdqduubr5qqc7tfthheu36yoqua` |
| skill/fetchai/http_echo/0.20.0 | `bafybeickwfnhufcaift5k6uspltvhatdpmppyhfzghewecctgq72dgu5a4` |
| agent/fetchai/error_test/0.1.0 | `bafybeigercyzr4qscyf4bp22jwehyoxhcix6yyuxhfec2n5umns3qcm7aq` |
| agent/fetchai/gym_aea/0.25.0 | `bafybeic7lugvrrlcre42evfnttonheppvpvupg3wgraizkyrorheicooem` |
| agent/fetchai/gym_aea/0.25.0 | `bafybeicdufnk7w7kqfzznl3oor3br7ufxepvge5lvdhrf67ki6lbnuap74` |
| agent/fetchai/my_first_aea/0.27.0 | `bafybeic6plxxhcbokxlce3grbgsm247rgvcb5arwwslm5yv6pt46byr22a` |
| agent/open_aea/gym_aea/0.1.0 | `bafybeidkfolcgqh5mmdcmd7vee74avhicgiahdyiflyylanowxmqc7bxni` |
| agent/open_aea/http_echo/0.1.0 | `bafybeihxe5mk2gs6k3xxf5rgaqqa5ij2ff74gebcwxskc2dpxvt5rcnyxi` |
| agent/open_aea/gym_aea/0.1.0 | `bafybeidgnc6yoyzyjpekrcijhioe4orcfw325yjb4hw7mmfocbnd6z4rja` |
| agent/open_aea/http_echo/0.1.0 | `bafybeifx3fqbwsggrm4ccztv56xt5xohgyf3g32ieryfxkm2jnuxo7raqq` |
| agent/open_aea/my_first_aea/0.1.0 | `bafybeifelwg4md24lwpxgx7x5cugq7ovhbkew3lxw43m52rdppfn5o5g4i` |
| connection/fetchai/local/0.20.0 | `bafybeianwid4lh3ubjheg4ho7qznuib2t6k35rcuconcbwtzmih4qdxo2i` |
| connection/valory/http_client/0.23.0 | `bafybeihz3tubwado7j3wlivndzzuj3c6fdsp4ra5r3nqixn3ufawzo3wii` |
| connection/valory/test_libp2p/0.1.0 | `bafybeigbkr22vy4bxfl3hohjzwxj76wn5y77ssrsdeqqiu3a7yrpkqpfle` |
| protocol/fetchai/tac/1.0.0 | `bafybeiaew226n32rwp3h57zl4b2mmbrhjbyrdjbl2evnxf2tmmi4vrls7a` |
| skill/fetchai/erc1155_client/0.28.0 | `bafybeigjapreaqjqvcukrnqr4fzlrugl3635bh2abj3tnxqq247swqtl7u` |
| skill/fetchai/erc1155_deploy/0.30.0 | `bafybeibtjaylkd47ghbwgl7rdck2exvnrodwnyjhfvrtaluwrvkx5k5gtq` |
| skill/fetchai/erc1155_client/0.28.0 | `bafybeiecwwk7nesipstq7acvrkjv2byze27t2n6jlnxwggl3ppcbybuoum` |
| skill/fetchai/erc1155_deploy/0.30.0 | `bafybeiapnneoqjkb7wzzbdsvrs6jga6kstmiw6rkqgvbwk4jmwyisc2rbi` |
| skill/fetchai/error/0.17.0 | `bafybeib7nhokw3bc46oxuk5mjazan42evipowmka2ikfcs6drcdz4mwkjm` |
| skill/fetchai/fipa_dummy_buyer/0.2.0 | `bafybeiha4jultg5srhr2ijplvubeo7esv4raq2cjlggmyzcaimop2ggg2m` |
| skill/fetchai/generic_buyer/0.26.0 | `bafybeicutlnmjjovt6ttg4w4tb47dgudwilm7esak2fi2pbghfp4wfabhq` |
| skill/fetchai/generic_seller/0.27.0 | `bafybeidjpgp323esan54fjxr6xqnq365oqi5g45p3nts67e3su6u4kss3y` |
| skill/fetchai/generic_buyer/0.26.0 | `bafybeicxrsrb3bg3c3uziojqzlocw74tp665q6of34zvcprl6ffccq6klu` |
| skill/fetchai/generic_seller/0.27.0 | `bafybeiefbhuiax2bqgmrztugtii36ob2hw7tsreoyqnsrqxsqz36bdfjfy` |
| skill/fetchai/task_test_skill/0.1.0 | `bafybeidv77u2xl52mnxakwvh7fuh46aiwfpteyof4eaptfd4agoi6cdble` |
4 changes: 2 additions & 2 deletions packages/fetchai/agents/gym_aea/aea-config.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -9,15 +9,15 @@ fingerprint:
README.md: bafybeiadln5ca6tu6rzbsgjpeluf6nz5efxl3u223c3vxwgf2iynkj5n6q
fingerprint_ignore_patterns: []
connections:
- fetchai/gym:0.19.0:bafybeiak5qnlo4b6ai5ep5cp5tyw26dyv5finwjcbwo3aryhtjqmdl2keu
- fetchai/gym:0.19.0:bafybeicehd5z4aktwtffytkrqiq7b4ui2grdf4yvqfpiczjp3gtmmxngqu
contracts: []
protocols:
- fetchai/default:1.0.0:bafybeihzesahyayexkhk26fg7rqnjuqaab3bmcijtjekvskvs4xw6ecyuu
- fetchai/gym:1.0.0:bafybeihpjm2sgnrpuwaqicikw4aybltm7xrjmf7cscpp2cy2xdoi6pekbq
- fetchai/state_update:1.0.0:bafybeidtndlmppst6l6iughpflqbbbkzditixo2fy2dncxfkb5apkx5y4m
- open_aea/signing:1.0.0:bafybeiambqptflge33eemdhis2whik67hjplfnqwieoa6wblzlaf7vuo44
skills:
- fetchai/gym:0.20.0:bafybeid53vlpk2jwdzqf7a5xh4q5653wg46h7eg7pq66c3pmmgwnwjnsja
- fetchai/gym:0.20.0:bafybeiejzgnbm3mprvt3riytwbnlrl3bdqduubr5qqc7tfthheu36yoqua
default_connection: fetchai/gym:0.19.0
default_ledger: fetchai
required_ledgers:
Expand Down
2 changes: 1 addition & 1 deletion packages/fetchai/connections/gym/connection.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -10,7 +10,7 @@ fingerprint:
__init__.py: bafybeiacpcxqwod5ppgwckp36jj3ax2ymzkrv4tlalzcatxrx4tblbvfvq
connection.py: bafybeiacf4utttdtrp2zb5wjrksatswb7dtlgnzafxiofuvzxot53oqdd4
tests/__init__.py: bafybeidgl3l7pzmg4upgkkfnq2kgbgzppkt5xy2tbottj3jqse2pf7juqm
tests/test_gym.py: bafybeigyry6mxho2kww5ih5hat5e2ppfqmkgqky4xfdsmu2sxeowarg6si
tests/test_gym.py: bafybeic2zyv2h2zdygrfjw2ix3vhmdoumofnj3zitn3fnhsowr7l7vpuea
fingerprint_ignore_patterns: []
connections: []
protocols:
Expand Down
Loading

0 comments on commit cb15961

Please sign in to comment.