summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorBenjamin Schubert <ben.c.schubert@gmail.com>2019-07-05 17:00:13 +0100
committerbst-marge-bot <marge-bot@buildstream.build>2019-07-15 14:14:03 +0000
commit2b1c63b50b11293377e87df802f35489e5f86c12 (patch)
tree70cc963390b24236238a47f64cc42280781b4e72
parentd256a13599e018dd1195ee98de5f0fbd5ed5c785 (diff)
downloadbuildstream-2b1c63b50b11293377e87df802f35489e5f86c12.tar.gz
_project: remove 'key' argument from 'get_path_from_node'
Now that we have scalar nodes, we can directly give the scalar to the method. - Adapt the plugin method to also not access via the key
-rw-r--r--src/buildstream/_project.py21
-rw-r--r--src/buildstream/plugin.py7
-rw-r--r--src/buildstream/plugins/sources/local.py2
-rw-r--r--src/buildstream/plugins/sources/patch.py2
4 files changed, 18 insertions, 14 deletions
diff --git a/src/buildstream/_project.py b/src/buildstream/_project.py
index 0c80c22b9..c78cfd878 100644
--- a/src/buildstream/_project.py
+++ b/src/buildstream/_project.py
@@ -247,8 +247,7 @@ class Project():
# will always be raised if both parameters are set to ``True``.
#
# Args:
- # node (dict): A dictionary loaded from YAML
- # key (str): The key whose value contains a path to validate
+ # node (ScalarNode): A Node loaded from YAML containing the path to validate
# check_is_file (bool): If ``True`` an error will also be raised
# if path does not point to a regular file.
# Defaults to ``False``
@@ -262,21 +261,21 @@ class Project():
# (LoadError): In case that the project path is not valid or does not
# exist
#
- def get_path_from_node(self, node, key, *,
+ def get_path_from_node(self, node, *,
check_is_file=False, check_is_dir=False):
- path_str = node.get_str(key)
+ path_str = node.as_str()
path = Path(path_str)
full_path = self._absolute_directory_path / path
- provenance = _yaml.node_get_provenance(node, key=key)
-
if full_path.is_symlink():
+ provenance = _yaml.node_get_provenance(node)
raise LoadError(LoadErrorReason.PROJ_PATH_INVALID_KIND,
"{}: Specified path '{}' must not point to "
"symbolic links "
.format(provenance, path_str))
if path.parts and path.parts[0] == '..':
+ provenance = _yaml.node_get_provenance(node)
raise LoadError(LoadErrorReason.PROJ_PATH_INVALID,
"{}: Specified path '{}' first component must "
"not be '..'"
@@ -288,6 +287,7 @@ class Project():
else:
full_resolved_path = full_path.resolve(strict=True) # pylint: disable=unexpected-keyword-arg
except FileNotFoundError:
+ provenance = _yaml.node_get_provenance(node)
raise LoadError(LoadErrorReason.MISSING_FILE,
"{}: Specified path '{}' does not exist"
.format(provenance, path_str))
@@ -296,12 +296,14 @@ class Project():
full_resolved_path == self._absolute_directory_path)
if not is_inside:
+ provenance = _yaml.node_get_provenance(node)
raise LoadError(LoadErrorReason.PROJ_PATH_INVALID,
"{}: Specified path '{}' must not lead outside of the "
"project directory"
.format(provenance, path_str))
if path.is_absolute():
+ provenance = _yaml.node_get_provenance(node)
raise LoadError(LoadErrorReason.PROJ_PATH_INVALID,
"{}: Absolute path: '{}' invalid.\n"
"Please specify a path relative to the project's root."
@@ -310,17 +312,20 @@ class Project():
if full_resolved_path.is_socket() or (
full_resolved_path.is_fifo() or
full_resolved_path.is_block_device()):
+ provenance = _yaml.node_get_provenance(node)
raise LoadError(LoadErrorReason.PROJ_PATH_INVALID_KIND,
"{}: Specified path '{}' points to an unsupported "
"file kind"
.format(provenance, path_str))
if check_is_file and not full_resolved_path.is_file():
+ provenance = _yaml.node_get_provenance(node)
raise LoadError(LoadErrorReason.PROJ_PATH_INVALID_KIND,
"{}: Specified path '{}' is not a regular file"
.format(provenance, path_str))
if check_is_dir and not full_resolved_path.is_dir():
+ provenance = _yaml.node_get_provenance(node)
raise LoadError(LoadErrorReason.PROJ_PATH_INVALID_KIND,
"{}: Specified path '{}' is not a directory"
.format(provenance, path_str))
@@ -594,7 +599,7 @@ class Project():
self.element_path = os.path.join(
self.directory,
- self.get_path_from_node(pre_config_node, 'element-path',
+ self.get_path_from_node(pre_config_node.get_scalar('element-path'),
check_is_dir=True)
)
@@ -947,7 +952,7 @@ class Project():
del origin_node[group]
if origin_node.get_str('origin') == 'local':
- path = self.get_path_from_node(origin, 'path',
+ path = self.get_path_from_node(origin.get_scalar('path'),
check_is_dir=True)
# paths are passed in relative to the project, but must be absolute
origin_node['path'] = os.path.join(self.directory, path)
diff --git a/src/buildstream/plugin.py b/src/buildstream/plugin.py
index cee24ea1f..2e5cc9678 100644
--- a/src/buildstream/plugin.py
+++ b/src/buildstream/plugin.py
@@ -363,7 +363,7 @@ class Plugin():
provenance = _yaml.node_get_provenance(node, key=member_name)
return str(provenance)
- def node_get_project_path(self, node, key, *,
+ def node_get_project_path(self, node, *,
check_is_file=False, check_is_dir=False):
"""Fetches a project path from a dictionary node and validates it
@@ -377,8 +377,7 @@ class Plugin():
``True``.
Args:
- node (dict): A dictionary loaded from YAML
- key (str): The key whose value contains a path to validate
+ node (ScalarNode): A Node loaded from YAML containing the path to validate
check_is_file (bool): If ``True`` an error will also be raised
if path does not point to a regular file.
Defaults to ``False``
@@ -403,7 +402,7 @@ class Plugin():
"""
- return self.__project.get_path_from_node(node, key,
+ return self.__project.get_path_from_node(node,
check_is_file=check_is_file,
check_is_dir=check_is_dir)
diff --git a/src/buildstream/plugins/sources/local.py b/src/buildstream/plugins/sources/local.py
index ff0cf1679..e28098c38 100644
--- a/src/buildstream/plugins/sources/local.py
+++ b/src/buildstream/plugins/sources/local.py
@@ -55,7 +55,7 @@ class LocalSource(Source):
def configure(self, node):
node.validate_keys(['path', *Source.COMMON_CONFIG_KEYS])
- self.path = self.node_get_project_path(node, 'path')
+ self.path = self.node_get_project_path(node.get_scalar('path'))
self.fullpath = os.path.join(self.get_project_directory(), self.path)
def preflight(self):
diff --git a/src/buildstream/plugins/sources/patch.py b/src/buildstream/plugins/sources/patch.py
index 01117db78..1e70039bd 100644
--- a/src/buildstream/plugins/sources/patch.py
+++ b/src/buildstream/plugins/sources/patch.py
@@ -55,7 +55,7 @@ class PatchSource(Source):
BST_REQUIRES_PREVIOUS_SOURCES_STAGE = True
def configure(self, node):
- self.path = self.node_get_project_path(node, 'path',
+ self.path = self.node_get_project_path(node.get_scalar('path'),
check_is_file=True)
self.strip_level = node.get_int("strip-level", default=1)
self.fullpath = os.path.join(self.get_project_directory(), self.path)