summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorJames Ennis <james.ennis@codethink.com>2018-10-26 13:12:12 +0000
committerJames Ennis <james.ennis@codethink.com>2018-10-26 13:12:12 +0000
commit283887a512285bbf118761c147bd55fdb29a9a70 (patch)
tree97527636fe178055622b2a695b92dd83a93433f2
parent1eb993bf32e30c7a63870a5c358d36e141d13b7a (diff)
parentf069d82fd7520caac9e97b10fb89cc39601fd99e (diff)
downloadbuildstream-283887a512285bbf118761c147bd55fdb29a9a70.tar.gz
Merge branch 'danielsilverstone-ct/yaml-sentinel-rework' into 'master'
Move _sentinel from utils.py to _yaml.py See merge request BuildStream/buildstream!903
-rw-r--r--buildstream/_yaml.py17
-rw-r--r--buildstream/element.py2
-rw-r--r--buildstream/plugin.py2
-rw-r--r--buildstream/utils.py4
4 files changed, 7 insertions, 18 deletions
diff --git a/buildstream/_yaml.py b/buildstream/_yaml.py
index 940ca81e5..ca12acae9 100644
--- a/buildstream/_yaml.py
+++ b/buildstream/_yaml.py
@@ -335,16 +335,9 @@ def node_get_provenance(node, key=None, indices=None):
return provenance
-# Helper to use utils.sentinel without unconditional utils import,
-# which causes issues for completion.
-#
-# Local private, but defined here because sphinx appears to break if
-# it's not defined before any functions calling it in default kwarg
-# values.
-#
-def _get_sentinel():
- from .utils import _sentinel
- return _sentinel
+# A sentinel to be used as a default argument for functions that need
+# to distinguish between a kwarg set to None and an unset kwarg.
+_sentinel = object()
# node_get()
@@ -368,10 +361,10 @@ def _get_sentinel():
# Note:
# Returned strings are stripped of leading and trailing whitespace
#
-def node_get(node, expected_type, key, indices=None, default_value=_get_sentinel()):
+def node_get(node, expected_type, key, indices=None, default_value=_sentinel):
value = node.get(key, default_value)
provenance = node_get_provenance(node)
- if value is _get_sentinel():
+ if value is _sentinel:
raise LoadError(LoadErrorReason.INVALID_DATA,
"{}: Dictionary did not contain expected key '{}'".format(provenance, key))
diff --git a/buildstream/element.py b/buildstream/element.py
index 6536d2582..4d3e1bc75 100644
--- a/buildstream/element.py
+++ b/buildstream/element.py
@@ -451,7 +451,7 @@ class Element(Plugin):
return None
- def node_subst_member(self, node, member_name, default=utils._sentinel):
+ def node_subst_member(self, node, member_name, default=_yaml._sentinel):
"""Fetch the value of a string node member, substituting any variables
in the loaded value with the element contextual variables.
diff --git a/buildstream/plugin.py b/buildstream/plugin.py
index 9c5c0d8ca..1b021d4b4 100644
--- a/buildstream/plugin.py
+++ b/buildstream/plugin.py
@@ -321,7 +321,7 @@ 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=utils._sentinel):
+ def node_get_member(self, node, expected_type, member_name, default=_yaml._sentinel):
"""Fetch the value of a node member, raising an error if the value is
missing or incorrectly typed.
diff --git a/buildstream/utils.py b/buildstream/utils.py
index 0bddb287d..c116797bd 100644
--- a/buildstream/utils.py
+++ b/buildstream/utils.py
@@ -654,10 +654,6 @@ def _pretty_size(size, dec_places=0):
return "{size:g}{unit}".format(size=round(psize, dec_places), unit=unit)
-# A sentinel to be used as a default argument for functions that need
-# to distinguish between a kwarg set to None and an unset kwarg.
-_sentinel = object()
-
# Main process pid
_main_pid = os.getpid()