diff options
author | Benjamin Schubert <contact@benschubert.me> | 2019-06-25 20:27:15 +0100 |
---|---|---|
committer | bst-marge-bot <marge-bot@buildstream.build> | 2019-07-15 14:14:03 +0000 |
commit | 42d3d8406a15cd5f6f4a7d00e298dba019a50ed6 (patch) | |
tree | 7165dafdc3707faf4e71fba8c81d5752fd4668d8 | |
parent | ed2dde6110a5f9087ff3596df9d86ba5468dcac8 (diff) | |
download | buildstream-42d3d8406a15cd5f6f4a7d00e298dba019a50ed6.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.py | 2 | ||||
-rw-r--r-- | src/buildstream/_includes.py | 8 | ||||
-rw-r--r-- | src/buildstream/_options/optionpool.py | 12 | ||||
-rw-r--r-- | src/buildstream/_yaml.pxd | 1 | ||||
-rw-r--r-- | src/buildstream/_yaml.pyx | 3 |
5 files changed, 17 insertions, 9 deletions
diff --git a/src/buildstream/_context.py b/src/buildstream/_context.py index 198e7f092..2bebc4845 100644 --- a/src/buildstream/_context.py +++ b/src/buildstream/_context.py @@ -316,7 +316,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 63ebd6e68..a00691b0e 100644 --- a/src/buildstream/_yaml.pyx +++ b/src/buildstream/_yaml.pyx @@ -238,6 +238,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] |