From f069d82fd7520caac9e97b10fb89cc39601fd99e Mon Sep 17 00:00:00 2001 From: Daniel Silverstone Date: Fri, 26 Oct 2018 11:09:43 +0100 Subject: various: Move _sentinel from utils.py to _yaml.py 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 --- buildstream/_yaml.py | 17 +++++------------ buildstream/element.py | 2 +- buildstream/plugin.py | 2 +- buildstream/utils.py | 4 ---- 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() -- cgit v1.2.1