Skip to content

Commit

Permalink
feat: support custom components in publish and eject commands
Browse files Browse the repository at this point in the history
Signed-off-by: OjusWiZard <ojuswimail@gmail.com>
  • Loading branch information
OjusWiZard committed Sep 18, 2024
1 parent f1e2e19 commit 01c0cff
Show file tree
Hide file tree
Showing 6 changed files with 36 additions and 3 deletions.
11 changes: 11 additions & 0 deletions aea/cli/eject.py
Original file line number Diff line number Diff line change
Expand Up @@ -59,6 +59,7 @@
from aea.configurations.constants import (
CONNECTION,
CONTRACT,
CUSTOM,
DEFAULT_VERSION,
PROTOCOL,
SKILL,
Expand Down Expand Up @@ -136,6 +137,16 @@ def skill(ctx: Context, public_id: PublicId) -> None:
_eject_item(ctx, SKILL, public_id, quiet=quiet, with_symlinks=with_symlinks)


@eject.command()
@click.argument("public_id", type=PublicIdParameter(), required=True)
@pass_ctx
def custom(ctx: Context, public_id: PublicId) -> None:
"""Eject a vendor custom component."""
quiet = ctx.config.get("quiet")
with_symlinks = ctx.config.get("with_symlinks")
_eject_item(ctx, CUSTOM, public_id, quiet=quiet, with_symlinks=with_symlinks)


@clean_after
def _eject_item(
ctx: Context,
Expand Down
3 changes: 2 additions & 1 deletion aea/cli/publish.py
Original file line number Diff line number Diff line change
Expand Up @@ -54,6 +54,7 @@
AGENTS,
CONNECTIONS,
CONTRACTS,
CUSTOMS,
DEFAULT_AEA_CONFIG_FILE,
DEFAULT_README_FILE,
ITEM_TYPE_PLURAL_TO_TYPE,
Expand Down Expand Up @@ -330,7 +331,7 @@ def _check_dependencies_in_registry(
registry: BaseRegistry, agent_config: AgentConfig, push_missing: bool
) -> None:
"""Check all agent dependencies present in registry."""
for item_type_plural in (PROTOCOLS, CONTRACTS, CONNECTIONS, SKILLS):
for item_type_plural in (PROTOCOLS, CONTRACTS, CONNECTIONS, SKILLS, CUSTOMS):
dependencies = getattr(agent_config, item_type_plural)
for public_id in dependencies:
if push_missing:
Expand Down
4 changes: 3 additions & 1 deletion aea/cli/registry/push.py
Original file line number Diff line number Diff line change
Expand Up @@ -40,6 +40,7 @@
from aea.configurations.constants import (
CONNECTIONS,
CONTRACTS,
CUSTOM,
DEFAULT_README_FILE,
ITEM_TYPE_PLURAL_TO_TYPE,
PROTOCOLS,
Expand All @@ -61,7 +62,8 @@ def _compress_dir(output_filename: str, source_dir: str) -> None:

def load_component_public_id(source_path: str, item_type: str) -> PublicId:
"""Get component version from source path."""
config = load_yaml(os.path.join(source_path, item_type + ".yaml"))
config_file = "component" if item_type == CUSTOM else item_type
config = load_yaml(os.path.join(source_path, config_file + ".yaml"))
item_author = config.get("author", "")
item_name = config.get("name", "")
item_version = config.get("version", "")
Expand Down
1 change: 1 addition & 0 deletions aea/configurations/constants.py
Original file line number Diff line number Diff line change
Expand Up @@ -157,6 +157,7 @@
CONTRACT: CONTRACTS,
CONNECTION: CONNECTIONS,
SKILL: SKILLS,
CUSTOM: CUSTOMS,
}

ITEM_TYPE_PLURAL_TO_TYPE = {v: k for k, v in ITEM_TYPE_TO_PLURAL.items()}
Expand Down
12 changes: 12 additions & 0 deletions tests/test_cli/test_eject.py
Original file line number Diff line number Diff line change
Expand Up @@ -20,6 +20,7 @@
"""This test module contains the tests for commands in aea.cli.eject module."""

import os
import shutil
from pathlib import Path
from unittest import mock

Expand Down Expand Up @@ -54,6 +55,11 @@ def test_eject_commands_positive(self):
self.add_item("connection", str(GYM_CONNECTION_PUBLIC_ID))
self.add_item("skill", str(GYM_SKILL_PUBLIC_ID))
self.add_item("contract", str(ERC1155_PUBLIC_ID))
self.scaffold_item("custom", "test")
shutil.move(
os.path.join(cwd, "customs"),
os.path.join(cwd, "vendor", self.author, "customs"),
)

# the order must be kept as is, because of recursive ejects
self.eject_item("skill", str(GYM_SKILL_PUBLIC_ID))
Expand All @@ -79,6 +85,12 @@ def test_eject_commands_positive(self):
)
assert "erc1155" in os.listdir((os.path.join(cwd, "contracts")))

self.eject_item("custom", f"{self.author}/test:0.1.0")
assert f"{self.author}/test:0.1.0" not in os.listdir(
(os.path.join(cwd, "vendor", self.author, "customs"))
)
assert "test" in os.listdir((os.path.join(cwd, "customs")))


class TestRecursiveEject(AEATestCaseEmpty):
"""Test that eject is recursive."""
Expand Down
8 changes: 7 additions & 1 deletion tests/test_cli/test_publish.py
Original file line number Diff line number Diff line change
Expand Up @@ -37,6 +37,7 @@
)
from aea.cli.registry.settings import REMOTE_HTTP, REMOTE_IPFS
from aea.configurations.base import PublicId
from aea.configurations.constants import CUSTOMS, SKILLS
from aea.helpers.base import cd
from aea.test_tools.test_cases import AEATestCaseEmpty, BaseAEATestCase

Expand Down Expand Up @@ -251,13 +252,16 @@ class TestPublishLocallyWithDeps(AEATestCaseEmpty):

NEW_ITEM_TYPE = "skill"
NEW_ITEM_NAME = "my_test_skill"
CUSTOM_ITEM_TYPE = "custom"
CUSTOM_ITEM_NAME = "test"

@classmethod
def setup_class(cls):
"""Set up test case."""
super(TestPublishLocallyWithDeps, cls).setup_class()
cls.add_item(cls.ITEM_TYPE, str(cls.ITEM_PUBLIC_ID), local=True)
cls.scaffold_item(cls.NEW_ITEM_TYPE, cls.NEW_ITEM_NAME)
cls.scaffold_item(cls.CUSTOM_ITEM_TYPE, cls.CUSTOM_ITEM_NAME)

def test_publish_ok_with_missing_push(
self,
Expand All @@ -268,9 +272,11 @@ def test_publish_ok_with_missing_push(
assert "use --push-missing" in str(e)

self.invoke("publish", "--local", "--push-missing")
packages_dir = self.t / self.packages_dir_path # type: ignore
assert (packages_dir / self.author / SKILLS / self.NEW_ITEM_NAME).exists()
assert (packages_dir / self.author / CUSTOMS / self.CUSTOM_ITEM_NAME).exists()

# remove agents published and publish again
packages_dir = self.t / self.packages_dir_path # type: ignore
rmtree(Path(packages_dir) / self.author / "agents")
self.invoke("publish", "--local")

Expand Down

0 comments on commit 01c0cff

Please sign in to comment.