summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorBenjamin Schubert <ben.c.schubert@gmail.com>2019-06-27 11:18:20 +0100
committerBenjamin Schubert <ben.c.schubert@gmail.com>2019-07-01 22:26:52 +0100
commit099bff38c3b655a7f5af4771feab8b12e805985b (patch)
tree8ab19c67b492c9da3ea1cf2a235d28a7c6d07610
parent7155ae81763cc67fdbfd119bdffe30d72afc82a5 (diff)
downloadbuildstream-099bff38c3b655a7f5af4771feab8b12e805985b.tar.gz
_yaml: Remove 'key' from node_find_target
- node_find_target with 'key' is only used once in the codebase. We can remove and simplify this function - Allow 'MappingNode.get_node()' to be called without any 'expected_types'
-rw-r--r--src/buildstream/_yaml.pxd2
-rw-r--r--src/buildstream/_yaml.pyx13
-rw-r--r--src/buildstream/source.py4
3 files changed, 7 insertions, 12 deletions
diff --git a/src/buildstream/_yaml.pxd b/src/buildstream/_yaml.pxd
index 98ea64b28..6e4fd6218 100644
--- a/src/buildstream/_yaml.pxd
+++ b/src/buildstream/_yaml.pxd
@@ -33,7 +33,7 @@ cdef class Node:
cdef class MappingNode(Node):
cdef Node get(self, str key, default, default_constructor)
cpdef MappingNode get_mapping(self, str key, default=*)
- cpdef Node get_node(self, str key, list allowed_types, bint allow_none=*)
+ cpdef Node get_node(self, str key, list allowed_types=*, bint allow_none=*)
cpdef ScalarNode get_scalar(self, str key, default=*)
cpdef SequenceNode get_sequence(self, str key, object default=*)
cpdef bint get_bool(self, str key, default=*) except *
diff --git a/src/buildstream/_yaml.pyx b/src/buildstream/_yaml.pyx
index 6d5ac9508..ef1a7f015 100644
--- a/src/buildstream/_yaml.pyx
+++ b/src/buildstream/_yaml.pyx
@@ -173,7 +173,7 @@ cdef class MappingNode(Node):
return value
- cpdef Node get_node(self, str key, list allowed_types, bint allow_none = False):
+ cpdef Node get_node(self, str key, list allowed_types = None, bint allow_none = False):
cdef value = self.value.get(key, _sentinel)
if value is _sentinel:
@@ -184,7 +184,7 @@ cdef class MappingNode(Node):
raise LoadError(LoadErrorReason.INVALID_DATA,
"{}: Dictionary did not contain expected key '{}'".format(provenance, key))
- if type(value) not in allowed_types:
+ if allowed_types and type(value) not in allowed_types:
provenance = node_get_provenance(self)
raise LoadError(LoadErrorReason.INVALID_DATA,
"{}: Value of '{}' is not one of the following: {}.".format(
@@ -1342,19 +1342,12 @@ def assert_symbol_name(ProvenanceInformation provenance, str symbol_name, str pu
# Args:
# node (Node): The node at the root of the tree to search
# target (Node): The node you are looking for in that tree
-# key (str): Optional string key within target node
#
# Returns:
# (list): A path from `node` to `target` or None if `target` is not in the subtree
-cpdef list node_find_target(MappingNode node, Node target, str key=None):
- if key is not None:
- target = target.value[key]
-
+cpdef list node_find_target(MappingNode node, Node target):
cdef list path = []
if _walk_find_target(node, path, target):
- if key:
- # Remove key from end of path
- path = path[:-1]
return path
return None
diff --git a/src/buildstream/source.py b/src/buildstream/source.py
index 6d65811be..2274f47d9 100644
--- a/src/buildstream/source.py
+++ b/src/buildstream/source.py
@@ -970,7 +970,9 @@ class Source(Plugin):
if action == 'add':
path = _yaml.node_find_target(toplevel_node, node)
else:
- path = _yaml.node_find_target(toplevel_node, node, key=key)
+ full_path = _yaml.node_find_target(toplevel_node, node.get_node(key))
+ # We want the path to the node containing the key, not to the key
+ path = full_path[:-1]
roundtrip_file = roundtrip_cache.get(provenance.filename)
if not roundtrip_file: