コード例 #1
0
def test_yaml_dump_all_load_all():
    """Test yaml_dump_all and yaml_load_all."""
    f = io.StringIO()
    data = [{"a": "12"}, {"b": "13"}]
    yaml_dump_all(data, f)

    f.seek(0)
    assert yaml_load_all(f) == data
コード例 #2
0
ファイル: loader.py プロジェクト: presidento23/agents-aea
 def _dump_agent_config(self, configuration: AgentConfig,
                        file_pointer: TextIO) -> None:
     """Dump agent configuration."""
     agent_config_part = configuration.ordered_json
     self.validate(agent_config_part)
     agent_config_part.pop("component_configurations")
     result = [agent_config_part
               ] + configuration.component_configurations_json()
     yaml_dump_all(result, file_pointer)
コード例 #3
0
def sort_configuration_file(config: PackageConfiguration):
    """Sort the order of the fields in the configuration files."""
    # load config file to get ignore patterns, dump again immediately to impose ordering
    assert config.directory is not None
    configuration_filepath = config.directory / config.default_configuration_filename
    if config.package_type == PackageType.AGENT:
        json_data = config.ordered_json
        component_configurations = json_data.pop("component_configurations")
        yaml_dump_all([json_data] + component_configurations,
                      configuration_filepath.open("w"))
    else:
        yaml_dump(config.ordered_json, configuration_filepath.open("w"))
コード例 #4
0
def update_ah_config_with_new_config(
        addresses, file_path: str = "./autonomous_hegician/aea-config.yaml"):
    """Get the AH config and update it with contract addresses."""
    with open(file_path, "r") as fp:
        full_config: List[Dict[str, Any]] = yaml_load_all(fp)
    assert len(full_config) >= 2, "Expecting at least one override defined!"
    skill_config = full_config[1]
    assert skill_config["public_id"] == "eightballer/option_management:0.1.0"
    skill_config["models"]["strategy"]["args"] = OrderedDict(addresses)
    full_config_updated = [full_config[0], skill_config] + full_config[2:]
    with open(file_path, "w") as fp:
        print(full_config_updated)
        yaml_dump_all(full_config_updated, fp)
def update_ah_config_with_new_config(
    ledger_string,
    file_paths: Tuple[str, ...] = (
        "./autonomous_hegician/aea-config.yaml",
        "./hegic_deployer/aea-config.yaml",
    ),
):
    """Get the AH config and update it with ledger string."""
    for file_path in file_paths:
        with open(file_path, "r") as fp:
            full_config: List[Dict[str, Any]] = yaml_load_all(fp)
        assert len(full_config) >= 3, "Expecting at least two overrides defined!"
        connection_config = full_config[2]
        assert connection_config["public_id"] == "fetchai/ledger:0.9.0"
        connection_config["config"]["ledger_apis"]["ethereum"][
            "address"
        ] = ledger_string

        full_config_updated = full_config[:2] + [connection_config] + full_config[3:]
        with open(file_path, "w") as fp:
            yaml_dump_all(full_config_updated, fp)
コード例 #6
0
ファイル: generic.py プロジェクト: hame58gp/agents-aea
def nested_set_config(
    dotted_path: str, value: Any, author: str = DEFAULT_AUTHOR
) -> None:
    """
    Set an AEA config with nested values.

    Run from agent's directory.

    Allowed dotted_path:
        'agent.an_attribute_name'
        'protocols.my_protocol.an_attribute_name'
        'connections.my_connection.an_attribute_name'
        'contracts.my_contract.an_attribute_name'
        'skills.my_skill.an_attribute_name'
        'vendor.author.[protocols|connections|skills].package_name.attribute_name

    :param dotted_path: dotted path to a setting.
    :param value: a value to assign. Must be of yaml serializable type.
    :param author: the author name, used to parse the dotted path.

    :return: None.
    """
    settings_keys, config_file_path, config_loader, _ = handle_dotted_path(
        dotted_path, author
    )

    with config_file_path.open() as fp:
        config = config_loader.load(fp)

    _nested_set(config, settings_keys, value)

    if config.package_type == PackageType.AGENT:
        json_data = config.ordered_json
        component_configurations = json_data.pop("component_configurations")
        yaml_dump_all(
            [json_data] + component_configurations, config_file_path.open("w")
        )
    else:
        yaml_dump(config.ordered_json, config_file_path.open("w"))