def load_from_layer_data(cls, layer_data): new_layer = cls() result_nodes = {} name_attr = nxt_node.INTERNAL_ATTRS.NAME name_key = nxt_node.INTERNAL_ATTRS.as_save_key(name_attr) for node_path, node_data in layer_data.get('nodes', {}).items(): parent_path = nxt_path.get_parent_path(node_path) node_name = nxt_path.node_name_from_node_path(node_path) node_data[name_key] = node_name spec_node = nxt_node.create_spec_node(node_data, new_layer, parent_path) code_lines = getattr(spec_node, nxt_node.INTERNAL_ATTRS.COMPUTE) code = '\n'.join(code_lines) setattr(spec_node, nxt_node.INTERNAL_ATTRS.CACHED_CODE, code) result_nodes[node_path] = spec_node new_layer.nodes = result_nodes return new_layer
def _construct_node_specs(self, layer_data): self.spec_list = [] self._nodes_path_as_key = {} self._nodes_node_as_key = {} nodes = order_nodes_dict(layer_data.get(SAVE_KEY.NODES, {})) for node_path, node_data in nodes.items(): parent_path = nxt_path.get_parent_path(node_path) root_name = nxt_path.node_name_from_node_path(node_path) node_data['name'] = root_name node_data[nxt_node.INTERNAL_ATTRS.SOURCE_LAYER] = self.real_path root_spec_node = nxt_node.create_spec_node(node_data, self, parent_path=parent_path) root_parent_path = getattr(root_spec_node, nxt_node.INTERNAL_ATTRS.PARENT_PATH) root_node_path = nxt_path.join_node_paths(root_parent_path, root_name) self.spec_list += [root_spec_node] self._nodes_path_as_key[root_node_path] = root_spec_node self._nodes_node_as_key[root_spec_node] = root_node_path self.clear_node_child_cache(root_node_path)