summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorTristan Van Berkom <tristan.vanberkom@codethink.co.uk>2017-10-01 19:06:21 +0900
committerTristan Van Berkom <tristan.vanberkom@codethink.co.uk>2017-10-01 19:17:13 +0900
commit2d664a9a47c55f5adb8f7d9694fc4198067411ea (patch)
treee05f1e6b5f06312f986a170b1f29d7502617c863
parent717ef5e35deda4637d0b74a62a3718b83e5471b1 (diff)
downloadbuildstream-2d664a9a47c55f5adb8f7d9694fc4198067411ea.tar.gz
_yaml.py: Fixing inconsistently named API _yaml.validate_node()
All of the _yaml APIs which deal with a node (dictionary loaded from YAML) are named _yaml.node_foo(), _yaml.node_bar(), _yaml.node_baz() etc, except for this one glaring exception. Also added a missing internal API documenting comment for _yaml.node_validate() Also updated all callers to _yaml.validate_node() to now call _yaml.node_validate().
-rw-r--r--buildstream/_artifactcache/artifactcache.py2
-rw-r--r--buildstream/_loader.py4
-rw-r--r--buildstream/_yaml.py16
-rw-r--r--buildstream/context.py10
-rw-r--r--buildstream/plugin.py2
-rw-r--r--buildstream/project.py8
-rw-r--r--tests/yaml/yaml.py6
7 files changed, 31 insertions, 17 deletions
diff --git a/buildstream/_artifactcache/artifactcache.py b/buildstream/_artifactcache/artifactcache.py
index da8882cc6..d91a93738 100644
--- a/buildstream/_artifactcache/artifactcache.py
+++ b/buildstream/_artifactcache/artifactcache.py
@@ -48,7 +48,7 @@ class ArtifactCache():
override_push = _yaml.node_get(artifact_overrides, str, 'push-url', default_value='') or None
override_push_port = _yaml.node_get(artifact_overrides, int, 'push-port', default_value=22)
- _yaml.validate_node(artifact_overrides, ['pull-url', 'push-url', 'push-port'])
+ _yaml.node_validate(artifact_overrides, ['pull-url', 'push-url', 'push-port'])
if override_pull or override_push:
self.artifact_pull = override_pull
diff --git a/buildstream/_loader.py b/buildstream/_loader.py
index a442dee2c..2385cf4c5 100644
--- a/buildstream/_loader.py
+++ b/buildstream/_loader.py
@@ -212,7 +212,7 @@ class LoadElement():
self.basedir = basedir
# Ensure the root node is valid
- _yaml.validate_node(self.data, [
+ _yaml.node_validate(self.data, [
'kind', 'depends', 'sources',
'variables', 'environment', 'environment-nocache',
'config', 'public', 'description',
@@ -378,7 +378,7 @@ def extract_depends_from_node(owner, data):
dependency = Dependency(owner, dep, filename=dep, provenance=dep_provenance)
elif isinstance(dep, Mapping):
- _yaml.validate_node(dep, ['filename', 'type', 'variant'])
+ _yaml.node_validate(dep, ['filename', 'type', 'variant'])
# Make variant optional, for this we set it to None after
variant = _yaml.node_get(dep, str, Symbol.VARIANT, default_value="")
diff --git a/buildstream/_yaml.py b/buildstream/_yaml.py
index 9823f7ca3..0922bdbda 100644
--- a/buildstream/_yaml.py
+++ b/buildstream/_yaml.py
@@ -594,7 +594,21 @@ def node_sanitize(node):
return node
-def validate_node(node, valid_keys):
+# node_validate()
+#
+# Validate the node so as to ensure the user has not specified
+# any keys which are unrecognized by buildstream (usually this
+# means a typo which would otherwise not trigger an error).
+#
+# Args:
+# node (dict): A dictionary loaded from YAML
+# valid_keys (list): A list of valid keys for the specified node
+#
+# Raises:
+# LoadError: In the case that the specified node contained
+# one or more invalid keys
+#
+def node_validate(node, valid_keys):
# Probably the fastest way to do this: https://stackoverflow.com/a/23062482
valid_keys = set(valid_keys)
diff --git a/buildstream/context.py b/buildstream/context.py
index 8485bb035..d271e06d5 100644
--- a/buildstream/context.py
+++ b/buildstream/context.py
@@ -161,7 +161,7 @@ class Context():
user_config = _yaml.load(config)
_yaml.composite(defaults, user_config, typesafe=True)
- _yaml.validate_node(defaults, [
+ _yaml.node_validate(defaults, [
'strict', 'sourcedir',
'builddir', 'artifactdir',
'logdir', 'scheduler',
@@ -182,14 +182,14 @@ class Context():
# Load artifact share configuration
artifacts = _yaml.node_get(defaults, Mapping, 'artifacts')
- _yaml.validate_node(artifacts, ['pull-url', 'push-url', 'push-port'])
+ _yaml.node_validate(artifacts, ['pull-url', 'push-url', 'push-port'])
self.artifact_pull = _yaml.node_get(artifacts, str, 'pull-url', default_value='') or None
self.artifact_push = _yaml.node_get(artifacts, str, 'push-url', default_value='') or None
self.artifact_push_port = _yaml.node_get(artifacts, int, 'push-port', default_value=22)
# Load logging config
logging = _yaml.node_get(defaults, Mapping, 'logging')
- _yaml.validate_node(logging, [
+ _yaml.node_validate(logging, [
'key-length', 'verbose',
'error-lines', 'message-lines',
'debug', 'element-format'
@@ -203,7 +203,7 @@ class Context():
# Load scheduler config
scheduler = _yaml.node_get(defaults, Mapping, 'scheduler')
- _yaml.validate_node(scheduler, [
+ _yaml.node_validate(scheduler, [
'on-error', 'fetchers', 'builders',
'pushers', 'network-retries'
])
@@ -219,7 +219,7 @@ class Context():
# Shallow validation of overrides, parts of buildstream which rely
# on the overrides are expected to validate elsewhere.
for project_name, overrides in _yaml.node_items(self._project_overrides):
- _yaml.validate_node(overrides, ['artifacts'])
+ _yaml.node_validate(overrides, ['artifacts'])
profile_end(Topics.LOAD_CONTEXT, 'load')
diff --git a/buildstream/plugin.py b/buildstream/plugin.py
index e6a21cbe9..93bac3465 100644
--- a/buildstream/plugin.py
+++ b/buildstream/plugin.py
@@ -280,7 +280,7 @@ class Plugin():
])
"""
- _yaml.validate_node(node, valid_keys)
+ _yaml.node_validate(node, valid_keys)
def node_get_list_element(self, node, expected_type, member_name, indices):
"""Fetch the value of a list element from a node member, raising an error if the
diff --git a/buildstream/project.py b/buildstream/project.py
index f44ca4605..dbb63cec6 100644
--- a/buildstream/project.py
+++ b/buildstream/project.py
@@ -158,7 +158,7 @@ class Project():
# Load project local config and override the builtin
project_conf = _yaml.load(projectfile)
_yaml.composite(config, project_conf, typesafe=True)
- _yaml.validate_node(config, [
+ _yaml.node_validate(config, [
'required-versions',
'element-path', 'variables',
'environment', 'environment-nocache',
@@ -198,7 +198,7 @@ class Project():
# Load artifacts pull/push configuration for this project
artifacts = _yaml.node_get(config, Mapping, 'artifacts')
- _yaml.validate_node(artifacts, ['pull-url', 'push-url', 'push-port'])
+ _yaml.node_validate(artifacts, ['pull-url', 'push-url', 'push-port'])
self.artifact_pull = _yaml.node_get(artifacts, str, 'pull-url', default_value='') or None
self.artifact_push = _yaml.node_get(artifacts, str, 'push-url', default_value='') or None
self.artifact_push_port = _yaml.node_get(artifacts, int, 'push-port', default_value=22)
@@ -249,7 +249,7 @@ class Project():
# Version requirements
versions = _yaml.node_get(self._unresolved_config, Mapping, 'required-versions')
- _yaml.validate_node(versions, ['project', 'elements', 'sources'])
+ _yaml.node_validate(versions, ['project', 'elements', 'sources'])
# Assert project version first
format_version = _yaml.node_get(versions, int, 'project')
@@ -276,7 +276,7 @@ class Project():
# Load the plugin paths
plugins = _yaml.node_get(self._unresolved_config, Mapping, 'plugins', default_value={})
- _yaml.validate_node(plugins, ['elements', 'sources'])
+ _yaml.node_validate(plugins, ['elements', 'sources'])
self._plugin_source_paths = [os.path.join(self.directory, path)
for path in self._extract_plugin_paths(plugins, 'sources')]
self._plugin_element_paths = [os.path.join(self.directory, path)
diff --git a/tests/yaml/yaml.py b/tests/yaml/yaml.py
index e972f89f4..948151bed 100644
--- a/tests/yaml/yaml.py
+++ b/tests/yaml/yaml.py
@@ -163,7 +163,7 @@ def test_composited_array_append_provenance(datafiles):
@pytest.mark.datafiles(os.path.join(DATA_DIR))
-def test_validate_node(datafiles):
+def test_node_validate(datafiles):
valid = os.path.join(datafiles.dirname,
datafiles.basename,
@@ -174,12 +174,12 @@ def test_validate_node(datafiles):
base = _yaml.load(valid)
- _yaml.validate_node(base, ['kind', 'description', 'moods', 'children', 'extra'])
+ _yaml.node_validate(base, ['kind', 'description', 'moods', 'children', 'extra'])
base = _yaml.load(invalid)
with pytest.raises(LoadError) as exc:
- _yaml.validate_node(base, ['kind', 'description', 'moods', 'children', 'extra'])
+ _yaml.node_validate(base, ['kind', 'description', 'moods', 'children', 'extra'])
assert (exc.value.reason == LoadErrorReason.INVALID_DATA)