This is an automated email from the ASF dual-hosted git repository. tvb pushed a commit to branch bschubert/more-mypy in repository https://gitbox.apache.org/repos/asf/buildstream.git
commit 54b101acd243079f3c3d8816da61ab01c52a6120 Author: Benjamin Schubert <[email protected]> AuthorDate: Tue Oct 15 11:57:45 2019 +0100 element.py: remove 'node_subst_member' and replace with 'node_susbstitue_variables' --- src/buildstream/element.py | 36 +++--------------------------- src/buildstream/plugins/elements/import.py | 4 ++-- src/buildstream/plugins/elements/script.py | 4 ++-- 3 files changed, 7 insertions(+), 37 deletions(-) diff --git a/src/buildstream/element.py b/src/buildstream/element.py index 6ff4016..5d3b1cb 100644 --- a/src/buildstream/element.py +++ b/src/buildstream/element.py @@ -98,7 +98,7 @@ from . import _cachekey from . import _signals from . import _site from ._platform import Platform -from .node import Node, _sentinel as _node_sentinel +from .node import Node from .plugin import Plugin from .sandbox import SandboxFlags, SandboxCommandError from .sandbox._config import SandboxConfig @@ -562,36 +562,6 @@ class Element(Plugin): provenance = node.get_provenance() raise LoadError('{}: {}'.format(provenance, e), e.reason, detail=e.detail) from e - def node_subst_member(self, node: 'MappingNode[str, Any]', member_name: str, default: str = _node_sentinel) -> Any: - """Fetch the value of a string node member, substituting any variables - in the loaded value with the element contextual variables. - - Args: - node: A MappingNode loaded from YAML - member_name: The name of the member to fetch - default: A value to return when *member_name* is not specified in *node* - - Returns: - The value of *member_name* in *node*, otherwise *default* - - Raises: - :class:`.LoadError`: When *member_name* is not found and no *default* was provided - - **Example:** - - .. code:: python - - # Expect a string 'name' in 'node', substituting any - # variables in the returned string - name = self.node_subst_member(node, 'name') - """ - value = node.get_str(member_name, default) - try: - return self.__variables.subst(value) - except LoadError as e: - provenance = node.get_scalar(member_name).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 @@ -2722,8 +2692,8 @@ class Element(Plugin): def __expand_environment(self, environment): # Resolve variables in environment value strings final_env = {} - for key in environment.keys(): - final_env[key] = self.node_subst_member(environment, key) + for key, value in environment.items(): + final_env[key] = self.node_substitute_variables(value) return final_env diff --git a/src/buildstream/plugins/elements/import.py b/src/buildstream/plugins/elements/import.py index 9568bd0..2f34b2a 100644 --- a/src/buildstream/plugins/elements/import.py +++ b/src/buildstream/plugins/elements/import.py @@ -49,8 +49,8 @@ class ImportElement(Element): 'source', 'target' ]) - self.source = self.node_subst_member(node, 'source') - self.target = self.node_subst_member(node, 'target') + self.source = self.node_substitute_variables(node.get_scalar('source')) + self.target = self.node_substitute_variables(node.get_scalar('target')) def preflight(self): # Assert that we have at least one source to fetch. diff --git a/src/buildstream/plugins/elements/script.py b/src/buildstream/plugins/elements/script.py index a7b53e4..483c70d 100644 --- a/src/buildstream/plugins/elements/script.py +++ b/src/buildstream/plugins/elements/script.py @@ -47,8 +47,8 @@ class ScriptElement(buildstream.ScriptElement): def configure(self, node): for n in node.get_sequence('layout', []): - dst = self.node_subst_member(n, 'destination') - elm = self.node_subst_member(n, 'element', None) + dst = self.node_substitute_variables(n.get_scalar('destination')) + elm = self.node_substitute_variables(n.get_scalar('element', None)) self.layout_add(elm, dst) node.validate_keys([
