This is an automated email from the ASF dual-hosted git repository. tvb pushed a commit to branch tristan/fix-ruamel-deprecation-warnings in repository https://gitbox.apache.org/repos/asf/buildstream.git
commit de67e74854765793970762be63e67d2e7c86244d Author: Tristan van Berkom <[email protected]> AuthorDate: Sun Aug 21 13:37:10 2022 +0900 _yaml.pyx: Added roundtrip_dump_string() A convenience function for dumping yaml to a returned string --- src/buildstream/_yaml.pyx | 19 ++++++++++++++++++- 1 file changed, 18 insertions(+), 1 deletion(-) diff --git a/src/buildstream/_yaml.pyx b/src/buildstream/_yaml.pyx index 19f5dfc38..57d98e413 100644 --- a/src/buildstream/_yaml.pyx +++ b/src/buildstream/_yaml.pyx @@ -1,5 +1,5 @@ # -# Copyright (C) 2018 Codethink Limited +# Copyright (C) 2022 Codethink Limited # Copyright (C) 2019 Bloomberg LLP # # Licensed under the Apache License, Version 2.0 (the "License"); @@ -22,6 +22,7 @@ import datetime import sys +from io import StringIO from contextlib import ExitStack from collections import OrderedDict from collections.abc import Mapping @@ -477,3 +478,19 @@ def roundtrip_dump(contents, file=None): else: f = sys.stdout yml.dump(contents, f) + + +# roundtrip_dump_string() +# +# Helper to call roundtrip_dump() but get the content in a string. +# +# Args: +# contents (Mapping or list): The content to write out as YAML. +# +# Returns: +# (str): The generated string +# +def roundtrip_dump_string(node): + with StringIO() as f: + roundtrip_dump(node, f) + return f.getvalue()
