summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorBenjamin Schubert <contact@benschubert.me>2019-06-25 20:27:15 +0100
committerBenjamin Schubert <ben.c.schubert@gmail.com>2019-07-01 22:26:44 +0100
commit328a9816863a8e404311f9ecdac332cd57fb715c (patch)
tree9410b9816780c40567e63bcaadfcc18dc40a4cad
parent8d55609815c90254ee1ae2489449b4c39840728c (diff)
downloadbuildstream-328a9816863a8e404311f9ecdac332cd57fb715c.tar.gz
_yaml: Introduce 'MappingNode.values()'
This is to mimic the 'dict.values()' interface. - Adapt parts of the code calling 'node_items' but ignoring the first value to use this instead
-rw-r--r--src/buildstream/_context.py2
-rw-r--r--src/buildstream/_includes.py8
-rw-r--r--src/buildstream/_options/optionpool.py12
-rw-r--r--src/buildstream/_yaml.pxd1
-rw-r--r--src/buildstream/_yaml.pyx3
5 files changed, 17 insertions, 9 deletions
diff --git a/src/buildstream/_context.py b/src/buildstream/_context.py
index 21c272daa..cc31e982a 100644
--- a/src/buildstream/_context.py
+++ b/src/buildstream/_context.py
@@ -313,7 +313,7 @@ class Context():
# Shallow validation of overrides, parts of buildstream which rely
# on the overrides are expected to validate elsewhere.
- for _, overrides in _yaml.node_items(self._project_overrides):
+ for overrides in self._project_overrides.values():
_yaml.node_validate(overrides,
['artifacts', 'source-caches', 'options',
'strict', 'default-mirror',
diff --git a/src/buildstream/_includes.py b/src/buildstream/_includes.py
index f63e56213..ea2bf484e 100644
--- a/src/buildstream/_includes.py
+++ b/src/buildstream/_includes.py
@@ -83,7 +83,7 @@ class Includes:
_yaml.composite_and_move(node, include_node)
- for _, value in _yaml.node_items(node):
+ for value in node.values():
self._process_value(value,
included=included,
current_loader=current_loader,
@@ -129,12 +129,14 @@ class Includes:
included=set(),
current_loader=None,
only_local=False):
- if _yaml.is_node(value):
+ value_type = type(value)
+
+ if value_type is _yaml.MappingNode:
self.process(value,
included=included,
current_loader=current_loader,
only_local=only_local)
- elif isinstance(value, list):
+ elif value_type is _yaml.SequenceNode:
for v in value:
self._process_value(v,
included=included,
diff --git a/src/buildstream/_options/optionpool.py b/src/buildstream/_options/optionpool.py
index 23459d3c5..af0f99b97 100644
--- a/src/buildstream/_options/optionpool.py
+++ b/src/buildstream/_options/optionpool.py
@@ -185,10 +185,11 @@ class OptionPool():
# Now recurse into nested dictionaries and lists
# and process any indirectly nested conditionals.
#
- for _, value in _yaml.node_items(node):
- if _yaml.is_node(value):
+ for value in node.values():
+ value_type = type(value)
+ if value_type is _yaml.MappingNode:
self.process_node(value)
- elif isinstance(value, list):
+ elif value_type is _yaml.SequenceNode:
self._process_list(value)
#######################################################
@@ -237,9 +238,10 @@ class OptionPool():
#
def _process_list(self, values):
for value in values:
- if _yaml.is_node(value):
+ value_type = type(value)
+ if value_type is _yaml.MappingNode:
self.process_node(value)
- elif isinstance(value, list):
+ elif value_type is _yaml.SequenceNode:
self._process_list(value)
# Process a single conditional, resulting in composition
diff --git a/src/buildstream/_yaml.pxd b/src/buildstream/_yaml.pxd
index b20c798de..e80df7115 100644
--- a/src/buildstream/_yaml.pxd
+++ b/src/buildstream/_yaml.pxd
@@ -41,6 +41,7 @@ cdef class MappingNode(Node):
cpdef str get_str(self, str key, object default=*)
cpdef list keys(self)
cpdef void safe_del(self, str key)
+ cpdef object values(self)
cdef class ScalarNode(Node):
diff --git a/src/buildstream/_yaml.pyx b/src/buildstream/_yaml.pyx
index a3692c455..e3d3f7df3 100644
--- a/src/buildstream/_yaml.pyx
+++ b/src/buildstream/_yaml.pyx
@@ -241,6 +241,9 @@ cdef class MappingNode(Node):
except KeyError:
pass
+ cpdef object values(self):
+ return self.value.values()
+
def __delitem__(self, str key):
del self.value[key]