You are viewing a plain text version of this content. The canonical link for it is here.
Posted to commits@buildstream.apache.org by gi...@apache.org on 2020/12/29 13:02:02 UTC
[buildstream] 12/27: _variables.pyx: Restructuring and removing
yellowness
This is an automated email from the ASF dual-hosted git repository.
github-bot pushed a commit to branch tristan/partial-variables-manual-string-join
in repository https://gitbox.apache.org/repos/asf/buildstream.git
commit 667da2ac3e50079e1ce5354e40cfcb142021d41d
Author: Tristan van Berkom <tr...@codethink.co.uk>
AuthorDate: Thu Jul 2 20:35:01 2020 +0900
_variables.pyx: Restructuring and removing yellowness
---
src/buildstream/_variables.pyx | 82 ++++++++++++++++++++++++++----------------
1 file changed, 52 insertions(+), 30 deletions(-)
diff --git a/src/buildstream/_variables.pyx b/src/buildstream/_variables.pyx
index 8020efe..152a8d3 100644
--- a/src/buildstream/_variables.pyx
+++ b/src/buildstream/_variables.pyx
@@ -129,7 +129,10 @@ cdef class Variables:
# the node untouched, you should use `node.clone()` beforehand
#
# Args:
- # (Node): A node for which to substitute the values
+ # (Node): A node for which to substitute the values
+ #
+ # Raises:
+ # (LoadError): if the string contains unresolved variable references.
#
cpdef expand(self, Node node):
self._expand(node)
@@ -145,23 +148,10 @@ cdef class Variables:
# (string): The new string with any substitutions made
#
# Raises:
- # LoadError, if the string contains unresolved variable references.
+ # (LoadError): if the string contains unresolved variable references.
#
- cpdef subst(self, ScalarNode node):
- cdef Value value = Value()
- cdef PyObject **dependencies
- cdef Py_ssize_t n_dependencies
- cdef Py_ssize_t idx = 0
- cdef str dep_name
-
- value.init(node)
- dependencies, n_dependencies = value.dependencies()
- while idx < n_dependencies:
- dep_name = <str> dependencies[idx]
- self._resolve(dep_name, node)
- idx += 1
-
- return value.resolve(self._values)
+ cpdef str subst(self, ScalarNode node):
+ return self._subst(node)
# check()
#
@@ -173,10 +163,11 @@ cdef class Variables:
# be raised.
#
cpdef check(self):
+ cdef object key
# Resolve all variables.
for key in self._values.keys():
- self._resolve(key, None)
+ self._resolve(<str> key, None)
# _init_values()
#
@@ -185,20 +176,47 @@ cdef class Variables:
#
cdef dict _init_values(self, MappingNode node):
cdef dict ret = {}
- cdef key_object
- cdef value_node_object
- cdef str key
- cdef ScalarNode value_node
-
- for key_object, value_object in node.items():
- key = <str> sys.intern(<str> key_object)
- value_node = <ScalarNode> value_object
+ cdef object key
+ cdef object value_node
+ cdef Value value
+
+ for key, value_node in node.items():
+ key = <object> sys.intern(<str> key)
value = Value()
- value.init(value_node)
+ value.init(<ScalarNode> value_node)
ret[key] = value
return ret
+ # _subst():
+ #
+ # Internal implementation of Variables.subst()
+ #
+ # Args:
+ # (string): The string to substitute
+ #
+ # Returns:
+ # (string): The new string with any substitutions made
+ #
+ # Raises:
+ # (LoadError): if the string contains unresolved variable references.
+ #
+ cpdef str _subst(self, ScalarNode node):
+ cdef Value value = Value()
+ cdef PyObject **dependencies
+ cdef Py_ssize_t n_dependencies
+ cdef Py_ssize_t idx = 0
+ cdef str dep_name
+
+ value.init(node)
+ dependencies, n_dependencies = value.dependencies()
+ while idx < n_dependencies:
+ dep_name = <str> dependencies[idx]
+ self._resolve(dep_name, node)
+ idx += 1
+
+ return value.resolve(self._values)
+
# _expand()
#
# Internal implementation of Variables.expand()
@@ -206,15 +224,19 @@ cdef class Variables:
# Args:
# (Node): A node for which to substitute the values
#
+ # Raises:
+ # (LoadError): if the string contains unresolved variable references.
+ #
cdef _expand(self, Node node):
+ cdef object entry
if isinstance(node, ScalarNode):
- (<ScalarNode> node).value = self.subst(node)
+ (<ScalarNode> node).value = self._subst(<ScalarNode> node)
elif isinstance(node, SequenceNode):
for entry in (<SequenceNode> node).value:
- self._expand(entry)
+ self._expand(<Node> entry)
elif isinstance(node, MappingNode):
for entry in (<MappingNode> node).value.values():
- self._expand(entry)
+ self._expand(<Node> entry)
else:
assert False, "Unknown 'Node' type"