Skip to content

Commit ad0562d

Browse files
Merge pull request #1911 from fetchai/develop
Release v0.7.2
2 parents 4c764b4 + 58e4dba commit ad0562d

85 files changed

Lines changed: 1280 additions & 376 deletions

File tree

Some content is hidden

Large Commits have some content hidden by default. Use the searchbox below for content that may be hidden.

HISTORY.md

Lines changed: 9 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,14 @@
11
# Release History
22

3+
## 0.7.2 (2020-11-09)
4+
5+
- Fixes some AW2 AEAs
6+
- Improves generic buyer AEA
7+
- Fixes a few backwards incompatibilities on CLI (upgrade, add, fetch) introduced in 0.7.1
8+
- Fixes geo locations in some tests
9+
- Multiple docs updates based on user feedback
10+
- Multiple additional tests and test stability fixes
11+
312
## 0.7.1 (2020-11-05)
413

514
- Adds two AEAs for Agent World 2

aea/__version__.py

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -22,7 +22,7 @@
2222
__title__ = "aea"
2323
__description__ = "Autonomous Economic Agent framework"
2424
__url__ = "https://github.com/fetchai/agents-aea.git"
25-
__version__ = "0.7.1"
25+
__version__ = "0.7.2"
2626
__author__ = "Fetch.AI Limited"
2727
__license__ = "Apache-2.0"
2828
__copyright__ = "2019 Fetch.AI Limited"

aea/cli/add.py

Lines changed: 65 additions & 20 deletions
Original file line numberDiff line numberDiff line change
@@ -18,13 +18,13 @@
1818
# ------------------------------------------------------------------------------
1919

2020
"""Implementation of the 'aea add' subcommand."""
21-
21+
from pathlib import Path
2222
from typing import cast
2323

2424
import click
2525

2626
from aea.cli.registry.add import fetch_package
27-
from aea.cli.utils.click_utils import PublicIdParameter
27+
from aea.cli.utils.click_utils import PublicIdParameter, registry_flag
2828
from aea.cli.utils.config import load_item_config
2929
from aea.cli.utils.context import Context
3030
from aea.cli.utils.decorators import check_aea_project, clean_after, pass_ctx
@@ -43,14 +43,14 @@
4343

4444

4545
@click.group()
46-
@click.option("--local", is_flag=True, help="For adding from local folder.")
46+
@registry_flag()
4747
@click.pass_context
4848
@check_aea_project
49-
def add(click_context, local):
49+
def add(click_context, local, remote):
5050
"""Add a resource to the agent."""
5151
ctx = cast(Context, click_context.obj)
52-
if local:
53-
ctx.set_config("is_local", True)
52+
ctx.set_config("is_local", local and not remote)
53+
ctx.set_config("is_mixed", not local and not remote)
5454

5555

5656
@add.command()
@@ -95,13 +95,7 @@ def add_item(ctx: Context, item_type: str, item_public_id: PublicId) -> None:
9595
:param item_public_id: the item public id.
9696
:return: None
9797
"""
98-
agent_name = cast(str, ctx.agent_config.agent_name)
99-
100-
click.echo(
101-
"Adding {} '{}' to the agent '{}'...".format(
102-
item_type, item_public_id, agent_name
103-
)
104-
)
98+
click.echo(f"Adding {item_type} '{item_public_id}'...")
10599
if is_item_present(ctx, item_type, item_public_id):
106100
present_item_id = get_item_id_present(ctx, item_type, item_public_id)
107101
raise click.ClickException(
@@ -112,16 +106,16 @@ def add_item(ctx: Context, item_type: str, item_public_id: PublicId) -> None:
112106

113107
dest_path = get_package_path(ctx, item_type, item_public_id)
114108
is_local = ctx.config.get("is_local")
109+
is_mixed = ctx.config.get("is_mixed")
115110

116111
ctx.clean_paths.append(dest_path)
117112

118-
is_distributed = is_distributed_item(item_public_id)
119-
if is_local and is_distributed: # pragma: nocover
120-
source_path = find_item_in_distribution(ctx, item_type, item_public_id)
121-
package_path = copy_package_directory(source_path, dest_path)
122-
elif is_local and not is_distributed:
123-
source_path, _ = find_item_locally(ctx, item_type, item_public_id)
124-
package_path = copy_package_directory(source_path, dest_path)
113+
if is_mixed:
114+
package_path = fetch_item_mixed(ctx, item_type, item_public_id, dest_path)
115+
elif is_local:
116+
package_path = find_item_locally_or_distributed(
117+
ctx, item_type, item_public_id, dest_path
118+
)
125119
else:
126120
package_path = fetch_package(
127121
item_type, public_id=item_public_id, cwd=ctx.cwd, dest=dest_path
@@ -167,3 +161,54 @@ def _add_item_deps(ctx: Context, item_type: str, item_config) -> None:
167161
for skill_public_id in item_config.skills:
168162
if skill_public_id not in ctx.agent_config.skills:
169163
add_item(ctx, "skill", skill_public_id)
164+
165+
166+
def find_item_locally_or_distributed(
167+
ctx: Context, item_type: str, item_public_id: PublicId, dest_path: str
168+
) -> Path:
169+
"""
170+
Unify find item locally both in case it is distributed or not.
171+
172+
:param ctx: the CLI context.
173+
:param item_type: the item type.
174+
:param item_public_id: the item public id.
175+
:param dest_path: the path to the destination.
176+
:return: the path to the found package.
177+
"""
178+
is_distributed = is_distributed_item(item_public_id)
179+
if is_distributed: # pragma: nocover
180+
source_path = find_item_in_distribution(ctx, item_type, item_public_id)
181+
package_path = copy_package_directory(source_path, dest_path)
182+
else:
183+
source_path, _ = find_item_locally(ctx, item_type, item_public_id)
184+
package_path = copy_package_directory(source_path, dest_path)
185+
186+
return package_path
187+
188+
189+
def fetch_item_mixed(
190+
ctx: Context, item_type: str, item_public_id: PublicId, dest_path: str,
191+
) -> Path:
192+
"""
193+
Find item, mixed mode.
194+
195+
That is, give priority to local registry, and fall back to remote registry
196+
in case of failure.
197+
198+
:param ctx: the CLI context.
199+
:param item_type: the item type.
200+
:param item_public_id: the item public id.
201+
:param dest_path: the path to the destination.
202+
:return: the path to the found package.
203+
"""
204+
try:
205+
package_path = find_item_locally_or_distributed(
206+
ctx, item_type, item_public_id, dest_path
207+
)
208+
except click.ClickException:
209+
click.echo("Fetch from local registry failed, trying remote registry...")
210+
# the following might raise exception, but we don't catch it this time
211+
package_path = fetch_package(
212+
item_type, public_id=item_public_id, cwd=ctx.cwd, dest=dest_path
213+
)
214+
return package_path

aea/cli/fetch.py

Lines changed: 24 additions & 36 deletions
Original file line numberDiff line numberDiff line change
@@ -49,10 +49,15 @@
4949
def fetch(click_context, public_id, alias, local, remote):
5050
"""Fetch Agent from Registry."""
5151
ctx = cast(Context, click_context.obj)
52+
is_mixed = not local and not remote
53+
ctx.set_config("is_local", local and not remote)
54+
ctx.set_config("is_mixed", is_mixed)
5255
if remote:
5356
fetch_agent(ctx, public_id, alias)
57+
elif local:
58+
fetch_agent_locally(ctx, public_id, alias)
5459
else:
55-
fetch_agent_locally(ctx, public_id, alias, is_mixed=not local)
60+
fetch_mixed(ctx, public_id, alias)
5661

5762

5863
def _is_version_correct(ctx: Context, agent_public_id: PublicId) -> bool:
@@ -76,7 +81,6 @@ def fetch_agent_locally(
7681
public_id: PublicId,
7782
alias: Optional[str] = None,
7883
target_dir: Optional[str] = None,
79-
is_mixed: bool = True,
8084
) -> None:
8185
"""
8286
Fetch Agent from local packages.
@@ -85,7 +89,6 @@ def fetch_agent_locally(
8589
:param public_id: public ID of agent to be fetched.
8690
:param alias: an optional alias.
8791
:param target_dir: the target directory to which the agent is fetched.
88-
:param is_mixed: flag to enable mixed mode (try first local, then remote).
8992
:return: None
9093
"""
9194
packages_path = (
@@ -125,58 +128,43 @@ def fetch_agent_locally(
125128
)
126129

127130
# add dependencies
128-
_fetch_agent_deps(ctx, is_mixed)
131+
_fetch_agent_deps(ctx)
129132
click.echo("Agent {} successfully fetched.".format(public_id.name))
130133

131134

132-
def _fetch_agent_deps(ctx: Context, is_mixed: bool = True) -> None:
135+
def _fetch_agent_deps(ctx: Context) -> None:
133136
"""
134137
Fetch agent dependencies.
135138
136139
:param ctx: context object.
137-
:param is_mixed: flag to enable mixed mode (try first local, then remote).
138140
139141
:return: None
140142
:raises: ClickException re-raises if occurs in add_item call.
141143
"""
142-
ctx.set_config("is_local", True)
143-
ctx.set_config("is_mixed", is_mixed)
144144
for item_type in ("protocol", "contract", "connection", "skill"):
145145
item_type_plural = "{}s".format(item_type)
146146
required_items = getattr(ctx.agent_config, item_type_plural)
147147
for item_id in required_items:
148-
fetch_local_or_mixed(ctx, item_type, item_id)
148+
add_item(ctx, item_type, item_id)
149149

150150

151-
def fetch_local_or_mixed(ctx: Context, item_type: str, item_id: PublicId) -> None:
151+
def fetch_mixed(
152+
ctx: Context,
153+
public_id: PublicId,
154+
alias: Optional[str] = None,
155+
target_dir: Optional[str] = None,
156+
) -> None:
152157
"""
153-
Fetch item, either local or mixed, depending on the parameters/context configuration.
158+
Fetch an agent in mixed mode.
154159
155-
It will first try to fetch from local registry; in case of failure,
156-
if the 'is_mixed' flag is set, it will try to fetch from remote registry.
157-
158-
Context expects 'is_local' and 'is_mixed' to be set.
159-
160-
:param ctx: the CLI context.
161-
:param item_type: the type of the package.
162-
:param item_id: the public id of the item.
160+
:param ctx: the Context.
161+
:param public_id: the public id.
162+
:param alias: the alias to the agent.
163+
:param target_dir: the target directory.
163164
:return: None
164165
"""
165-
166-
def _raise(item_type_: str, item_id_: PublicId, exception):
167-
"""Temporary function to raise exception (used below twice)."""
168-
raise click.ClickException(
169-
f"Failed to add {item_type_} dependency {item_id_}: {str(exception)}"
170-
)
171-
172166
try:
173-
add_item(ctx, item_type, item_id)
174-
except click.ClickException as e:
175-
if not ctx.config.get("is_mixed", False):
176-
_raise(item_type, item_id, e)
177-
ctx.set_config("is_local", False)
178-
try:
179-
add_item(ctx, item_type, item_id)
180-
except click.ClickException as e:
181-
_raise(item_type, item_id, e)
182-
ctx.set_config("is_local", True)
167+
fetch_agent_locally(ctx, public_id, alias=alias, target_dir=target_dir)
168+
except click.ClickException:
169+
click.echo("Fetch from local registry failed, trying on remote registry...")
170+
fetch_agent(ctx, public_id, alias=alias, target_dir=target_dir)

aea/cli/publish.py

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -55,7 +55,7 @@ def publish(click_context, local, remote): # pylint: disable=unused-argument
5555
if remote:
5656
publish_agent(ctx)
5757
else:
58-
_save_agent_locally(ctx, is_mixed=not local)
58+
_save_agent_locally(ctx, is_mixed=not local and not remote)
5959

6060

6161
def _validate_config(ctx: Context) -> None:

aea/cli/registry/fetch.py

Lines changed: 3 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -48,7 +48,7 @@ def fetch_agent(
4848
:return: None
4949
"""
5050
author, name, version = public_id.author, public_id.name, public_id.version
51-
api_path = "/agents/{}/{}/{}".format(author, name, version)
51+
api_path = f"/agents/{author}/{name}/{version}"
5252
resp = request_api("GET", api_path)
5353
file_url = resp["file"]
5454

@@ -88,9 +88,7 @@ def fetch_agent(
8888
add_item(ctx, item_type, item_public_id)
8989
except Exception as e:
9090
raise click.ClickException(
91-
'Unable to fetch dependency for agent "{}", aborting. {}'.format(
92-
name, e
93-
)
91+
f'Unable to fetch dependency for agent "{name}", aborting. {e}'
9492
)
9593
click.echo("Dependencies successfully fetched.")
96-
click.echo("Agent {} successfully fetched to {}.".format(name, aea_folder))
94+
click.echo(f"Agent {name} successfully fetched to {aea_folder}.")

0 commit comments

Comments
 (0)