Use custom YAML subclass to be compatible with ruamel_yaml>=0.17

Signed-off-by: Martin Weinelt <hexa@darmstadt.ccc.de>
This commit is contained in:
Martin Weinelt
2021-06-20 15:18:37 +02:00
parent 09f6bf1b46
commit e0942417a1
3 changed files with 30 additions and 13 deletions

18
whipper/common/yaml.py Normal file
View File

@@ -0,0 +1,18 @@
from ruamel.yaml import YAML as ruamel_YAML
from ruamel.yaml.compat import StringIO
# https://yaml.readthedocs.io/en/latest/example.html#output-of-dump-as-a-string
class YAML(ruamel_YAML):
def __init__(self, *args, **kwargs):
super().__init__()
self.width = 4000
self.default_flow_style = False
def dump(self, data, stream=None, **kw):
inefficient = False
if stream is None:
inefficient = True
stream = StringIO()
ruamel_YAML.dump(self, data, stream, **kw)
if inefficient:
return stream.getvalue()