diff options
author | Benjamin Schubert <contact@benschubert.me> | 2019-10-15 14:17:19 +0100 |
---|---|---|
committer | Benjamin Schubert <contact@benschubert.me> | 2019-10-16 13:58:57 +0100 |
commit | 1a7582c45a9bd265b8da429fde145b115a50fac0 (patch) | |
tree | 9990eef5524a5640e027275e5735ca79600c8471 | |
parent | abc522cd6a292ef571cafb1b4d4288903690d730 (diff) | |
download | buildstream-1a7582c45a9bd265b8da429fde145b115a50fac0.tar.gz |
node.pyx: Make 'strip_node_info' public
'strip_node_info' would be useful for multiple plugins. We should
therefore allow users to use it.
-rw-r--r-- | src/buildstream/_workspaces.py | 2 | ||||
-rw-r--r-- | src/buildstream/element.py | 2 | ||||
-rw-r--r-- | src/buildstream/node.pxd | 2 | ||||
-rw-r--r-- | src/buildstream/node.pyx | 42 | ||||
-rw-r--r-- | src/buildstream/sandbox/_sandboxremote.py | 2 | ||||
-rw-r--r-- | src/buildstream/source.py | 4 | ||||
-rw-r--r-- | tests/artifactcache/junctions.py | 2 | ||||
-rw-r--r-- | tests/frontend/workspace.py | 6 |
8 files changed, 31 insertions, 31 deletions
diff --git a/src/buildstream/_workspaces.py b/src/buildstream/_workspaces.py index a16c840e5..f9023dc54 100644 --- a/src/buildstream/_workspaces.py +++ b/src/buildstream/_workspaces.py @@ -630,7 +630,7 @@ class Workspaces(): def _load_workspace(self, node): running_files = node.get_mapping('running_files', default=None) if running_files: - running_files = running_files._strip_node_info() + running_files = running_files.strip_node_info() dictionary = { 'prepared': node.get_bool('prepared', default=False), diff --git a/src/buildstream/element.py b/src/buildstream/element.py index 870e49e19..65b87e631 100644 --- a/src/buildstream/element.py +++ b/src/buildstream/element.py @@ -2170,7 +2170,7 @@ class Element(Plugin): 'element-plugin-version': self.BST_ARTIFACT_VERSION, 'sandbox': self.__sandbox_config.get_unique_key(), 'environment': cache_env, - 'public': self.__public._strip_node_info() + 'public': self.__public.strip_node_info() } def __get_source_entry(_source): diff --git a/src/buildstream/node.pxd b/src/buildstream/node.pxd index f2244a18f..47f46bbdf 100644 --- a/src/buildstream/node.pxd +++ b/src/buildstream/node.pxd @@ -29,10 +29,10 @@ cdef class Node: # Public Methods cpdef Node clone(self) cpdef ProvenanceInformation get_provenance(self) + cpdef object strip_node_info(self) # Private Methods used in BuildStream cpdef void _assert_fully_composited(self) except * - cpdef object _strip_node_info(self) # Protected Methods cdef void _compose_on(self, str key, MappingNode target, list path) except * diff --git a/src/buildstream/node.pyx b/src/buildstream/node.pyx index 89bb18eaf..bf6ce3a32 100644 --- a/src/buildstream/node.pyx +++ b/src/buildstream/node.pyx @@ -97,6 +97,14 @@ cdef class Node: """ raise NotImplementedError() + cpdef object strip_node_info(self): + """ Remove all the node information (provenance) and return the underlying data as plain python objects + + Returns: + (list, dict, str, None): the underlying data that was held in the node structure. + """ + raise NotImplementedError() + ############################################################# # Public Methods # ############################################################# @@ -176,14 +184,6 @@ cdef class Node: cpdef void _assert_fully_composited(self) except *: raise NotImplementedError() - # _strip_node_info() - # - # Remove all the node information (provenance) and return - # the underlying data as plain python objects (list, dict, str, None) - # - cpdef object _strip_node_info(self): - raise NotImplementedError() - ############################################################# # Abstract Protected Methods # ############################################################# @@ -414,6 +414,9 @@ cdef class ScalarNode(Node): cpdef ScalarNode clone(self): return self + cpdef object strip_node_info(self): + return self.value + ############################################################# # Private Methods implementations # ############################################################# @@ -421,9 +424,6 @@ cdef class ScalarNode(Node): cpdef void _assert_fully_composited(self) except *: pass - cpdef object _strip_node_info(self): - return self.value - ############################################################# # Protected Methods # ############################################################# @@ -870,6 +870,12 @@ cdef class MappingNode(Node): return MappingNode.__new__(MappingNode, self.file_index, self.line, self.column, copy) + cpdef object strip_node_info(self): + cdef str key + cdef Node value + + return {key: value.strip_node_info() for key, value in self.value.items()} + ############################################################# # Private Methods used in BuildStream # ############################################################# @@ -949,12 +955,6 @@ cdef class MappingNode(Node): value._assert_fully_composited() - cpdef object _strip_node_info(self): - cdef str key - cdef Node value - - return {key: value._strip_node_info() for key, value in self.value.items()} - ############################################################# # Protected Methods # ############################################################# @@ -1371,6 +1371,10 @@ cdef class SequenceNode(Node): return SequenceNode.__new__(SequenceNode, self.file_index, self.line, self.column, copy) + cpdef object strip_node_info(self): + cdef Node value + return [value.strip_node_info() for value in self.value] + ############################################################# # Private Methods implementations # ############################################################# @@ -1380,10 +1384,6 @@ cdef class SequenceNode(Node): for value in self.value: value._assert_fully_composited() - cpdef object _strip_node_info(self): - cdef Node value - return [value._strip_node_info() for value in self.value] - ############################################################# # Protected Methods # ############################################################# diff --git a/src/buildstream/sandbox/_sandboxremote.py b/src/buildstream/sandbox/_sandboxremote.py index 678b11c32..77bb34fa9 100644 --- a/src/buildstream/sandbox/_sandboxremote.py +++ b/src/buildstream/sandbox/_sandboxremote.py @@ -175,7 +175,7 @@ class SandboxRemote(Sandbox): config[tls_key] = resolve_path(config.get_str(tls_key)) # TODO: we should probably not be stripping node info and rather load files the safe way - return RemoteExecutionSpec(*[conf._strip_node_info() for conf in service_configs]) + return RemoteExecutionSpec(*[conf.strip_node_info() for conf in service_configs]) def run_remote_command(self, channel, action_digest): # Sends an execution request to the remote execution server. diff --git a/src/buildstream/source.py b/src/buildstream/source.py index 1fb318b52..7fc2e9fc0 100644 --- a/src/buildstream/source.py +++ b/src/buildstream/source.py @@ -918,8 +918,8 @@ class Source(Plugin): # Step 2 - Set the ref in memory, and determine changed state # # TODO: we are working on dictionaries here, would be nicer to just work on the nodes themselves - clean = node._strip_node_info() - to_modify = node._strip_node_info() + clean = node.strip_node_info() + to_modify = node.strip_node_info() current_ref = self.get_ref() # pylint: disable=assignment-from-no-return diff --git a/tests/artifactcache/junctions.py b/tests/artifactcache/junctions.py index 1fafb11f1..dab69ea8d 100644 --- a/tests/artifactcache/junctions.py +++ b/tests/artifactcache/junctions.py @@ -24,7 +24,7 @@ def project_set_artifacts(project, url): 'url': url, 'push': True } - _yaml.roundtrip_dump(project_config._strip_node_info(), file=project_conf_file) + _yaml.roundtrip_dump(project_config.strip_node_info(), file=project_conf_file) @pytest.mark.datafiles(DATA_DIR) diff --git a/tests/frontend/workspace.py b/tests/frontend/workspace.py index 2006fe7f4..dc9f38540 100644 --- a/tests/frontend/workspace.py +++ b/tests/frontend/workspace.py @@ -950,7 +950,7 @@ def test_list_supported_workspace(cli, tmpdir, datafiles, workspace_cfg, expecte def parse_dict_as_yaml(node): tempfile = os.path.join(str(tmpdir), 'yaml_dump') _yaml.roundtrip_dump(node, tempfile) - return _yaml.load(tempfile)._strip_node_info() + return _yaml.load(tempfile).strip_node_info() project = str(datafiles) os.makedirs(os.path.join(project, '.bst')) @@ -962,7 +962,7 @@ def test_list_supported_workspace(cli, tmpdir, datafiles, workspace_cfg, expecte result = cli.run(project=project, args=['workspace', 'list']) result.assert_success() - loaded_config = _yaml.load(workspace_config_path)._strip_node_info() + loaded_config = _yaml.load(workspace_config_path).strip_node_info() # Check that workspace config remains the same if no modifications # to workspaces were made @@ -997,7 +997,7 @@ def test_list_supported_workspace(cli, tmpdir, datafiles, workspace_cfg, expecte result.assert_success() # Check that workspace config is converted correctly if necessary - loaded_config = _yaml.load(workspace_config_path)._strip_node_info() + loaded_config = _yaml.load(workspace_config_path).strip_node_info() assert loaded_config == parse_dict_as_yaml(expected) |