summaryrefslogtreecommitdiff
path: root/src
diff options
context:
space:
mode:
authorBenjamin Schubert <ben.c.schubert@gmail.com>2019-07-03 12:20:27 +0100
committerbst-marge-bot <marge-bot@buildstream.build>2019-07-15 14:14:03 +0000
commitd8466183f77c75bbd7ad27c7cbf5e58189945be1 (patch)
tree3ab6c9fa8f02ce355b0543608fafcd5fa4b5db28 /src
parent9e801b5e1c19c46de8b1e88f416e34e180df83e9 (diff)
downloadbuildstream-d8466183f77c75bbd7ad27c7cbf5e58189945be1.tar.gz
_yaml: Create 'from_dict' on Node and remove node creation methods
Using 'Node.from_dict({})' can replace new_empty_node, and the rest is not needed anymore. - Adapt all call sites
Diffstat (limited to 'src')
-rw-r--r--src/buildstream/_context.py2
-rw-r--r--src/buildstream/_loader/loader.py2
-rw-r--r--src/buildstream/_loader/metaelement.py10
-rw-r--r--src/buildstream/_projectrefs.py2
-rw-r--r--src/buildstream/_yaml.pyx26
-rw-r--r--src/buildstream/element.py4
-rw-r--r--src/buildstream/plugin.py20
-rw-r--r--src/buildstream/sandbox/_sandboxremote.py2
8 files changed, 16 insertions, 52 deletions
diff --git a/src/buildstream/_context.py b/src/buildstream/_context.py
index 6977565f2..aa5867bd5 100644
--- a/src/buildstream/_context.py
+++ b/src/buildstream/_context.py
@@ -154,7 +154,7 @@ class Context():
self._artifactcache = None
self._sourcecache = None
self._projects = []
- self._project_overrides = _yaml.new_empty_node()
+ self._project_overrides = _yaml.Node.from_dict({})
self._workspaces = None
self._workspace_project_cache = WorkspaceProjectCache()
self._cascache = None
diff --git a/src/buildstream/_loader/loader.py b/src/buildstream/_loader/loader.py
index 750df40c9..e45381fbf 100644
--- a/src/buildstream/_loader/loader.py
+++ b/src/buildstream/_loader/loader.py
@@ -120,7 +120,7 @@ class Loader():
# Set up a dummy element that depends on all top-level targets
# to resolve potential circular dependencies between them
- dummy_target = LoadElement(_yaml.new_empty_node(), "", self)
+ dummy_target = LoadElement(_yaml.Node.from_dict({}), "", self)
dummy_target.dependencies.extend(
LoadElement.Dependency(element, Symbol.RUNTIME)
for element in target_elements
diff --git a/src/buildstream/_loader/metaelement.py b/src/buildstream/_loader/metaelement.py
index 45eb6f4d0..8214e303d 100644
--- a/src/buildstream/_loader/metaelement.py
+++ b/src/buildstream/_loader/metaelement.py
@@ -48,12 +48,12 @@ class MetaElement():
self.kind = kind
self.provenance = provenance
self.sources = sources
- self.config = config or _yaml.new_empty_node()
- self.variables = variables or _yaml.new_empty_node()
- self.environment = environment or _yaml.new_empty_node()
+ self.config = config or _yaml.Node.from_dict({})
+ self.variables = variables or _yaml.Node.from_dict({})
+ self.environment = environment or _yaml.Node.from_dict({})
self.env_nocache = env_nocache or []
- self.public = public or _yaml.new_empty_node()
- self.sandbox = sandbox or _yaml.new_empty_node()
+ self.public = public or _yaml.Node.from_dict({})
+ self.sandbox = sandbox or _yaml.Node.from_dict({})
self.build_dependencies = []
self.dependencies = []
self.first_pass = first_pass
diff --git a/src/buildstream/_projectrefs.py b/src/buildstream/_projectrefs.py
index c3e669c81..a46765250 100644
--- a/src/buildstream/_projectrefs.py
+++ b/src/buildstream/_projectrefs.py
@@ -87,7 +87,7 @@ class ProjectRefs():
# Ensure we create our toplevel entry point on the fly here
for node in [self._toplevel_node, self._toplevel_save]:
if 'projects' not in node:
- node['projects'] = _yaml.new_empty_node(ref_node=node)
+ node['projects'] = {}
# lookup_ref()
#
diff --git a/src/buildstream/_yaml.pyx b/src/buildstream/_yaml.pyx
index d89ba74cb..07209aa1f 100644
--- a/src/buildstream/_yaml.pyx
+++ b/src/buildstream/_yaml.pyx
@@ -71,7 +71,11 @@ cdef class Node:
@classmethod
def from_dict(cls, dict value):
- return _new_node_from_dict(value, Node(None, _SYNTHETIC_FILE_INDEX, 0, next_synthetic_counter()))
+ if value:
+ return _new_node_from_dict(value, Node(None, _SYNTHETIC_FILE_INDEX, 0, next_synthetic_counter()))
+ else:
+ # We got an empty dict, we can shortcut
+ return MappingNode({}, _SYNTHETIC_FILE_INDEX, 0, next_synthetic_counter())
cdef bint _walk_find(self, Node target, list path) except *:
raise NotImplementedError()
@@ -1134,26 +1138,6 @@ def new_synthetic_file(str filename, object project=None):
return node
-# new_empty_node()
-#
-# Args:
-# ref_node (Node): Optional node whose provenance should be referenced
-#
-# Returns
-# (Node): A new empty YAML mapping node
-#
-def new_empty_node(Node ref_node=None):
- if ref_node is not None:
- return MappingNode({}, ref_node.file_index, ref_node.line, next_synthetic_counter())
- else:
- return MappingNode({}, _SYNTHETIC_FILE_INDEX, 0, 0)
-
-
-# FIXME: we should never need that
-def new_empty_list_node():
- return SequenceNode([], _SYNTHETIC_FILE_INDEX, 0, 0)
-
-
# new_node_from_dict()
#
# Args:
diff --git a/src/buildstream/element.py b/src/buildstream/element.py
index 7fb883cf4..39900cffc 100644
--- a/src/buildstream/element.py
+++ b/src/buildstream/element.py
@@ -2510,7 +2510,7 @@ class Element(Plugin):
# Defaults are loaded once per class and then reused
#
if cls.__defaults is None:
- defaults = _yaml.new_empty_node()
+ defaults = _yaml.Node.from_dict({})
if plugin_conf is not None:
# Load the plugin's accompanying .yaml file if one was provided
@@ -2545,7 +2545,7 @@ class Element(Plugin):
default_env = cls.__defaults.get_mapping("environment", default={})
if meta.is_junction:
- environment = _yaml.new_empty_node()
+ environment = _yaml.Node.from_dict({})
else:
environment = project.base_environment.copy()
diff --git a/src/buildstream/plugin.py b/src/buildstream/plugin.py
index fb0516ed2..a6f92ea41 100644
--- a/src/buildstream/plugin.py
+++ b/src/buildstream/plugin.py
@@ -363,26 +363,6 @@ class Plugin():
provenance = _yaml.node_get_provenance(node, key=member_name)
return str(provenance)
- def new_empty_node(self):
- """Create an empty 'Node' object to be handled by BuildStream's core
- Args:
- None
-
- Returns:
- Node: An empty Node object
-
- Raises:
- None
-
- **Example:**
-
- .. code:: python
-
- # Create an empty Node object to store metadata information
- metadata = self.new_empty_node()
- """
- return _yaml.new_empty_node()
-
def node_get_project_path(self, node, key, *,
check_is_file=False, check_is_dir=False):
"""Fetches a project path from a dictionary node and validates it
diff --git a/src/buildstream/sandbox/_sandboxremote.py b/src/buildstream/sandbox/_sandboxremote.py
index e7673f855..d0e641e56 100644
--- a/src/buildstream/sandbox/_sandboxremote.py
+++ b/src/buildstream/sandbox/_sandboxremote.py
@@ -144,7 +144,7 @@ class SandboxRemote(Sandbox):
# 'url' was the only valid key for remote-execution:
if 'url' in remote_config:
if 'execution-service' not in remote_config:
- exec_config = _yaml.new_node_from_dict({'url': remote_config['url']})
+ exec_config = _yaml.Node.from_dict({'url': remote_config['url']})
else:
provenance = _yaml.node_get_provenance(remote_config, key='url')
raise _yaml.LoadError(_yaml.LoadErrorReason.INVALID_DATA,