summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorBenjamin Schubert <ben.c.schubert@gmail.com>2019-05-21 11:52:51 +0100
committerBenjamin Schubert <contact@benschubert.me>2019-05-29 19:50:18 +0100
commiteadcca3eaa921341b6c29d48c841614d9da7472a (patch)
tree112bfb4ad12dade267d7b445df4fa8c490d7bc9e
parent6901a829027a1fe0dd2002852a80a2eef0b322e4 (diff)
downloadbuildstream-eadcca3eaa921341b6c29d48c841614d9da7472a.tar.gz
_variable: Import _yaml from C.
This requires the addition of a definition file (.pxd), to list symbols exported.
-rwxr-xr-xsetup.py2
-rw-r--r--src/buildstream/_variables.pyx13
-rw-r--r--src/buildstream/_yaml.pxd44
-rw-r--r--src/buildstream/_yaml.pyx24
4 files changed, 57 insertions, 26 deletions
diff --git a/setup.py b/setup.py
index b848e2458..a57e65b56 100755
--- a/setup.py
+++ b/setup.py
@@ -392,7 +392,7 @@ def register_cython_module(module_name, dependencies=None):
BUILD_EXTENSIONS = []
register_cython_module("buildstream._yaml")
-register_cython_module("buildstream._variables")
+register_cython_module("buildstream._variables", dependencies=["buildstream._yaml"])
#####################################################
# Main setup() Invocation #
diff --git a/src/buildstream/_variables.pyx b/src/buildstream/_variables.pyx
index d99aaeb78..9b8b5a902 100644
--- a/src/buildstream/_variables.pyx
+++ b/src/buildstream/_variables.pyx
@@ -24,7 +24,7 @@ import re
import sys
from ._exceptions import LoadError, LoadErrorReason
-from . import _yaml
+from . cimport _yaml
# Variables are allowed to have dashes here
#
@@ -58,18 +58,18 @@ PARSE_EXPANSION = re.compile(r"\%\{([a-zA-Z][a-zA-Z0-9_-]*)\}")
# variable settings for the element.
#
# Args:
-# node (dict): A node loaded and composited with yaml tools
+# node (Node): A node loaded and composited with yaml tools
#
# Raises:
# LoadError, if unresolved variables, or cycles in resolution, occur.
#
cdef class Variables:
- cdef object original
+ cdef _yaml.Node original
cdef dict _expstr_map
cdef public dict flat
- def __init__(self, node):
+ def __init__(self, _yaml.Node node):
self.original = node
self._expstr_map = self._resolve(node)
self.flat = self._flatten()
@@ -115,13 +115,12 @@ cdef class Variables:
#
# Here we resolve all of our inputs into a dictionary, ready for use
# in subst()
- # FIXME: node should be a yaml Node if moved
- cdef dict _resolve(self, object node):
+ cdef dict _resolve(self, _yaml.Node node):
# Special case, if notparallel is specified in the variables for this
# element, then override max-jobs to be 1.
# Initialize it as a string as all variables are processed as strings.
#
- if _yaml.node_get(node, bool, 'notparallel', default_value=False):
+ if _yaml.node_get(node, bool, 'notparallel', None, False):
_yaml.node_set(node, 'max-jobs', str(1))
cdef dict ret = {}
diff --git a/src/buildstream/_yaml.pxd b/src/buildstream/_yaml.pxd
new file mode 100644
index 000000000..27a1a888e
--- /dev/null
+++ b/src/buildstream/_yaml.pxd
@@ -0,0 +1,44 @@
+#
+# Copyright (C) 2019 Bloomberg L.P.
+#
+# This program is free software; you can redistribute it and/or
+# modify it under the terms of the GNU Lesser General Public
+# License as published by the Free Software Foundation; either
+# version 2 of the License, or (at your option) any later version.
+#
+# This library is distributed in the hope that it will be useful,
+# but WITHOUT ANY WARRANTY; without even the implied warranty of
+# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
+# Lesser General Public License for more details.
+#
+# You should have received a copy of the GNU Lesser General Public
+# License along with this library. If not, see <http://www.gnu.org/licenses/>.
+#
+# Authors:
+# Benjamin Schubert <bschubert@bloomberg.net>
+
+# Documentation for each class and method here can be found in the adjacent
+# implementation file (_yaml.pyx)
+
+cdef class Node:
+
+ cdef public object value
+ cdef public int file_index
+ cdef public int line
+ cdef public int column
+
+
+cdef class ProvenanceInformation:
+
+ cdef public Node node
+ cdef str displayname
+ cdef public str filename, shortname
+ cdef public int col, line
+ cdef public object project, toplevel
+ cdef public bint is_synthetic
+
+
+cpdef object node_get(Node node, object expected_type, str key, list indices=*, object default_value=*, bint allow_none=*)
+cpdef void node_set(Node node, object key, object value, list indices=*) except *
+cpdef list node_keys(object node)
+cpdef ProvenanceInformation node_get_provenance(Node node, str key=*, list indices=*)
diff --git a/src/buildstream/_yaml.pyx b/src/buildstream/_yaml.pyx
index b981e1f8a..b7e0e26f8 100644
--- a/src/buildstream/_yaml.pyx
+++ b/src/buildstream/_yaml.pyx
@@ -58,11 +58,6 @@ from ._exceptions import LoadError, LoadErrorReason
#
cdef class Node:
- cdef public object value
- cdef public int file_index
- cdef public int line
- cdef public int column
-
def __init__(self, object value, int file_index, int line, int column):
self.value = value
self.file_index = file_index
@@ -112,13 +107,6 @@ _SYNTHETIC_COUNTER = count(start=-1, step=-1)
# Returned from node_get_provenance
cdef class ProvenanceInformation:
- cdef public Node node
- cdef str displayname
- cdef public str filename, shortname
- cdef public int col, line
- cdef public object project, toplevel
- cdef public bint is_synthetic
-
def __init__(self, Node nodeish):
cdef FileInfo fileinfo
@@ -519,7 +507,7 @@ _sentinel = object()
# Note:
# Returned strings are stripped of leading and trailing whitespace
#
-cpdef node_get(Node node, object expected_type, str key, list indices=None, object default_value=_sentinel, bint allow_none=False):
+cpdef object node_get(Node node, object expected_type, str key, list indices=None, object default_value=_sentinel, bint allow_none=False):
if indices is None:
if default_value is _sentinel:
value = node.value.get(key, Node(default_value, _SYNTHETIC_FILE_INDEX, 0, 0))
@@ -617,7 +605,7 @@ cdef list __trim_list_provenance(list value):
# indices: Any indices to index into the list referenced by key, like in
# `node_get` (must be a list of integers)
#
-def node_set(Node node, object key, object value, list indices=None):
+cpdef void node_set(Node node, object key, object value, list indices=None) except *:
cdef int idx
if indices:
@@ -723,10 +711,10 @@ def node_items(node):
# Yields:
# (str): The key name
#
-def node_keys(node):
- if type(node) is not Node:
- node = Node(node, _SYNTHETIC_FILE_INDEX, 0, 0)
- yield from node.value.keys()
+cpdef list node_keys(object node):
+ if type(node) is Node:
+ return list((<Node> node).value.keys())
+ return list(node.keys())
# node_del()