summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
-rw-r--r--src/buildstream/_context.py2
-rw-r--r--src/buildstream/_gitsourcebase.py2
-rw-r--r--src/buildstream/_options/optionpool.py2
-rw-r--r--src/buildstream/_project.py11
-rw-r--r--src/buildstream/_variables.pyx2
-rw-r--r--src/buildstream/_yaml.pxd3
-rw-r--r--src/buildstream/_yaml.pyx22
-rw-r--r--src/buildstream/element.py2
8 files changed, 16 insertions, 30 deletions
diff --git a/src/buildstream/_context.py b/src/buildstream/_context.py
index b55c2647a..198e7f092 100644
--- a/src/buildstream/_context.py
+++ b/src/buildstream/_context.py
@@ -268,7 +268,7 @@ class Context():
# This stops it being used in the remote service set up
remote_execution.safe_del('pull-artifact-files')
# Don't pass the remote execution settings if that was the only option
- if _yaml.node_keys(remote_execution) == []:
+ if remote_execution.keys() == []:
del defaults['remote-execution']
else:
self.pull_artifact_files = True
diff --git a/src/buildstream/_gitsourcebase.py b/src/buildstream/_gitsourcebase.py
index 4837877f4..5ed844bbe 100644
--- a/src/buildstream/_gitsourcebase.py
+++ b/src/buildstream/_gitsourcebase.py
@@ -413,7 +413,7 @@ class _GitSourceBase(Source):
self.submodule_overrides = {}
self.submodule_checkout_overrides = {}
modules = node.get_mapping('submodules', {})
- for path, _ in self.node_items(modules):
+ for path in modules.keys():
submodule = modules.get_mapping(path)
url = submodule.get_str('url', None)
diff --git a/src/buildstream/_options/optionpool.py b/src/buildstream/_options/optionpool.py
index 713c9b056..23459d3c5 100644
--- a/src/buildstream/_options/optionpool.py
+++ b/src/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_keys(node):
+ for option_name in node.keys():
try:
option = self._options[option_name]
except KeyError as e:
diff --git a/src/buildstream/_project.py b/src/buildstream/_project.py
index e1e873858..e5c0ad21a 100644
--- a/src/buildstream/_project.py
+++ b/src/buildstream/_project.py
@@ -714,7 +714,7 @@ class Project():
# Perform environment expansion right away
shell_environment = shell_options.get_mapping('environment', default={})
- for key in _yaml.node_keys(shell_environment):
+ for key in shell_environment.keys():
value = shell_environment.get_str(key)
self._shell_environment[key] = os.path.expandvars(value)
@@ -887,7 +887,7 @@ class Project():
# Store source versions for checking later
source_versions = origin.get_mapping('sources', default={})
- for key in _yaml.node_keys(source_versions):
+ for key in source_versions.keys():
if key in source_format_versions:
raise LoadError(
LoadErrorReason.INVALID_YAML,
@@ -896,7 +896,7 @@ class Project():
# Store element versions for checking later
element_versions = origin.get_mapping('elements', default={})
- for key in _yaml.node_keys(element_versions):
+ for key in element_versions.keys():
if key in element_format_versions:
raise LoadError(
LoadErrorReason.INVALID_YAML,
@@ -936,11 +936,10 @@ class Project():
raise LoadError(LoadErrorReason.INVALID_DATA,
"Unexpected plugin group: {}, expecting {}"
.format(plugin_group, expected_groups))
- node_keys = [key for key in _yaml.node_keys(origin)]
- if plugin_group in node_keys:
+ if plugin_group in origin.keys():
origin_node = origin.copy()
plugins = origin.get_mapping(plugin_group, default={})
- _yaml.node_set(origin_node, 'plugins', [k for k in _yaml.node_keys(plugins)])
+ _yaml.node_set(origin_node, 'plugins', plugins.keys())
for group in expected_groups:
if group in origin_node:
del origin_node[group]
diff --git a/src/buildstream/_variables.pyx b/src/buildstream/_variables.pyx
index e8f083912..f1d3c2ab0 100644
--- a/src/buildstream/_variables.pyx
+++ b/src/buildstream/_variables.pyx
@@ -127,7 +127,7 @@ cdef class Variables:
cdef str key
cdef str value
- for key in _yaml.node_keys(node):
+ for key in node.keys():
value = node.get_str(key)
ret[sys.intern(key)] = _parse_expstr(value)
return ret
diff --git a/src/buildstream/_yaml.pxd b/src/buildstream/_yaml.pxd
index d198103f1..b20c798de 100644
--- a/src/buildstream/_yaml.pxd
+++ b/src/buildstream/_yaml.pxd
@@ -39,10 +39,10 @@ cdef class MappingNode(Node):
cpdef bint get_bool(self, str key, default=*) except *
cpdef int get_int(self, str key, default=*) except *
cpdef str get_str(self, str key, object default=*)
+ cpdef list keys(self)
cpdef void safe_del(self, str key)
-
cdef class ScalarNode(Node):
cpdef bint as_bool(self) except *
cpdef int as_int(self) except *
@@ -68,5 +68,4 @@ cdef class ProvenanceInformation:
cpdef void node_validate(Node node, list valid_keys) except *
cpdef void node_set(Node node, object key, object value, list indices=*) except *
-cpdef list node_keys(Node node)
cpdef ProvenanceInformation node_get_provenance(Node node, str key=*, list indices=*)
diff --git a/src/buildstream/_yaml.pyx b/src/buildstream/_yaml.pyx
index fbdaac908..63ebd6e68 100644
--- a/src/buildstream/_yaml.pyx
+++ b/src/buildstream/_yaml.pyx
@@ -229,6 +229,9 @@ cdef class MappingNode(Node):
cdef ScalarNode scalar = self.get_scalar(key, default)
return scalar.as_str()
+ cpdef list keys(self):
+ return list(self.value.keys())
+
cpdef void safe_del(self, str key):
try:
del self.value[key]
@@ -849,21 +852,6 @@ def node_items(Node node):
yield (key, value.value)
-# node_keys()
-#
-# A convenience generator for iterating over loaded keys
-# in a dictionary loaded from project YAML.
-#
-# Args:
-# node (Node): The dictionary node
-#
-# Yields:
-# (str): The key name
-#
-cpdef list node_keys(Node node):
- return list(node.value.keys())
-
-
# is_node()
#
# A test method which returns whether or not the passed in value
@@ -987,8 +975,8 @@ cdef bint _is_composite_list(Node node):
cdef bint has_keys = False
cdef str key
- if type(node.value) is dict:
- for key in node_keys(node):
+ if type(node) is MappingNode:
+ for key in (<MappingNode> node).keys():
if key in ['(>)', '(<)', '(=)']: # pylint: disable=simplifiable-if-statement
has_directives = True
else:
diff --git a/src/buildstream/element.py b/src/buildstream/element.py
index e25b387c0..8a70396be 100644
--- a/src/buildstream/element.py
+++ b/src/buildstream/element.py
@@ -2561,7 +2561,7 @@ class Element(Plugin):
def __expand_environment(self, environment):
# Resolve variables in environment value strings
final_env = {}
- for key, _ in self.node_items(environment):
+ for key in environment.keys():
final_env[key] = self.node_subst_member(environment, key)
return final_env