summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorbst-marge-bot <marge-bot@buildstream.build>2019-04-04 10:43:45 +0000
committerbst-marge-bot <marge-bot@buildstream.build>2019-04-04 10:43:45 +0000
commita3fe0a4c5d7d52d456707f675974bbf4ecc62626 (patch)
tree221a5068473631a98df039d21745f9b594c2dd72
parent9605f798022a02ff92f089d54f031c12bfbe6a00 (diff)
parent58e3ecde55276f6101211af58e7c21e04485e4b9 (diff)
downloadbuildstream-a3fe0a4c5d7d52d456707f675974bbf4ecc62626.tar.gz
Merge branch 'danielsilverstone-ct/more-yaml-cleanups' into 'master'
_yaml.py: Add node_keys() See merge request BuildStream/buildstream!1274
-rw-r--r--buildstream/_options/optionpool.py2
-rw-r--r--buildstream/_project.py10
-rw-r--r--buildstream/_yaml.py17
3 files changed, 23 insertions, 6 deletions
diff --git a/buildstream/_options/optionpool.py b/buildstream/_options/optionpool.py
index 5b248111f..de3af3e15 100644
--- a/buildstream/_options/optionpool.py
+++ b/buildstream/_options/optionpool.py
@@ -91,7 +91,7 @@ class OptionPool():
# node (dict): The loaded YAML options
#
def load_yaml_values(self, node, *, transform=None):
- for option_name, _ in _yaml.node_items(node):
+ for option_name in _yaml.node_keys(node):
try:
option = self._options[option_name]
except KeyError as e:
diff --git a/buildstream/_project.py b/buildstream/_project.py
index c6d0f29fd..18c2319c0 100644
--- a/buildstream/_project.py
+++ b/buildstream/_project.py
@@ -720,7 +720,7 @@ class Project():
# Perform environment expansion right away
shell_environment = _yaml.node_get(shell_options, Mapping, 'environment', default_value={})
- for key, _ in _yaml.node_items(shell_environment):
+ for key in _yaml.node_keys(shell_environment):
value = _yaml.node_get(shell_environment, str, key)
self._shell_environment[key] = os.path.expandvars(value)
@@ -895,7 +895,7 @@ class Project():
# Store source versions for checking later
source_versions = _yaml.node_get(origin, Mapping, 'sources', default_value={})
- for key, _ in _yaml.node_items(source_versions):
+ for key in _yaml.node_keys(source_versions):
if key in source_format_versions:
raise LoadError(
LoadErrorReason.INVALID_YAML,
@@ -904,7 +904,7 @@ class Project():
# Store element versions for checking later
element_versions = _yaml.node_get(origin, Mapping, 'elements', default_value={})
- for key, _ in _yaml.node_items(element_versions):
+ for key in _yaml.node_keys(element_versions):
if key in element_format_versions:
raise LoadError(
LoadErrorReason.INVALID_YAML,
@@ -944,11 +944,11 @@ class Project():
raise LoadError(LoadErrorReason.INVALID_DATA,
"Unexpected plugin group: {}, expecting {}"
.format(plugin_group, expected_groups))
- node_keys = [key for key, _ in _yaml.node_items(origin)]
+ node_keys = [key for key in _yaml.node_keys(origin)]
if plugin_group in node_keys:
origin_node = _yaml.node_copy(origin)
plugins = _yaml.node_get(origin, Mapping, plugin_group, default_value={})
- _yaml.node_set(origin_node, 'plugins', [k for k, _ in _yaml.node_items(plugins)])
+ _yaml.node_set(origin_node, 'plugins', [k for k in _yaml.node_keys(plugins)])
for group in expected_groups:
if _yaml.node_contains(origin_node, group):
_yaml.node_del(origin_node, group)
diff --git a/buildstream/_yaml.py b/buildstream/_yaml.py
index 5184485de..15ae5752f 100644
--- a/buildstream/_yaml.py
+++ b/buildstream/_yaml.py
@@ -642,6 +642,23 @@ def node_items(node):
yield (key, value[0])
+# node_keys()
+#
+# A convenience generator for iterating over loaded keys
+# in a dictionary loaded from project YAML.
+#
+# Args:
+# node (dict): The dictionary node
+#
+# Yields:
+# (str): The key name
+#
+def node_keys(node):
+ if type(node) is not Node:
+ node = Node(node, None, 0, 0)
+ yield from node[0].keys()
+
+
# node_del()
#
# A convenience generator for iterating over loaded key/value