diff options
author | Benjamin Schubert <ben.c.schubert@gmail.com> | 2019-06-25 10:17:44 +0100 |
---|---|---|
committer | bst-marge-bot <marge-bot@buildstream.build> | 2019-07-15 14:14:02 +0000 |
commit | 0d957f0d8e3d6492d2144f0b57df163eaf1ab1e5 (patch) | |
tree | 0e601df1fe8a7d7ebecbc678ac50b3fff668d849 /src/buildstream/_includes.py | |
parent | 88abfbd8a29c5056eb0f089463cc28813bb172ad (diff) | |
download | buildstream-0d957f0d8e3d6492d2144f0b57df163eaf1ab1e5.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.py | 19 |
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, '(@)') |