From 80d59cdf96fbd1e157cbbead0262801df7283ce1 Mon Sep 17 00:00:00 2001 From: Kevin Carter Date: Tue, 24 Jan 2017 23:00:20 -0600 Subject: [PATCH] Added yaml class dumper to support indentation The default py yaml `safe_dumps` keeps to the yaml spec which states incremental indentations are not required. Sadly, without the indentations some consumers of yaml configurations files will break. This commit adds an incremental indentation dumper to cater for all yaml configuration consumers. Change-Id: Ifa5bcc6ff9f0a9cb5e619e62d0356f5d6887ca6e Signed-off-by: Kevin Carter --- action/_v2_config_template.py | 8 +++++++- tests/files/test_extend.yml.expected | 12 ++++++------ tests/files/test_no_extend.yml.expected | 6 +++--- 3 files changed, 16 insertions(+), 10 deletions(-) diff --git a/action/_v2_config_template.py b/action/_v2_config_template.py index 361c2a0..ff8c5c1 100644 --- a/action/_v2_config_template.py +++ b/action/_v2_config_template.py @@ -73,6 +73,11 @@ def _convert_2_string(item): return str(item) +class IDumper(yaml.SafeDumper): + def increase_indent(self, flow=False, indentless=False): + return super(IDumper, self).increase_indent(flow, False) + + class MultiKeyDict(dict): """Dictionary class which supports duplicate keys. This class allows for an item to be added into a standard python dictionary @@ -374,8 +379,9 @@ class ActionModule(ActionBase): new_items=config_overrides, list_extend=list_extend ) - return yaml.safe_dump( + return yaml.dump( merged_resultant, + Dumper=IDumper, default_flow_style=False, width=1000, ) diff --git a/tests/files/test_extend.yml.expected b/tests/files/test_extend.yml.expected index b81b2e3..c132a76 100644 --- a/tests/files/test_extend.yml.expected +++ b/tests/files/test_extend.yml.expected @@ -1,8 +1,8 @@ list_one: -- one -- two -- three -- four + - one + - two + - three + - four list_two: -- one -- two + - one + - two diff --git a/tests/files/test_no_extend.yml.expected b/tests/files/test_no_extend.yml.expected index b864299..4713768 100644 --- a/tests/files/test_no_extend.yml.expected +++ b/tests/files/test_no_extend.yml.expected @@ -1,5 +1,5 @@ list_one: -- four + - four list_two: -- one -- two + - one + - two