コード例 #1
0
def _check_is_item_in_local_registry(public_id, item_type_plural,
                                     registry_path):
    try:
        _try_get_item_source_path(registry_path, public_id.author,
                                  item_type_plural, public_id.name)
    except click.ClickException as e:
        raise click.ClickException(
            "Dependency is missing. {} "
            "Please push it first and then retry.".format(e))
コード例 #2
0
def _fetch_agent_locally(ctx: Context, public_id: PublicId,
                         click_context) -> None:
    """
    Fetch Agent from local packages.

    :param ctx: Context
    :param public_id: public ID of agent to be fetched.

    :return: None
    """
    packages_path = os.path.basename(DEFAULT_REGISTRY_PATH)
    source_path = _try_get_item_source_path(packages_path, public_id.author,
                                            "agents", public_id.name)
    target_path = os.path.join(ctx.cwd, public_id.name)
    if os.path.exists(target_path):
        raise click.ClickException(
            'Item "{}" already exists in target folder.'.format(
                public_id.name))
    copy_tree(source_path, target_path)

    # add dependencies
    ctx.cwd = target_path
    try_to_load_agent_config(ctx)

    for item_type in ("skill", "connection", "contract", "protocol"):
        item_type_plural = "{}s".format(item_type)
        required_items = getattr(ctx.agent_config, item_type_plural)
        for item_id in required_items:
            try:
                _add_item(click_context, item_type, item_id)
            except SystemExit:
                continue
    click.echo("Agent {} successfully fetched.".format(public_id.name))
コード例 #3
0
 def test_get_item_source_path_positive(self, exists_mock, join_mock):
     """Test for get_item_source_path positive result."""
     result = _try_get_item_source_path("cwd", AUTHOR, "skills",
                                        "skill-name")
     expected_result = "some-path"
     self.assertEqual(result, expected_result)
     join_mock.assert_called_once_with("cwd", AUTHOR, "skills",
                                       "skill-name")
     exists_mock.assert_called_once_with("some-path")
コード例 #4
0
ファイル: push.py プロジェクト: pbukva/agents-aea
def _save_item_locally(ctx: Context, item_type: str,
                       item_id: PublicId) -> None:
    """
    Save item to local packages.

    :param item_type: str type of item (connection/protocol/skill).
    :param item_id: the public id of the item.
    :return: None
    """
    item_type_plural = item_type + "s"

    source_path = _try_get_item_source_path(ctx.cwd, None, item_type_plural,
                                            item_id.name)
    target_path = _try_get_item_target_path(
        ctx.agent_config.registry_path,
        ctx.agent_config.author,
        item_type_plural,
        item_id.name,
    )
    _check_package_public_id(source_path, item_type, item_id)
    copytree(source_path, target_path)
    click.echo('{} "{}" successfully saved in packages folder.'.format(
        item_type.title(), item_id))
コード例 #5
0
 def test_get_item_source_path_not_exists(self, exists_mock, join_mock):
     """Test for get_item_source_path item already exists."""
     with self.assertRaises(ClickException):
         _try_get_item_source_path("cwd", AUTHOR, "skills", "skill-name")