From 725ad614968ce601e58f592584b9d08bf30476c7 Mon Sep 17 00:00:00 2001 From: Viraj Patel Date: Tue, 30 Aug 2022 10:24:45 +0000 Subject: [PATCH 1/6] feat: add nested params variable --- aea/configurations/base.py | 5 +++++ 1 file changed, 5 insertions(+) diff --git a/aea/configurations/base.py b/aea/configurations/base.py index 080ba7bcbc..78ac6a1893 100644 --- a/aea/configurations/base.py +++ b/aea/configurations/base.py @@ -225,7 +225,11 @@ class PackageConfiguration(Configuration, ABC): default_configuration_filename: str package_type: PackageType + FIELDS_ALLOWED_TO_UPDATE: FrozenSet[str] = frozenset(["build_directory"]) + FIELDS_WITH_NESTED_FIELDS: FrozenSet[str] = frozenset() + NESTED_FIELDS_ALLOWED_TO_UPDATE: FrozenSet[str] = frozenset() + schema: str CHECK_EXCLUDES: List[Tuple[str]] = [] @@ -572,6 +576,7 @@ class ConnectionConfig(ComponentConfiguration): FIELDS_ALLOWED_TO_UPDATE: FrozenSet[str] = frozenset( ["config", "cert_requests", "is_abstract", "build_directory"] ) + FIELDS_WITH_NESTED_FIELDS: FrozenSet[str] = frozenset(["config"]) __slots__ = ( "class_name", From 0b9cec249f5adc85e829c174e45a53b75ddd71c8 Mon Sep 17 00:00:00 2001 From: Viraj Patel Date: Fri, 2 Sep 2022 06:23:16 +0000 Subject: [PATCH 2/6] feat: remove support for `NESTED_FIELDS_ALLOWED_TO_UPDATE` --- aea/configurations/base.py | 11 +---------- aea/test_tools/generic.py | 2 +- 2 files changed, 2 insertions(+), 11 deletions(-) diff --git a/aea/configurations/base.py b/aea/configurations/base.py index 6710e1480c..0cc5354787 100644 --- a/aea/configurations/base.py +++ b/aea/configurations/base.py @@ -229,7 +229,6 @@ class PackageConfiguration(Configuration, ABC): FIELDS_ALLOWED_TO_UPDATE: FrozenSet[str] = frozenset(["build_directory"]) FIELDS_WITH_NESTED_FIELDS: FrozenSet[str] = frozenset() - NESTED_FIELDS_ALLOWED_TO_UPDATE: FrozenSet[str] = frozenset() schema: str CHECK_EXCLUDES: List[Tuple[str]] = [] @@ -962,7 +961,6 @@ class SkillConfig(ComponentConfiguration): FIELDS_WITH_NESTED_FIELDS: FrozenSet[str] = frozenset( ["behaviours", "handlers", "models"] ) - NESTED_FIELDS_ALLOWED_TO_UPDATE: FrozenSet[str] = frozenset(["args"]) __slots__ = ( "connections", @@ -1147,17 +1145,10 @@ def get_overridable(self) -> dict: result[self.abstract_field_name] = current_config_data[ self.abstract_field_name ] - for field in self.FIELDS_WITH_NESTED_FIELDS: if not current_config_data.get(field, {}): continue - result[field] = {} - for name in current_config_data[field].keys(): - result[field][name] = {} - for nested_field in self.NESTED_FIELDS_ALLOWED_TO_UPDATE: - result[field][name][nested_field] = current_config_data[field][ - name - ][nested_field] + result[field] = current_config_data[field] return result diff --git a/aea/test_tools/generic.py b/aea/test_tools/generic.py index d55ad6bc31..292db1724c 100644 --- a/aea/test_tools/generic.py +++ b/aea/test_tools/generic.py @@ -123,7 +123,7 @@ def get_nested_ordered_dict_from_keys_and_value( ): root_attr = getattr(configuration_obj, root_key) length = len(keys) - if length < 3 or keys[2] not in SkillConfig.NESTED_FIELDS_ALLOWED_TO_UPDATE: + if length < 3: raise ValueError(f"Invalid keys={keys}.") # pragma: nocover skill_component_id = keys[1] skill_component_config = root_attr.read(skill_component_id) From 9dd1f77a25088daf1f0bf1c85a889ea68436f5b0 Mon Sep 17 00:00:00 2001 From: Viraj Patel Date: Fri, 2 Sep 2022 06:33:29 +0000 Subject: [PATCH 3/6] feat: remove support for `FIELDS_WITH_NESTED_FIELDS` from component config --- aea/configurations/base.py | 19 ------------------- aea/test_tools/generic.py | 5 +---- 2 files changed, 1 insertion(+), 23 deletions(-) diff --git a/aea/configurations/base.py b/aea/configurations/base.py index 0cc5354787..28ee524ce7 100644 --- a/aea/configurations/base.py +++ b/aea/configurations/base.py @@ -228,7 +228,6 @@ class PackageConfiguration(Configuration, ABC): package_type: PackageType FIELDS_ALLOWED_TO_UPDATE: FrozenSet[str] = frozenset(["build_directory"]) - FIELDS_WITH_NESTED_FIELDS: FrozenSet[str] = frozenset() schema: str CHECK_EXCLUDES: List[Tuple[str]] = [] @@ -576,7 +575,6 @@ class ConnectionConfig(ComponentConfiguration): FIELDS_ALLOWED_TO_UPDATE: FrozenSet[str] = frozenset( ["config", "cert_requests", "is_abstract", "build_directory"] ) - FIELDS_WITH_NESTED_FIELDS: FrozenSet[str] = frozenset(["config"]) __slots__ = ( "class_name", @@ -958,9 +956,6 @@ class SkillConfig(ComponentConfiguration): FIELDS_ALLOWED_TO_UPDATE: FrozenSet[str] = frozenset( ["behaviours", "handlers", "models", "is_abstract", "build_directory"] ) - FIELDS_WITH_NESTED_FIELDS: FrozenSet[str] = frozenset( - ["behaviours", "handlers", "models"] - ) __slots__ = ( "connections", @@ -1137,20 +1132,6 @@ def _create_or_update_from_json( return instance - def get_overridable(self) -> dict: - """Get overridable configuration data.""" - result = {} - current_config_data = self.json - if self.abstract_field_name in current_config_data: - result[self.abstract_field_name] = current_config_data[ - self.abstract_field_name - ] - for field in self.FIELDS_WITH_NESTED_FIELDS: - if not current_config_data.get(field, {}): - continue - result[field] = current_config_data[field] - return result - class AgentConfig(PackageConfiguration): """Class to represent the agent configuration file.""" diff --git a/aea/test_tools/generic.py b/aea/test_tools/generic.py index 292db1724c..b9adc8267a 100644 --- a/aea/test_tools/generic.py +++ b/aea/test_tools/generic.py @@ -117,10 +117,7 @@ def get_nested_ordered_dict_from_keys_and_value( return _dic root_key = keys[0] - if ( - isinstance(configuration_obj, SkillConfig) - and root_key in SkillConfig.FIELDS_WITH_NESTED_FIELDS - ): + if isinstance(configuration_obj, SkillConfig): root_attr = getattr(configuration_obj, root_key) length = len(keys) if length < 3: From cf5c6e34bf9af09718bf23c1de6270b8a28104bc Mon Sep 17 00:00:00 2001 From: Viraj Patel Date: Fri, 2 Sep 2022 06:41:56 +0000 Subject: [PATCH 4/6] chore: address linters --- aea/configurations/base.py | 1 - 1 file changed, 1 deletion(-) diff --git a/aea/configurations/base.py b/aea/configurations/base.py index 28ee524ce7..d0f7f38847 100644 --- a/aea/configurations/base.py +++ b/aea/configurations/base.py @@ -951,7 +951,6 @@ class SkillConfig(ComponentConfiguration): default_configuration_filename = DEFAULT_SKILL_CONFIG_FILE package_type = PackageType.SKILL schema = "skill-config_schema.json" - abstract_field_name = "is_abstract" FIELDS_ALLOWED_TO_UPDATE: FrozenSet[str] = frozenset( ["behaviours", "handlers", "models", "is_abstract", "build_directory"] From a5e3202b6ba4e027601685a95ae7a6a9bd6c278a Mon Sep 17 00:00:00 2001 From: Viraj Patel Date: Fri, 2 Sep 2022 07:37:43 +0000 Subject: [PATCH 5/6] chore: revert temp changes --- aea/configurations/base.py | 30 ++++++++++++++++++++++++++++++ 1 file changed, 30 insertions(+) diff --git a/aea/configurations/base.py b/aea/configurations/base.py index d0f7f38847..16ce21cb04 100644 --- a/aea/configurations/base.py +++ b/aea/configurations/base.py @@ -228,6 +228,8 @@ class PackageConfiguration(Configuration, ABC): package_type: PackageType FIELDS_ALLOWED_TO_UPDATE: FrozenSet[str] = frozenset(["build_directory"]) + FIELDS_WITH_NESTED_FIELDS: FrozenSet[str] = frozenset() + NESTED_FIELDS_ALLOWED_TO_UPDATE: FrozenSet[str] = frozenset() schema: str CHECK_EXCLUDES: List[Tuple[str]] = [] @@ -575,6 +577,7 @@ class ConnectionConfig(ComponentConfiguration): FIELDS_ALLOWED_TO_UPDATE: FrozenSet[str] = frozenset( ["config", "cert_requests", "is_abstract", "build_directory"] ) + FIELDS_WITH_NESTED_FIELDS: FrozenSet[str] = frozenset(["config"]) __slots__ = ( "class_name", @@ -951,10 +954,15 @@ class SkillConfig(ComponentConfiguration): default_configuration_filename = DEFAULT_SKILL_CONFIG_FILE package_type = PackageType.SKILL schema = "skill-config_schema.json" + abstract_field_name = "is_abstract" FIELDS_ALLOWED_TO_UPDATE: FrozenSet[str] = frozenset( ["behaviours", "handlers", "models", "is_abstract", "build_directory"] ) + FIELDS_WITH_NESTED_FIELDS: FrozenSet[str] = frozenset( + ["behaviours", "handlers", "models"] + ) + NESTED_FIELDS_ALLOWED_TO_UPDATE: FrozenSet[str] = frozenset(["args"]) __slots__ = ( "connections", @@ -1131,6 +1139,27 @@ def _create_or_update_from_json( return instance + def get_overridable(self) -> dict: + """Get overridable configuration data.""" + result = {} + current_config_data = self.json + if self.abstract_field_name in current_config_data: + result[self.abstract_field_name] = current_config_data[ + self.abstract_field_name + ] + + for field in self.FIELDS_WITH_NESTED_FIELDS: + if not current_config_data.get(field, {}): + continue + result[field] = {} + for name in current_config_data[field].keys(): + result[field][name] = {} + for nested_field in self.NESTED_FIELDS_ALLOWED_TO_UPDATE: + result[field][name][nested_field] = current_config_data[field][ + name + ][nested_field] + return result + class AgentConfig(PackageConfiguration): """Class to represent the agent configuration file.""" @@ -1161,6 +1190,7 @@ class AgentConfig(PackageConfiguration): "storage_uri", ] ) + FIELDS_WITH_NESTED_FIELDS: FrozenSet[str] = frozenset(["logging_config"]) CHECK_EXCLUDES = [ ("private_key_paths",), ("connection_private_key_paths",), From 54a522f161d40ac82ea04151a087a67d17939943 Mon Sep 17 00:00:00 2001 From: Viraj Patel Date: Fri, 2 Sep 2022 08:16:53 +0000 Subject: [PATCH 6/6] chore: revert changes --- aea/test_tools/generic.py | 7 +++++-- 1 file changed, 5 insertions(+), 2 deletions(-) diff --git a/aea/test_tools/generic.py b/aea/test_tools/generic.py index b9adc8267a..d55ad6bc31 100644 --- a/aea/test_tools/generic.py +++ b/aea/test_tools/generic.py @@ -117,10 +117,13 @@ def get_nested_ordered_dict_from_keys_and_value( return _dic root_key = keys[0] - if isinstance(configuration_obj, SkillConfig): + if ( + isinstance(configuration_obj, SkillConfig) + and root_key in SkillConfig.FIELDS_WITH_NESTED_FIELDS + ): root_attr = getattr(configuration_obj, root_key) length = len(keys) - if length < 3: + if length < 3 or keys[2] not in SkillConfig.NESTED_FIELDS_ALLOWED_TO_UPDATE: raise ValueError(f"Invalid keys={keys}.") # pragma: nocover skill_component_id = keys[1] skill_component_config = root_attr.read(skill_component_id)