def setup_class(cls): """Set up the test.""" cls.expected_custom_component_configuration = dict(foo="bar") cls.agent_config = AgentConfig( agent_name="agent_name", author="author", version="0.1.0", default_routing={ str(cls.old_protocol_id): str(cls.old_connection_id) }, default_connection=str(cls.old_connection_id), ) cls.agent_config.protocols = {cls.old_protocol_id} cls.agent_config.contracts = {cls.old_contract_id} cls.agent_config.connections = {cls.old_connection_id} cls.agent_config.skills = {cls.old_skill_id} cls.agent_config.component_configurations[ComponentId( ComponentType.PROTOCOL, cls.old_protocol_id)] = cls.expected_custom_component_configuration cls.agent_config.component_configurations[ComponentId( ComponentType.CONTRACT, cls.old_contract_id)] = cls.expected_custom_component_configuration cls.agent_config.component_configurations[ComponentId( ComponentType.CONNECTION, cls.old_connection_id )] = cls.expected_custom_component_configuration cls.agent_config.component_configurations[ComponentId( ComponentType.SKILL, cls.old_skill_id)] = cls.expected_custom_component_configuration replace_component_ids(cls.agent_config, cls.replacements)
def _create_agent_config(ctx: Context, agent_name: str, set_author: str) -> AgentConfig: """ Create agent config. :param ctx: context object. :param agent_name: agent name. :param set_author: author name to set. :return: AgentConfig object. """ agent_config = AgentConfig( agent_name=agent_name, aea_version=compute_specifier_from_version(get_current_aea_version()), author=set_author, version=DEFAULT_VERSION, license_=DEFAULT_LICENSE, registry_path=os.path.join("..", DEFAULT_REGISTRY_PATH), description="", default_ledger=DEFAULT_LEDGER, default_connection=None, ) with open_file(os.path.join(agent_name, DEFAULT_AEA_CONFIG_FILE), "w") as config_file: ctx.agent_loader.dump(agent_config, config_file) return agent_config
def _crete_agent_config(ctx: Context, agent_name: str, set_author: str) -> AgentConfig: """ Create agent config. :param ctx: context object. :param agent_name: agent name. :param set_author: author name to set. :return: AgentConfig object. """ agent_config = AgentConfig( agent_name=agent_name, aea_version=aea.__version__, author=set_author, version=DEFAULT_VERSION, license_=DEFAULT_LICENSE, registry_path=os.path.join("..", DEFAULT_REGISTRY_PATH), description="", ) agent_config.default_connection = str(DEFAULT_CONNECTION) agent_config.default_ledger = DEFAULT_LEDGER with open(os.path.join(agent_name, DEFAULT_AEA_CONFIG_FILE), "w") as config_file: ctx.agent_loader.dump(agent_config, config_file) return agent_config
def _create_aea(click_context, agent_name: str, set_author: str, local: bool) -> None: ctx = cast(Context, click_context.obj) path = Path(agent_name) ctx.clean_paths.append(str(path)) # we have already checked that the directory does not exist. path.mkdir(exist_ok=False) try: # set up packages directories. _setup_package_folder(Path(agent_name, "protocols")) _setup_package_folder(Path(agent_name, "contracts")) _setup_package_folder(Path(agent_name, "connections")) _setup_package_folder(Path(agent_name, "skills")) # set up a vendor directory Path(agent_name, "vendor").mkdir(exist_ok=False) Path(agent_name, "vendor", "__init__.py").touch(exist_ok=False) # create a config file inside it click.echo("Creating config file {}".format(DEFAULT_AEA_CONFIG_FILE)) config_file = open(os.path.join(agent_name, DEFAULT_AEA_CONFIG_FILE), "w") agent_config = AgentConfig( agent_name=agent_name, aea_version=aea.__version__, author=set_author, version=DEFAULT_VERSION, license=DEFAULT_LICENSE, registry_path=os.path.join("..", DEFAULT_REGISTRY_PATH), description="", ) agent_config.default_connection = DEFAULT_CONNECTION # type: ignore agent_config.default_ledger = DEFAULT_LEDGER ctx.agent_loader.dump(agent_config, config_file) # next commands must be done from the agent's directory -> overwrite ctx.cwd ctx.agent_config = agent_config ctx.cwd = agent_config.agent_name click.echo("Adding default packages ...") if local: ctx.set_config("is_local", True) _add_item(click_context, "connection", DEFAULT_CONNECTION) _add_item(click_context, "skill", DEFAULT_SKILL) except Exception as e: raise click.ClickException(str(e))
def create(click_context, agent_name): """Create an agent.""" ctx = cast(Context, click_context.obj) path = Path(agent_name) logger.info("Initializing AEA project '{}'".format(agent_name)) logger.info("Creating project directory '/{}'".format(agent_name)) # create the agent's directory try: path.mkdir(exist_ok=False) # create a config file inside it logger.info("Creating config file {}".format(DEFAULT_AEA_CONFIG_FILE)) config_file = open(os.path.join(agent_name, DEFAULT_AEA_CONFIG_FILE), "w") agent_config = AgentConfig(agent_name=agent_name, aea_version=aea.__version__, authors="", version="v1", license="", url="", registry_path=DEFAULT_REGISTRY_PATH, description="") agent_config.default_connection = DEFAULT_CONNECTION ctx.agent_loader.dump(agent_config, config_file) # next commands must be done from the agent's directory -> overwrite ctx.cwd ctx.agent_config = agent_config ctx.cwd = agent_config.agent_name logger.info("Default connections:") click_context.invoke(connection, connection_name=DEFAULT_CONNECTION) logger.info("Default skills:") click_context.invoke(skill, skill_name=DEFAULT_SKILL) except OSError: logger.error("Directory already exist. Aborting...") sys.exit(1) except ValidationError as e: logger.error(str(e)) shutil.rmtree(agent_name, ignore_errors=True) sys.exit(1) except Exception as e: logger.exception(e) shutil.rmtree(agent_name, ignore_errors=True) sys.exit(1)
def test_agent_config_to_json_with_optional_configurations(): """Test agent config to json with optional configurations.""" agent_config = AgentConfig( "name", "author", timeout=0.1, execution_timeout=1.0, max_reactions=100, decision_maker_handler=dict(dotted_path="", file_path=""), skill_exception_policy="propagate", default_routing={"author/name:0.1.0": "author/name:0.1.0"}, loop_mode="sync", runtime_mode="async", ) agent_config.default_connection = "author/name:0.1.0" agent_config.default_ledger = DEFAULT_LEDGER agent_config.json
def test_agent_config_package_dependencies(): """Test agent config package dependencies.""" agent_config = AgentConfig("name", "author") assert agent_config.package_dependencies == set() pid = PublicId("author", "name", "0.1.0") agent_config.protocols.add(pid) agent_config.connections.add(pid) agent_config.contracts.add(pid) agent_config.skills.add(pid) assert agent_config.package_dependencies == { PackageId(PackageType.PROTOCOL, pid), PackageId(PackageType.CONNECTION, pid), PackageId(PackageType.CONTRACT, pid), PackageId(PackageType.SKILL, pid), }
def create(click_context, agent_name): """Create an agent.""" ctx = cast(Context, click_context.obj) path = Path(agent_name) logger.info("Creating agent's directory in '{}'".format(path)) # create the agent's directory try: path.mkdir(exist_ok=False) # create a config file inside it config_file = open(os.path.join(agent_name, DEFAULT_AEA_CONFIG_FILE), "w") agent_config = AgentConfig(agent_name=agent_name, aea_version=aea.__version__, authors="", version="v1", license="", url="", registry_path="../packages", private_key_pem_path="") agent_config.default_connection = DEFAULT_CONNECTION ctx.agent_loader.dump(agent_config, config_file) logger.info("Created config file {}".format(DEFAULT_AEA_CONFIG_FILE)) # next commands must be done from the agent's directory -> overwrite ctx.cwd ctx.agent_config = agent_config ctx.cwd = agent_config.agent_name logger.info("Adding default connection '{}' to the agent...".format(DEFAULT_CONNECTION)) click_context.invoke(connection, connection_name=DEFAULT_CONNECTION) logger.info("Adding default skill '{}' to the agent...".format(DEFAULT_SKILL)) click_context.invoke(skill, skill_name=DEFAULT_SKILL) except OSError: logger.error("Directory already exist. Aborting...") exit(-1) except ValidationError as e: logger.error(str(e)) shutil.rmtree(agent_name, ignore_errors=True) exit(-1) except Exception as e: logger.exception(e) shutil.rmtree(agent_name, ignore_errors=True) exit(-1)
def test_agent_config_to_json_with_optional_configurations(): """Test agent config to json with optional configurations.""" agent_config = AgentConfig( "name", "author", period=0.1, execution_timeout=1.0, max_reactions=100, decision_maker_handler=dict(dotted_path="", file_path=""), error_handler=dict(dotted_path="", file_path=""), skill_exception_policy="propagate", connection_exception_policy="propagate", default_routing={"author/name:0.1.0": "author/name:0.1.0"}, currency_denominations={"fetchai": "fet"}, loop_mode="sync", runtime_mode="async", storage_uri="some_uri_to_storage", ) agent_config.default_connection = "author/name:0.1.0" agent_config.default_ledger = DEFAULT_LEDGER agent_config.json assert agent_config.package_id == PackageId.from_uri_path( "agent/author/name/0.1.0")
def test_default_connection(self): """Test case for default_connection setter positive result.""" agent_config = AgentConfig(agent_name="my_agent", author="fetchai") agent_config.default_connection = None agent_config.default_connection = 1 agent_config.public_id
def test_init_logging_config_positive(self): """Test case for from_json method positive result.""" AgentConfig(agent_name="my_agent", author="fetchai", logging_config={})
def create(click_context, agent_name, author, local): """Create an agent.""" try: _check_is_parent_folders_are_aea_projects_recursively() except Exception: logger.error( "The current folder is already an AEA project. Please move to the parent folder." ) sys.exit(1) if author is not None: if local: do_init(author, False, False) else: raise click.ClickException( "Author is not set up. Please use 'aea init' to initialize.") config = _get_or_create_cli_config() set_author = config.get(AUTHOR, None) if set_author is None: click.echo( "The AEA configurations are not initialized. Uses `aea init` before continuing or provide optional argument `--author`." ) sys.exit(1) ctx = cast(Context, click_context.obj) path = Path(agent_name) click.echo("Initializing AEA project '{}'".format(agent_name)) click.echo("Creating project directory './{}'".format(agent_name)) # create the agent's directory try: path.mkdir(exist_ok=False) # set up packages directories. _setup_package_folder(Path(agent_name, "protocols")) _setup_package_folder(Path(agent_name, "contracts")) _setup_package_folder(Path(agent_name, "connections")) _setup_package_folder(Path(agent_name, "skills")) # set up a vendor directory Path(agent_name, "vendor").mkdir(exist_ok=False) Path(agent_name, "vendor", "__init__.py").touch(exist_ok=False) # create a config file inside it click.echo("Creating config file {}".format(DEFAULT_AEA_CONFIG_FILE)) config_file = open(os.path.join(agent_name, DEFAULT_AEA_CONFIG_FILE), "w") agent_config = AgentConfig( agent_name=agent_name, aea_version=aea.__version__, author=set_author, version=DEFAULT_VERSION, license=DEFAULT_LICENSE, registry_path=os.path.join("..", DEFAULT_REGISTRY_PATH), description="", ) agent_config.default_connection = DEFAULT_CONNECTION agent_config.default_ledger = DEFAULT_LEDGER ctx.agent_loader.dump(agent_config, config_file) # next commands must be done from the agent's directory -> overwrite ctx.cwd ctx.agent_config = agent_config ctx.cwd = agent_config.agent_name click.echo("Adding default packages ...") if local: ctx.set_config("is_local", True) _add_item(click_context, "connection", DEFAULT_CONNECTION) _add_item(click_context, "skill", DEFAULT_SKILL) except OSError: logger.error("Directory already exist. Aborting...") sys.exit(1) except ValidationError as e: logger.error(str(e)) shutil.rmtree(agent_name, ignore_errors=True) sys.exit(1) except Exception as e: logger.exception(e) shutil.rmtree(agent_name, ignore_errors=True) sys.exit(1)
def test_name_and_author(self): """Test case for default_connection setter positive result.""" agent_config = AgentConfig(agent_name="my_agent", author="fetchai") agent_config.name = "new_name" agent_config.author = "new_author"
def test_default_connection(self): """Test case for default_connection setter positive result.""" agent_config = AgentConfig() agent_config.default_connection = None agent_config.default_connection = 1 agent_config.public_id
def test_init_logging_config_positive(self): """Test case for from_json method positive result.""" AgentConfig(logging_config={})