diff options
author | Benjamin Schubert <contact@benschubert.me> | 2019-10-15 13:56:48 +0100 |
---|---|---|
committer | Benjamin Schubert <contact@benschubert.me> | 2019-10-15 14:26:17 +0100 |
commit | d5bc3208414c70950114cdd0d4f73fb277dcad40 (patch) | |
tree | 93ad350db154dd49b67232bfeec386f0e36da9fd | |
parent | 54b101acd243079f3c3d8816da61ab01c52a6120 (diff) | |
download | buildstream-d5bc3208414c70950114cdd0d4f73fb277dcad40.tar.gz |
element.py: Rework 'node_subst_list' to take the sequence directly
Also rename it to 'node_sequence_substitute_variables' to mimic
'node_substitute_variables'.
-rw-r--r-- | src/buildstream/element.py | 13 | ||||
-rw-r--r-- | 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 5d3b1cba0..5230557c8 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 483c70dab..6bc0569d1 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() |