diff options
author | Benjamin Schubert <ben.c.schubert@gmail.com> | 2019-05-30 14:28:08 +0100 |
---|---|---|
committer | Benjamin Schubert <ben.c.schubert@gmail.com> | 2019-05-31 15:20:10 +0100 |
commit | 3dea2a9cf66813ad351e1055d1bccdc1d11c8399 (patch) | |
tree | 08604149ce8cd46781d134e7372d1a00cf972092 | |
parent | 40b606aac952b473d6f221aa0cad5a474b1088ac (diff) | |
download | buildstream-3dea2a9cf66813ad351e1055d1bccdc1d11c8399.tar.gz |
_loader/types.py: Cythonize and import yaml from C
- _yaml: export two other functions used from types.py that weren't
exposed as part of the C Api yet
- Cythonize types.py and import Yaml from C.
-rwxr-xr-x | setup.py | 1 | ||||
-rw-r--r-- | src/buildstream/_loader/types.pyx (renamed from src/buildstream/_loader/types.py) | 6 | ||||
-rw-r--r-- | src/buildstream/_yaml.pxd | 2 | ||||
-rw-r--r-- | src/buildstream/_yaml.pyx | 4 |
4 files changed, 8 insertions, 5 deletions
@@ -393,6 +393,7 @@ def register_cython_module(module_name, dependencies=None): BUILD_EXTENSIONS = [] +register_cython_module("buildstream._loader.types", dependencies=["buildstream._yaml"]) register_cython_module("buildstream._yaml") register_cython_module("buildstream._variables", dependencies=["buildstream._yaml"]) diff --git a/src/buildstream/_loader/types.py b/src/buildstream/_loader/types.pyx index f9dd38ca0..e8aa59c99 100644 --- a/src/buildstream/_loader/types.py +++ b/src/buildstream/_loader/types.pyx @@ -18,7 +18,7 @@ # Tristan Van Berkom <tristan.vanberkom@codethink.co.uk> from .._exceptions import LoadError, LoadErrorReason -from .. import _yaml +from .. cimport _yaml # Symbol(): @@ -75,7 +75,7 @@ class Dependency(): _yaml.node_validate(dep, ['filename', 'type', 'junction']) # Make type optional, for this we set it to None - dep_type = _yaml.node_get(dep, str, Symbol.TYPE, default_value=None) + dep_type = _yaml.node_get(dep, str, Symbol.TYPE, None, None) if dep_type is None or dep_type == Symbol.ALL: dep_type = None elif dep_type not in [Symbol.BUILD, Symbol.RUNTIME]: @@ -86,7 +86,7 @@ class Dependency(): self.name = _yaml.node_get(dep, str, Symbol.FILENAME) self.dep_type = dep_type - self.junction = _yaml.node_get(dep, str, Symbol.JUNCTION, default_value=None) + self.junction = _yaml.node_get(dep, str, Symbol.JUNCTION, None, None) else: raise LoadError(LoadErrorReason.INVALID_DATA, diff --git a/src/buildstream/_yaml.pxd b/src/buildstream/_yaml.pxd index 27a1a888e..640563318 100644 --- a/src/buildstream/_yaml.pxd +++ b/src/buildstream/_yaml.pxd @@ -38,7 +38,9 @@ cdef class ProvenanceInformation: cdef public bint is_synthetic +cpdef bint is_node(object maybenode) 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=*) +cpdef void node_validate(Node node, list valid_keys) except * diff --git a/src/buildstream/_yaml.pyx b/src/buildstream/_yaml.pyx index 9ff7e3d0c..06d9054d4 100644 --- a/src/buildstream/_yaml.pyx +++ b/src/buildstream/_yaml.pyx @@ -763,7 +763,7 @@ def node_del(Node node, str key, bint safe=False): # Returns: # (bool): Whether or not maybenode was a Node # -def is_node(maybenode): +cpdef bint is_node(object maybenode): # It's a programming error to give this a Node which isn't a mapping # so assert that. assert (type(maybenode) is not Node) or (type(maybenode.value) is dict) @@ -1119,7 +1119,7 @@ cpdef object node_sanitize(object node, object dict_type=OrderedDict): # LoadError: In the case that the specified node contained # one or more invalid keys # -def node_validate(Node node, list valid_keys): +cpdef void node_validate(Node node, list valid_keys) except *: # Probably the fastest way to do this: https://stackoverflow.com/a/23062482 cdef set valid_keys_set = set(valid_keys) |