summaryrefslogtreecommitdiff
path: root/src/buildstream/_includes.py
diff options
context:
space:
mode:
authorBenjamin Schubert <ben.c.schubert@gmail.com>2019-06-25 10:17:44 +0100
committerBenjamin Schubert <ben.c.schubert@gmail.com>2019-07-01 22:26:32 +0100
commit52361b728872b9c5cf5deec6b139b2b0eec045d3 (patch)
tree66f1098318f5f55445ac6ef8480251d4b1ab9837 /src/buildstream/_includes.py
parent0416c9918cfcd74f72ccc89eb2a3506d6694416e (diff)
downloadbuildstream-52361b728872b9c5cf5deec6b139b2b0eec045d3.tar.gz
_yaml: Add a 'get_node' on Mapping, when return type can be of multiple types
Sometimes, we might want to have a list or a string, in which case, we can now use 'get_node', which can return multiple types. This method doesn't contain a 'default' value, as building a 'Node' from it would be hard. We therefore just have a 'allow_none' flag that allows returning 'None' when the value is not found. - includes: use the new 'get_node' instead of trying multiple versions
Diffstat (limited to 'src/buildstream/_includes.py')
-rw-r--r--src/buildstream/_includes.py19
1 files changed, 7 insertions, 12 deletions
diff --git a/src/buildstream/_includes.py b/src/buildstream/_includes.py
index 9bed8189c..2831c9765 100644
--- a/src/buildstream/_includes.py
+++ b/src/buildstream/_includes.py
@@ -35,19 +35,14 @@ class Includes:
if current_loader is None:
current_loader = self._loader
- try:
- includes = node.get_str('(@)', default=None)
- if includes is not None:
- includes = [includes]
- except LoadError:
- try:
- includes = node.get_sequence('(@)').as_str_list()
- except LoadError:
- provenance = _yaml.node_get_provenance(node, key='(@)')
- raise LoadError(LoadErrorReason.INVALID_DATA,
- "{}: {} must either be list or str".format(provenance, _yaml.node_sanitize(node)))
+ includes_node = node.get_node('(@)', allowed_types=[_yaml.ScalarNode, _yaml.SequenceNode], allow_none=True)
+
+ if includes_node:
+ if type(includes_node) is _yaml.ScalarNode: # pylint: disable=unidiomatic-typecheck
+ includes = [includes_node.as_str()]
+ else:
+ includes = includes_node.as_str_list()
- if includes:
include_provenance = _yaml.node_get_provenance(node, key='(@)')
_yaml.node_del(node, '(@)')