summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorDaniel Silverstone <daniel.silverstone@codethink.co.uk>2018-10-26 11:09:43 +0100
committerDaniel Silverstone <daniel.silverstone@codethink.co.uk>2018-10-26 11:09:43 +0100
commit08849af4d47dba1a04f6cb8c472a62b9297726bb (patch)
tree00baf1b3ef28d79f7d63c28ac6a947818cf43225
parent494d7018ec16f90bb917b3fe0cbbc4d8893febec (diff)
downloadbuildstream-danielsilverstone-ct/yaml-sentinel-rework.tar.gz
various: Move _sentinel from utils.py to _yaml.pydanielsilverstone-ct/yaml-sentinel-rework
The `_sentinel` in `utils.py` was used only for yaml node tracking. As such, simplify matters by removing it from `utils.py` and move it to `_yaml.py` which means that we no longer need to try and avoid a circular import issue by means of runtime importing. Signed-off-by: Daniel Silverstone <daniel.silverstone@codethink.co.uk>
-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()