diff options
author | Chandan Singh <csingh43@bloomberg.net> | 2018-04-22 03:16:03 +0100 |
---|---|---|
committer | Tristan Van Berkom <tristan.van.berkom@gmail.com> | 2018-06-06 22:10:49 +0000 |
commit | a5ff465d9225ad894435f95ec03f6ee21968fcb1 (patch) | |
tree | 727d3dc771d7267840b02cdb589a4d0bd358c726 /buildstream | |
parent | 7df956547696092cb07082bc4f6ec12f6585cdd0 (diff) | |
download | buildstream-a5ff465d9225ad894435f95ec03f6ee21968fcb1.tar.gz |
_project.py: Allow running bst commands from subdirectories of project root
When initializing the project, BuildStream will continue searching for
project.conf in parent directories in case it is not found in the
current directory.
Fixes #368.
Diffstat (limited to 'buildstream')
-rw-r--r-- | buildstream/_project.py | 31 |
1 files changed, 29 insertions, 2 deletions
diff --git a/buildstream/_project.py b/buildstream/_project.py index 5344e954e..25ffaf6d2 100644 --- a/buildstream/_project.py +++ b/buildstream/_project.py @@ -40,6 +40,9 @@ from ._workspaces import Workspaces # The separator we use for user specified aliases _ALIAS_SEPARATOR = ':' +# Project Configuration file +_PROJECT_CONF_FILE = 'project.conf' + # HostMount() # @@ -75,7 +78,7 @@ class Project(): self.name = None # The project directory - self.directory = os.path.abspath(directory) + self.directory = self._ensure_project_dir(directory) # Absolute path to where elements are loaded from within the project self.element_path = None @@ -211,7 +214,7 @@ class Project(): def _load(self): # Load builtin default - projectfile = os.path.join(self.directory, "project.conf") + projectfile = os.path.join(self.directory, _PROJECT_CONF_FILE) config = _yaml.load(_site.default_project_config) # Load project local config and override the builtin @@ -458,3 +461,27 @@ class Project(): # paths are passed in relative to the project, but must be absolute origin_dict['path'] = os.path.join(self.directory, origin_dict['path']) destination.append(origin_dict) + + # _ensure_project_dir() + # + # Returns path of the project directory, if a configuration file is found + # in given directory or any of its parent directories. + # + # Args: + # directory (str) - directory from where the command was invoked + # + # Raises: + # LoadError if project.conf is not found + # + def _ensure_project_dir(self, directory): + directory = os.path.abspath(directory) + while not os.path.isfile(os.path.join(directory, _PROJECT_CONF_FILE)): + parent_dir = os.path.dirname(directory) + if directory == parent_dir: + raise LoadError( + LoadErrorReason.MISSING_PROJECT_CONF, + '{} not found in current directory or any of its parent directories' + .format(_PROJECT_CONF_FILE)) + directory = parent_dir + + return directory |