From 32f486cbf39e54a747bbf8f570e6cdb78ec5ac28 Mon Sep 17 00:00:00 2001 From: Oliver Cleary Date: Thu, 21 Mar 2024 07:15:35 +1100 Subject: [PATCH] [Resolves #1187] Rename dict_merge and list_join config params to merge --- docs/_source/docs/stack_config.rst | 20 ++++++++++---------- docs/_source/docs/stack_group_config.rst | 5 ++--- sceptre/config/reader.py | 6 +----- sceptre/config/strategies.py | 13 +++++++------ tests/test_config_reader.py | 6 ++---- 5 files changed, 22 insertions(+), 28 deletions(-) diff --git a/docs/_source/docs/stack_config.rst b/docs/_source/docs/stack_config.rst index 267a3f48e..d8e88075a 100644 --- a/docs/_source/docs/stack_config.rst +++ b/docs/_source/docs/stack_config.rst @@ -110,9 +110,9 @@ dependencies_inheritance This configuration will override the default inheritance strategy of `dependencies`. -The default value for this is ``list_join``. +The default value for this is ``merge``. -Valid values for this config are: ``list_join``, or ``child_wins``. +Valid values for this config are: ``merge``, or ``override``. hooks ~~~~~ @@ -131,9 +131,9 @@ hooks_inheritance This configuration will override the default inheritance strategy of `hooks`. -The default value for this is ``child_wins``. +The default value for this is ``override``. -Valid values for this config are: ``list_join``, or ``child_wins``. +Valid values for this config are: ``merge``, or ``override``. ignore ~~~~~~ @@ -329,9 +329,9 @@ parameters_inheritance This configuration will override the default inheritance strategy of `parameters`. -The default value for this is ``child_wins``. +The default value for this is ``override``. -Valid values for this config are: ``dict_merge``, or ``child_wins``. +Valid values for this config are: ``merge``, or ``override``. protected ~~~~~~~~~ @@ -446,9 +446,9 @@ sceptre_user_data_inheritance This configuration will override the default inheritance strategy of `sceptre_user_data`. -The default value for this is ``child_wins``. +The default value for this is ``override``. -Valid values for this config are: ``dict_merge``, or ``child_wins``. +Valid values for this config are: ``merge``, or ``override``. stack_name ~~~~~~~~~~ @@ -501,9 +501,9 @@ stack_tags_inheritance This configuration will override the default inheritance strategy of `stack_tags`. -The default value for this is ``child_wins``. +The default value for this is ``override``. -Valid values for this config are: ``dict_merge``, or ``child_wins``. +Valid values for this config are: ``merge``, or ``override``. stack_timeout ~~~~~~~~~~~~~ diff --git a/docs/_source/docs/stack_group_config.rst b/docs/_source/docs/stack_group_config.rst index 1b0b4b92c..c465f6ee5 100644 --- a/docs/_source/docs/stack_group_config.rst +++ b/docs/_source/docs/stack_group_config.rst @@ -192,9 +192,8 @@ The inheritance strategy of some properties may be overridden by the stack group Strategy options: - - ``list_join``: Child configs are appended to parent configs. - - ``dict_merge``: Child configs will be merged with parent configs, the child keys taking precedence. - - ``child_wins``: Overrides parent if set. +* ``merge``: Child config is merged with parent configs. For maps child keys take precedence. +* ``override``: Overrides parent if set. .. _setting_dependencies_for_stack_groups: diff --git a/sceptre/config/reader.py b/sceptre/config/reader.py index de65a7993..fc7421772 100644 --- a/sceptre/config/reader.py +++ b/sceptre/config/reader.py @@ -435,16 +435,12 @@ def _get_merge_with_stratgies(self, left: dict, right: dict) -> dict: ) if not name: pass - elif name not in strategies.SELECTABLE: - raise SceptreException( - f"{name} is not a valid inheritance strategy" - ) elif name not in CONFIG_MERGE_STRATEGY_OVERRIDES[config_key]: raise SceptreException( f"{name} is not a valid inheritance strategy for {config_key}" ) else: - strategy = strategies.SELECTABLE[name] + strategy = CONFIG_MERGE_STRATEGY_OVERRIDES[config_key][name] value = strategy(left.get(config_key), right.get(config_key)) if value: diff --git a/sceptre/config/strategies.py b/sceptre/config/strategies.py index 744169ee9..65f033d2d 100644 --- a/sceptre/config/strategies.py +++ b/sceptre/config/strategies.py @@ -86,10 +86,11 @@ def child_or_parent(a, b): return b or a -SELECTABLE = { - "list_join": list_join, - "dict_merge": dict_merge, - "child_wins": child_wins, +LIST_STRATEGIES = { + "merge": list_join, + "override": child_wins, +} +DICT_STRATEGIES = { + "merge": dict_merge, + "override": child_wins, } -LIST_STRATEGIES = ["list_join", "child_wins"] -DICT_STRATEGIES = ["dict_merge", "child_wins"] diff --git a/tests/test_config_reader.py b/tests/test_config_reader.py index ccb6d9e5c..1bd9f7eaf 100644 --- a/tests/test_config_reader.py +++ b/tests/test_config_reader.py @@ -737,7 +737,7 @@ def test_inheritance_strategy_override_dict_merge( for i, (stack_path, stack_values) in enumerate(zip(filepaths, values)): params = {config_key: stack_values} if i == inheritance_at: - params[f"{config_key}_inheritance"] = "dict_merge" + params[f"{config_key}_inheritance"] = "merge" config = { "region": "region", "project_code": "project_code", @@ -787,7 +787,7 @@ def test_inheritance_strategy_override_list_join( for i, (stack_path, stack_values) in enumerate(zip(filepaths, values)): params = {config_key: stack_values} if i == inheritance_at: - params[f"{config_key}_inheritance"] = "list_join" + params[f"{config_key}_inheritance"] = "merge" config = { "region": "region", "project_code": "project_code", @@ -808,8 +808,6 @@ def test_inheritance_strategy_override_list_join( @pytest.mark.parametrize( "config_key,strategy", ( - ("hooks", "dict_merge"), - ("stack_tags", "list_join"), ("hooks", "foo"), ("hooks", "deepcopy"), ("hooks", "child_or_parent"),