diff options
author | Benjamin Schubert <ben.c.schubert@gmail.com> | 2019-07-05 17:00:13 +0100 |
---|---|---|
committer | Benjamin Schubert <ben.c.schubert@gmail.com> | 2019-07-09 16:55:56 +0100 |
commit | d109c08d3cd1a7721036a5de54c01856ffe39a2d (patch) | |
tree | 6794d7bcbc00061a8eb0234ec43e63394bbc4423 | |
parent | 8b2193fde212479f3d6d0996a9493c6b51cee1ad (diff) | |
download | buildstream-d109c08d3cd1a7721036a5de54c01856ffe39a2d.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.py | 21 | ||||
-rw-r--r-- | src/buildstream/plugin.py | 5 | ||||
-rw-r--r-- | src/buildstream/plugins/sources/local.py | 2 | ||||
-rw-r--r-- | src/buildstream/plugins/sources/patch.py | 2 |
4 files changed, 17 insertions, 13 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 5d6e796d2..2e5cc9678 100644 --- a/src/buildstream/plugin.py +++ b/src/buildstream/plugin.py @@ -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) |