Skip to content

Commit

Permalink
[Resolves #1187] Rename dict_merge and list_join config params to merge
Browse files Browse the repository at this point in the history
  • Loading branch information
okcleary committed Mar 20, 2024
1 parent 3ecd9be commit 32f486c
Show file tree
Hide file tree
Showing 5 changed files with 22 additions and 28 deletions.
20 changes: 10 additions & 10 deletions docs/_source/docs/stack_config.rst
Original file line number Diff line number Diff line change
Expand Up @@ -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
~~~~~
Expand All @@ -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
~~~~~~
Expand Down Expand Up @@ -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
~~~~~~~~~
Expand Down Expand Up @@ -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
~~~~~~~~~~
Expand Down Expand Up @@ -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
~~~~~~~~~~~~~
Expand Down
5 changes: 2 additions & 3 deletions docs/_source/docs/stack_group_config.rst
Original file line number Diff line number Diff line change
Expand Up @@ -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:

Expand Down
6 changes: 1 addition & 5 deletions sceptre/config/reader.py
Original file line number Diff line number Diff line change
Expand Up @@ -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:
Expand Down
13 changes: 7 additions & 6 deletions sceptre/config/strategies.py
Original file line number Diff line number Diff line change
Expand Up @@ -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"]
6 changes: 2 additions & 4 deletions tests/test_config_reader.py
Original file line number Diff line number Diff line change
Expand Up @@ -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",
Expand Down Expand Up @@ -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",
Expand All @@ -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"),
Expand Down

0 comments on commit 32f486c

Please sign in to comment.