summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorBenjamin Schubert <ben.c.schubert@gmail.com>2019-06-13 20:21:48 +0100
committerBenjamin Schubert <ben.c.schubert@gmail.com>2019-07-01 22:26:20 +0100
commitaa6531812ab4b8f86b2ef376103fd09cbbf0bb33 (patch)
tree97c86be9933ac6e3694e6efb9a982273f157983a
parentb5b42041efb564deec1a0ca606011c80e2379893 (diff)
downloadbuildstream-aa6531812ab4b8f86b2ef376103fd09cbbf0bb33.tar.gz
element: Remove `node_get_member` and all references to it
This can now be done more easily with the Node api
-rw-r--r--src/buildstream/element.py7
-rw-r--r--src/buildstream/plugin.py39
-rw-r--r--src/buildstream/plugins/sources/bzr.py2
-rw-r--r--src/buildstream/plugins/sources/pip.py2
4 files changed, 3 insertions, 47 deletions
diff --git a/src/buildstream/element.py b/src/buildstream/element.py
index 8990b03a2..38c0f4d10 100644
--- a/src/buildstream/element.py
+++ b/src/buildstream/element.py
@@ -503,10 +503,6 @@ class Element(Plugin):
Raises:
:class:`.LoadError`: When *member_name* is not found and no *default* was provided
- This is essentially the same as :func:`~buildstream.plugin.Plugin.node_get_member`
- except that it assumes the expected type is a string and will also perform variable
- substitutions.
-
**Example:**
.. code:: python
@@ -535,9 +531,6 @@ class Element(Plugin):
Raises:
:class:`.LoadError`
- This is essentially the same as :func:`~buildstream.plugin.Plugin.node_get_member`
- except that it assumes the expected type is a list of strings and will also
- perform variable substitutions.
"""
value = self.node_get_member(node, list, member_name)
ret = []
diff --git a/src/buildstream/plugin.py b/src/buildstream/plugin.py
index 9b18e35c5..f2bd90b35 100644
--- a/src/buildstream/plugin.py
+++ b/src/buildstream/plugin.py
@@ -280,12 +280,7 @@ class Plugin():
Plugin implementors should implement this method to read configuration
data and store it.
- Plugins should use the :func:`Plugin.node_get_member() <buildstream.plugin.Plugin.node_get_member>`
- method to fetch values from the passed `node`. This will ensure that a nice human readable error
- message will be raised if the expected configuration is not found, indicating the filename,
- line and column numbers.
-
- Further the :func:`Plugin.node_validate() <buildstream.plugin.Plugin.node_validate>` method
+ The :func:`Plugin.node_validate() <buildstream.plugin.Plugin.node_validate>` method
should be used to ensure that the user has not specified keys in `node` which are unsupported
by the plugin.
@@ -385,38 +380,6 @@ class Plugin():
provenance = _yaml.node_get_provenance(node, key=member_name)
return str(provenance)
- def node_get_member(self, node, expected_type, member_name, default=_yaml._sentinel, *, allow_none=False):
- """Fetch the value of a node member, raising an error if the value is
- missing or incorrectly typed.
-
- Args:
- node (Node): A dictionary loaded from YAML
- expected_type (type): The expected type of the node member
- member_name (str): The name of the member to fetch
- default (expected_type): A value to return when *member_name* is not specified in *node*
- allow_none (bool): Allow explicitly set None values in the YAML (*Since: 1.4*)
-
- Returns:
- The value of *member_name* in *node*, otherwise *default*
-
- Raises:
- :class:`.LoadError`: When *member_name* is not found and no *default* was provided
-
- Note:
- Returned strings are stripped of leading and trailing whitespace
-
- **Example:**
-
- .. code:: python
-
- # Expect a string 'name' in 'node'
- name = self.node_get_member(node, str, 'name')
-
- # Fetch an optional integer
- level = self.node_get_member(node, int, 'level', -1)
- """
- return _yaml.node_get(node, expected_type, member_name, default_value=default, allow_none=allow_none)
-
def node_set_member(self, node, key, value):
"""Set the value of a node member
Args:
diff --git a/src/buildstream/plugins/sources/bzr.py b/src/buildstream/plugins/sources/bzr.py
index 082d11dec..28bea1415 100644
--- a/src/buildstream/plugins/sources/bzr.py
+++ b/src/buildstream/plugins/sources/bzr.py
@@ -93,7 +93,7 @@ class BzrSource(Source):
return Consistency.RESOLVED
def load_ref(self, node):
- self.ref = self.node_get_member(node, str, 'ref', None)
+ self.ref = node.get_str('ref', None)
def get_ref(self):
return self.ref
diff --git a/src/buildstream/plugins/sources/pip.py b/src/buildstream/plugins/sources/pip.py
index db0537497..816b9e95b 100644
--- a/src/buildstream/plugins/sources/pip.py
+++ b/src/buildstream/plugins/sources/pip.py
@@ -150,7 +150,7 @@ class PipSource(Source):
return self.ref
def load_ref(self, node):
- self.ref = self.node_get_member(node, str, 'ref', None)
+ self.ref = node.get_str('ref', None)
def set_ref(self, ref, node):
node['ref'] = self.ref = ref