summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorAngelos Evripiotis <jevripiotis@bloomberg.net>2018-10-19 17:55:51 +0100
committerAngelos Evripiotis <jevripiotis@bloomberg.net>2018-11-20 11:19:33 +0000
commit27ca65931d3cf6cf897b623f21ba2363f3c54029 (patch)
tree36852dbf42d763ea4dcfe5ee0f506a333e1a67c2
parentb81c43331ef9c09e7252cef6b9ee04a605329fea (diff)
downloadbuildstream-27ca65931d3cf6cf897b623f21ba2363f3c54029.tar.gz
Add prompt.auto-init buildstream.conf option
Provide an option in buildstream.conf to disable the 'Would you like to ...' prompt when we cannot resolve a project. Some users prefer not to be interrupted by such prompts, so pave the way to creating options to disable all those that might get in the way. Follow the example of the advice.* options 'git-config', and create a namespace for these UI options grouped by behaviour, rather than an over-reaching 'ui.*' namespace. In later work perhaps we'll also add 'advice.*' options. Add a NEWS item for this.
-rw-r--r--NEWS4
-rw-r--r--buildstream/_context.py20
-rw-r--r--buildstream/_frontend/app.py7
-rw-r--r--buildstream/data/userconfig.yaml16
4 files changed, 43 insertions, 4 deletions
diff --git a/NEWS b/NEWS
index 56cacc623..584f1d6d8 100644
--- a/NEWS
+++ b/NEWS
@@ -45,6 +45,10 @@ buildstream 1.3.1
instead of just a specially-formatted build-root with a `root` and `scratch`
subdirectory.
+ o The buildstream.conf file learned a new 'prompt.auto-init' option. This
+ allows users to suppress prompts for automatically running 'bst init' if we
+ were unable to resolve the project.
+
o Due to the element `build tree` being cached in the respective artifact their
size in some cases has significantly increased. In *most* cases the build trees
are not utilised when building targets, as such by default bst 'pull' & 'build'
diff --git a/buildstream/_context.py b/buildstream/_context.py
index 55cce685b..9bb261b62 100644
--- a/buildstream/_context.py
+++ b/buildstream/_context.py
@@ -110,6 +110,10 @@ class Context():
# Whether or not to attempt to pull build trees globally
self.pull_buildtrees = None
+ # Boolean, whether to offer to create a project for the user, if we are
+ # invoked outside of a directory where we can resolve the project.
+ self.prompt_auto_init = None
+
# Whether elements must be rebuilt when their dependencies have changed
self._strict_build_plan = None
@@ -165,7 +169,7 @@ class Context():
_yaml.node_validate(defaults, [
'sourcedir', 'builddir', 'artifactdir', 'logdir',
'scheduler', 'artifacts', 'logging', 'projects',
- 'cache'
+ 'cache', 'prompt'
])
for directory in ['sourcedir', 'builddir', 'artifactdir', 'logdir']:
@@ -221,6 +225,20 @@ class Context():
self.sched_pushers = _yaml.node_get(scheduler, int, 'pushers')
self.sched_network_retries = _yaml.node_get(scheduler, int, 'network-retries')
+ # Load prompt preferences
+ #
+ # We convert string options to booleans here, so we can be both user
+ # and coder-friendly. The string options are worded to match the
+ # responses the user would give at the cli, for least surprise. The
+ # booleans are converted here because it's easiest to eyeball that the
+ # strings are right.
+ #
+ prompt = _yaml.node_get(
+ defaults, Mapping, 'prompt')
+ _yaml.node_validate(prompt, ['auto-init'])
+ self.prompt_auto_init = _node_get_option_str(
+ prompt, 'auto-init', ['ask', 'no']) == 'ask'
+
# Load per-projects overrides
self._project_overrides = _yaml.node_get(defaults, Mapping, 'projects', default_value={})
diff --git a/buildstream/_frontend/app.py b/buildstream/_frontend/app.py
index b42b94bc1..4094eec17 100644
--- a/buildstream/_frontend/app.py
+++ b/buildstream/_frontend/app.py
@@ -222,9 +222,10 @@ class App():
# Let's automatically start a `bst init` session in this case
if e.reason == LoadErrorReason.MISSING_PROJECT_CONF and self.interactive:
click.echo("A project was not detected in the directory: {}".format(directory), err=True)
- click.echo("", err=True)
- if click.confirm("Would you like to create a new project here ?"):
- self.init_project(None)
+ if self.context.prompt_auto_init:
+ click.echo("", err=True)
+ if click.confirm("Would you like to create a new project here?"):
+ self.init_project(None)
self._error_exit(e, "Error loading project")
diff --git a/buildstream/data/userconfig.yaml b/buildstream/data/userconfig.yaml
index f540a97f6..0e6581cb7 100644
--- a/buildstream/data/userconfig.yaml
+++ b/buildstream/data/userconfig.yaml
@@ -100,3 +100,19 @@ logging:
[%{elapsed}][%{key}][%{element}] %{action} %{message}
+#
+# Prompt overrides
+#
+# Here you can suppress 'are you sure?' and other kinds of prompts by supplying
+# override values. Note that e.g. 'yes' and 'no' have the same meaning here as
+# they do in the actual cli prompt.
+#
+prompt:
+
+ # Whether to create a project with 'bst init' if we are invoked outside of a
+ # directory where we can resolve the project.
+ #
+ # ask - Prompt the user to choose.
+ # no - Never create the project.
+ #
+ auto-init: ask