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-11 18:34:20 +0100
commit9b51c59deece7b33288343e385eac89c335040c1 (patch)
treed6a92782685600cf9b0d973e0815ec3bfa89bace
parent890511ec5fa1d3463ade54bc2bd89da6c360e6de (diff)
downloadbuildstream-9b51c59deece7b33288343e385eac89c335040c1.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 b2a7f88aa..e0c04b655 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(
@@ -1339,19 +1339,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 828d05017..89655e15b 100644
--- a/src/buildstream/source.py
+++ b/src/buildstream/source.py
@@ -964,7 +964,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: