You are viewing a plain text version of this content. The canonical link for it is here.
Posted to commits@buildstream.apache.org by tv...@apache.org on 2022/08/21 04:39:19 UTC

[buildstream] branch tristan/fix-ruamel-deprecation-warnings created (now df7647463)

This is an automated email from the ASF dual-hosted git repository.

tvb pushed a change to branch tristan/fix-ruamel-deprecation-warnings
in repository https://gitbox.apache.org/repos/asf/buildstream.git


      at df7647463 element.py, _frontend/widget.py: Use _yaml.roundtrip_dump_string()

This branch includes the following new commits:

     new de67e7485 _yaml.pyx: Added roundtrip_dump_string()
     new df7647463 element.py, _frontend/widget.py: Use _yaml.roundtrip_dump_string()

The 2 revisions listed above as "new" are entirely new to this
repository and will be described in separate emails.  The revisions
listed as "add" were already present in the repository and have only
been added to this reference.



[buildstream] 02/02: element.py, _frontend/widget.py: Use _yaml.roundtrip_dump_string()

Posted by tv...@apache.org.
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 df7647463d1dcdac3f7518740c7d9a49ca992e84
Author: Tristan van Berkom <tr...@codethink.co.uk>
AuthorDate: Sun Aug 21 13:37:54 2022 +0900

    element.py, _frontend/widget.py: Use _yaml.roundtrip_dump_string()
    
    Instead of deprecated round_trip_dump() from ruamel.yaml.
    
    This will silence a lot of the remaining pesky deprecation warnings after
    running tests in tox.
---
 src/buildstream/_frontend/widget.py | 16 +++++-----------
 src/buildstream/element.py          |  4 ++--
 2 files changed, 7 insertions(+), 13 deletions(-)

diff --git a/src/buildstream/_frontend/widget.py b/src/buildstream/_frontend/widget.py
index 4cede5f47..746fcba94 100644
--- a/src/buildstream/_frontend/widget.py
+++ b/src/buildstream/_frontend/widget.py
@@ -22,11 +22,11 @@ from contextlib import ExitStack
 from mmap import mmap
 import re
 import textwrap
-from ruamel import yaml
 import click
 
 from .profile import Profile
 from ..types import _Scope
+from .. import _yaml
 from .. import __version__ as bst_version
 from .. import FileType
 from .._exceptions import BstError, ImplError
@@ -384,29 +384,23 @@ class LogLine(Widget):
                 line = p.fmt_subst(
                     line,
                     "config",
-                    yaml.round_trip_dump(element._Element__config, default_flow_style=False, allow_unicode=True),
+                    _yaml.roundtrip_dump_string(element._Element__config),
                 )
 
             # Variables
             if "%{vars" in format_:
                 variables = dict(element._Element__variables)
-                line = p.fmt_subst(
-                    line, "vars", yaml.round_trip_dump(variables, default_flow_style=False, allow_unicode=True)
-                )
+                line = p.fmt_subst(line, "vars", _yaml.roundtrip_dump_string(variables))
 
             # Environment
             if "%{env" in format_:
                 environment = element._Element__environment
-                line = p.fmt_subst(
-                    line, "env", yaml.round_trip_dump(environment, default_flow_style=False, allow_unicode=True)
-                )
+                line = p.fmt_subst(line, "env", _yaml.roundtrip_dump_string(environment))
 
             # Public
             if "%{public" in format_:
                 environment = element._Element__public
-                line = p.fmt_subst(
-                    line, "public", yaml.round_trip_dump(environment, default_flow_style=False, allow_unicode=True)
-                )
+                line = p.fmt_subst(line, "public", _yaml.roundtrip_dump_string(environment))
 
             # Workspaced
             if "%{workspaced" in format_:
diff --git a/src/buildstream/element.py b/src/buildstream/element.py
index 9382c8c61..66bc9cf8c 100644
--- a/src/buildstream/element.py
+++ b/src/buildstream/element.py
@@ -77,7 +77,6 @@ import string
 from typing import cast, TYPE_CHECKING, Any, Dict, Iterator, Iterable, List, Optional, Set, Sequence
 
 from pyroaring import BitMap  # pylint: disable=no-name-in-module
-from ruamel import yaml
 
 from . import _yaml
 from ._variables import Variables
@@ -1654,7 +1653,8 @@ class Element(Plugin):
         assert not self._cached_success()
 
         # Print the environment at the beginning of the log file.
-        env_dump = yaml.round_trip_dump(self.get_environment(), default_flow_style=False, allow_unicode=True)
+        env_dump = _yaml.roundtrip_dump_string(self.get_environment())
+
         self.log("Build environment for element {}".format(self.name), detail=env_dump)
 
         context = self._get_context()


[buildstream] 01/02: _yaml.pyx: Added roundtrip_dump_string()

Posted by tv...@apache.org.
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 <tr...@codethink.co.uk>
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()