You are viewing a plain text version of this content. The canonical link for it is here.
Posted to commits@buildstream.apache.org by no...@apache.org on 2020/12/29 12:34:27 UTC

[buildstream] 06/10: element.py: Rework 'node_subst_list' to take the sequence directly

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

not-in-ldap pushed a commit to branch bschubert/more-mypy
in repository https://gitbox.apache.org/repos/asf/buildstream.git

commit d5bc3208414c70950114cdd0d4f73fb277dcad40
Author: Benjamin Schubert <co...@benschubert.me>
AuthorDate: Tue Oct 15 13:56:48 2019 +0100

    element.py: Rework 'node_subst_list' to take the sequence directly
    
    Also rename it to 'node_sequence_substitute_variables' to mimic
    'node_substitute_variables'.
---
 src/buildstream/element.py                 | 13 ++++++-------
 src/buildstream/plugins/elements/script.py |  2 +-
 2 files changed, 7 insertions(+), 8 deletions(-)

diff --git a/src/buildstream/element.py b/src/buildstream/element.py
index 5d3b1cb..5230557 100644
--- a/src/buildstream/element.py
+++ b/src/buildstream/element.py
@@ -112,7 +112,7 @@ from .storage._casbaseddirectory import CasBasedDirectory
 from .storage.directory import VirtualDirectoryError
 
 if TYPE_CHECKING:
-    from .node import MappingNode, ScalarNode
+    from .node import MappingNode, ScalarNode, SequenceNode
     from .types import SourceRef
     from typing import Set, Tuple
 
@@ -562,22 +562,21 @@ class Element(Plugin):
             provenance = node.get_provenance()
             raise LoadError('{}: {}'.format(provenance, e), e.reason, detail=e.detail) from e
 
-    def node_subst_list(self, node: 'MappingNode[str, Any]', member_name: str) -> List[Any]:
-        """Fetch a list from a node member, substituting any variables in the list
+    def node_sequence_substitute_variables(self, node: 'SequenceNode[ScalarNode]') -> List[str]:
+        """Substitute any variables in the given sequence
 
         Args:
-          node: A MappingNode loaded from YAML
-          member_name: The name of the member to fetch (a list)
+          node: A SequenceNode loaded from YAML
 
         Returns:
-          The list in *member_name*
+          The list with every variable replaced
 
         Raises:
           :class:`.LoadError`
 
         """
         ret = []
-        for value in node.get_sequence(member_name):
+        for value in node:
             try:
                 ret.append(self.__variables.subst(value.as_str()))
             except LoadError as e:
diff --git a/src/buildstream/plugins/elements/script.py b/src/buildstream/plugins/elements/script.py
index 483c70d..6bc0569 100644
--- a/src/buildstream/plugins/elements/script.py
+++ b/src/buildstream/plugins/elements/script.py
@@ -55,7 +55,7 @@ class ScriptElement(buildstream.ScriptElement):
             'commands', 'root-read-only', 'layout'
         ])
 
-        cmds = self.node_subst_list(node, "commands")
+        cmds = self.node_sequence_substitute_variables(node.get_sequence("commands"))
         self.add_commands("commands", cmds)
 
         self.set_work_dir()