Commit a5ff465d authored by Chandan Singh's avatar Chandan Singh Committed by Tristan Van Berkom 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.
parent 7df95654
......@@ -40,6 +40,9 @@ from ._workspaces import Workspaces
# The separator we use for user specified aliases
# Project Configuration file
_PROJECT_CONF_FILE = 'project.conf'
# HostMount()
......@@ -75,7 +78,7 @@ class Project(): = None
# The project directory = os.path.abspath(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(, "project.conf")
projectfile = os.path.join(, _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(, origin_dict['path'])
# _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(
'{} not found in current directory or any of its parent directories'
directory = parent_dir
return directory
......@@ -54,6 +54,21 @@ def test_load_default_project(cli, datafiles):
assert (env['TERM'] == "dumb")
def test_load_project_from_subdir(cli, datafiles):
project = os.path.join(datafiles.dirname, datafiles.basename, 'project-from-subdir')
result =
cwd=os.path.join(project, 'subdirectory'),
args=['show', '--format', '%{env}', 'manual.bst'])
# Read back some of our project defaults from the env
env = _yaml.load_data(result.output)
assert (env['USER'] == "tomjon")
assert (env['TERM'] == "dumb")
def test_override_project_path(cli, datafiles):
project = os.path.join(datafiles.dirname, datafiles.basename, "overridepath")
# Basic project configuration that doesnt override anything
name: pony
This directory is used to test running commands from a project subdirectory.
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment