diff options
-rw-r--r-- | NEWS | 3 | ||||
-rw-r--r-- | src/buildstream/_yaml.pxd | 2 | ||||
-rw-r--r-- | src/buildstream/_yaml.pyx | 32 | ||||
-rw-r--r-- | src/buildstream/element.py | 2 | ||||
-rw-r--r-- | src/buildstream/plugin.py | 6 |
5 files changed, 22 insertions, 23 deletions
@@ -2,6 +2,9 @@ buildstream 1.3.1 ================= + o BREAKING CHANGE: `Plugin.node_items` doesn't accept 'dict' values anymore. + Please used `Node`s instead. + o BREAKING CHANGE: `node_get_member` doesn't accept 'expected_type=Mapping' anymore. Please use 'expected_type=dict' instead. diff --git a/src/buildstream/_yaml.pxd b/src/buildstream/_yaml.pxd index 6a12fa7b3..b6043e5a8 100644 --- a/src/buildstream/_yaml.pxd +++ b/src/buildstream/_yaml.pxd @@ -41,5 +41,5 @@ cdef class ProvenanceInformation: cpdef object node_get(Node node, object expected_type, str key, list indices=*, object default_value=*, bint allow_none=*) cpdef void node_validate(Node node, list valid_keys) except * cpdef void node_set(Node node, object key, object value, list indices=*) except * -cpdef list node_keys(object node) +cpdef list node_keys(Node 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 f14b55e51..edad3fbee 100644 --- a/src/buildstream/_yaml.pyx +++ b/src/buildstream/_yaml.pyx @@ -596,9 +596,9 @@ cpdef object node_get(Node node, object expected_type, str key, list indices=Non cdef list __trim_list_provenance(list value): cdef list ret = [] + cdef Node entry + for entry in value: - if type(entry) is not Node: - entry = Node(entry, _SYNTHETIC_FILE_INDEX, 0, 0) if type(entry.value) is list: ret.append(__trim_list_provenance(entry.value)) elif type(entry.value) is dict: @@ -624,6 +624,9 @@ cdef list __trim_list_provenance(list value): cpdef void node_set(Node node, object key, object value, list indices=None) except *: cdef int idx + if type(value) is list: + value = __new_node_from_list(value) + if indices: node = <Node> (<dict> node.value)[key] key = indices.pop() @@ -693,21 +696,17 @@ def node_extend_list(Node node, str key, Py_ssize_t length, object default): # tuples in a dictionary loaded from project YAML. # # Args: -# node (dict): The dictionary node +# node (Node): The dictionary node # # Yields: # (str): The key name # (anything): The value for the key # -def node_items(node): - if type(node) is not Node: - node = Node(node, _SYNTHETIC_FILE_INDEX, 0, 0) - +def node_items(Node node): cdef str key + cdef Node value for key, value in node.value.items(): - if type(value) is not Node: - value = Node(value, _SYNTHETIC_FILE_INDEX, 0, 0) if type(value.value) is dict: yield (key, value) elif type(value.value) is list: @@ -722,15 +721,13 @@ def node_items(node): # in a dictionary loaded from project YAML. # # Args: -# node (dict): The dictionary node +# node (Node): The dictionary node # # Yields: # (str): The key name # -cpdef list node_keys(object node): - if type(node) is Node: - return list((<Node> node).value.keys()) - return list(node.keys()) +cpdef list node_keys(Node node): + return list(node.value.keys()) # node_del() @@ -1182,11 +1179,10 @@ cpdef Node node_copy(Node source): # Internal function to help node_copy() but for lists. cdef Node _list_copy(Node source): cdef list copy = [] + cdef Node item + for item in source.value: - if type(item) is Node: - item_type = type(item.value) - else: - item_type = type(item) + item_type = type(item.value) if item_type is dict: copy.append(node_copy(item)) diff --git a/src/buildstream/element.py b/src/buildstream/element.py index 84c8f20ff..a60546084 100644 --- a/src/buildstream/element.py +++ b/src/buildstream/element.py @@ -1986,7 +1986,7 @@ class Element(Plugin): flags |= SandboxFlags.NETWORK_ENABLED | SandboxFlags.INHERIT_UID # Apply project defined environment vars to set for a shell - for key, value in _yaml.node_items(shell_environment): + for key, value in shell_environment.items(): environment[key] = value # Setup any requested bind mounts diff --git a/src/buildstream/plugin.py b/src/buildstream/plugin.py index d8b6a7359..a12ff61ec 100644 --- a/src/buildstream/plugin.py +++ b/src/buildstream/plugin.py @@ -358,7 +358,7 @@ class Plugin(): """Iterate over a dictionary loaded from YAML Args: - node (dict): The YAML loaded dictionary object + node (Node): The YAML loaded dictionary object Returns: list: List of key/value tuples to iterate over @@ -378,7 +378,7 @@ class Plugin(): for reporting an error or warning. Args: - node (dict): The YAML loaded dictionary object + node (Node): The YAML loaded dictionary object member_name (str): The name of the member to check, or None for the node itself Returns: @@ -392,7 +392,7 @@ class Plugin(): missing or incorrectly typed. Args: - node (dict): A dictionary loaded from YAML + node (Node): A dictionary loaded from YAML expected_type (type): The expected type of the node member member_name (str): The name of the member to fetch default (expected_type): A value to return when *member_name* is not specified in *node* |