You are viewing a plain text version of this content. The canonical link for it is here.
Posted to commits@buildstream.apache.org by no...@apache.org on 2020/12/29 12:34:28 UTC

[buildstream] 07/10: node.pyx: Make 'strip_node_info' public

This is an automated email from the ASF dual-hosted git repository.

not-in-ldap pushed a commit to branch bschubert/more-mypy
in repository https://gitbox.apache.org/repos/asf/buildstream.git

commit c8ecc1eb2d99d8e3b671714a43431d2b4f572adf
Author: Benjamin Schubert <co...@benschubert.me>
AuthorDate: Tue Oct 15 14:17:19 2019 +0100

    node.pyx: Make 'strip_node_info' public
    
    'strip_node_info' would be useful for multiple plugins. We should
    therefore allow users to use it.
---
 src/buildstream/_workspaces.py            |  2 +-
 src/buildstream/element.py                |  2 +-
 src/buildstream/node.pxd                  |  2 +-
 src/buildstream/node.pyx                  | 26 +++++++++++++-------------
 src/buildstream/sandbox/_sandboxremote.py |  2 +-
 tests/artifactcache/junctions.py          |  2 +-
 tests/frontend/workspace.py               |  6 +++---
 7 files changed, 21 insertions(+), 21 deletions(-)

diff --git a/src/buildstream/_workspaces.py b/src/buildstream/_workspaces.py
index a16c840..f9023dc 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 5230557..18e2aec 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 f2244a1..47f46bb 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 89bb18e..0c47c29 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): 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                 #
     #############################################################
@@ -421,7 +421,7 @@ cdef class ScalarNode(Node):
     cpdef void _assert_fully_composited(self) except *:
         pass
 
-    cpdef object _strip_node_info(self):
+    cpdef object strip_node_info(self):
         return self.value
 
     #############################################################
@@ -949,11 +949,11 @@ cdef class MappingNode(Node):
 
             value._assert_fully_composited()
 
-    cpdef object _strip_node_info(self):
+    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()}
+        return {key: value.strip_node_info() for key, value in self.value.items()}
 
     #############################################################
     #                     Protected Methods                     #
@@ -1380,9 +1380,9 @@ cdef class SequenceNode(Node):
         for value in self.value:
             value._assert_fully_composited()
 
-    cpdef object _strip_node_info(self):
+    cpdef object strip_node_info(self):
         cdef Node value
-        return [value._strip_node_info() for value in self.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 678b11c..77bb34f 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/tests/artifactcache/junctions.py b/tests/artifactcache/junctions.py
index 1fafb11..dab69ea 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 2006fe7..dc9f385 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)