You are viewing a plain text version of this content. The canonical link for it is here.
Posted to commits@buildstream.apache.org by tv...@apache.org on 2021/02/04 08:21:07 UTC

[buildstream] 01/02: _context.py: Add user_remotes to global user context, the default of which is set to 'all'

This is an automated email from the ASF dual-hosted git repository.

tvb pushed a commit to branch tpollard/752
in repository https://gitbox.apache.org/repos/asf/buildstream.git

commit 99f0d726f993f2c3d5e2a4683fa35d7a28efc2ad
Author: Tom Pollard <to...@codethink.co.uk>
AuthorDate: Wed Nov 14 17:26:34 2018 +0000

    _context.py: Add user_remotes to global user context, the default
    of which is set to 'all'
    
    _frontend/app.py & cli.py: Add --user-remotes as a bst main option,
    with values of 'all', 'user' or 'none' which when passed will
    override the default or user defined context for user_remotes
    
    tests/completions/completions.py: Update for the added flag
---
 buildstream/_context.py       | 13 ++++++++++++-
 buildstream/_frontend/app.py  |  3 ++-
 buildstream/_frontend/cli.py  |  3 +++
 tests/frontend/completions.py |  2 ++
 4 files changed, 19 insertions(+), 2 deletions(-)

diff --git a/buildstream/_context.py b/buildstream/_context.py
index 1d049f7..4375543 100644
--- a/buildstream/_context.py
+++ b/buildstream/_context.py
@@ -131,6 +131,9 @@ class Context():
         # Make sure the XDG vars are set in the environment before loading anything
         self._init_xdg()
 
+        # Which remote artifact servers to interact with. all, user or none
+        self.use_remotes = 'all'
+
         # Private variables
         self._cache_key = None
         self._message_handler = None
@@ -183,7 +186,8 @@ class Context():
         _yaml.node_validate(defaults, [
             'sourcedir', 'builddir', 'artifactdir', 'logdir',
             'scheduler', 'artifacts', 'logging', 'projects',
-            'cache', 'prompt', 'workspacedir', 'remote-execution'
+            'cache', 'prompt', 'workspacedir', 'remote-execution',
+            'useremotes'
         ])
 
         for directory in ['sourcedir', 'builddir', 'artifactdir', 'logdir', 'workspacedir']:
@@ -213,6 +217,13 @@ class Context():
         # Load pull build trees configuration
         self.pull_buildtrees = _yaml.node_get(cache, bool, 'pull-buildtrees')
 
+        # Load remote artifact server usage
+        self.use_remotes = _yaml.node_get(defaults, str, 'useremotes', default_value='all')
+        valid_actions = ['all', 'user', 'none']
+        if self.use_remotes not in valid_actions:
+            raise LoadError(LoadErrorReason.INVALID_DATA,
+                            "useremotes should be one of: {}".format(", ".join(valid_actions)))
+
         # Load logging config
         logging = _yaml.node_get(defaults, Mapping, 'logging')
         _yaml.node_validate(logging, [
diff --git a/buildstream/_frontend/app.py b/buildstream/_frontend/app.py
index b6da079..bd3d475 100644
--- a/buildstream/_frontend/app.py
+++ b/buildstream/_frontend/app.py
@@ -183,7 +183,8 @@ class App():
             'builders': 'sched_builders',
             'pushers': 'sched_pushers',
             'network_retries': 'sched_network_retries',
-            'pull_buildtrees': 'pull_buildtrees'
+            'pull_buildtrees': 'pull_buildtrees',
+            'use_remotes': 'use_remotes'
         }
         for cli_option, context_attr in override_map.items():
             option_value = self._main_options.get(cli_option)
diff --git a/buildstream/_frontend/cli.py b/buildstream/_frontend/cli.py
index 163a057..27f0700 100644
--- a/buildstream/_frontend/cli.py
+++ b/buildstream/_frontend/cli.py
@@ -252,6 +252,9 @@ def print_version(ctx, param, value):
               help="The mirror to fetch from first, before attempting other mirrors")
 @click.option('--pull-buildtrees', is_flag=True, default=None,
               help="Include an element's build tree when pulling remote element artifacts")
+@click.option('--use-remotes', default='all',
+              type=click.Choice(['all', 'user', 'none']),
+              help='The remote artifact caches to interact with (default: all)')
 @click.pass_context
 def cli(context, **kwargs):
     """Build and manipulate BuildStream projects
diff --git a/tests/frontend/completions.py b/tests/frontend/completions.py
index 007064f..d7c34d3 100644
--- a/tests/frontend/completions.py
+++ b/tests/frontend/completions.py
@@ -44,6 +44,7 @@ MAIN_OPTIONS = [
     "--pull-buildtrees ",
     "--pushers ",
     "--strict ",
+    "--use-remotes ",
     "--verbose ",
     "--version ",
 ]
@@ -155,6 +156,7 @@ def test_options(cli, cmd, word_idx, expected):
 
 @pytest.mark.parametrize("cmd,word_idx,expected", [
     ('bst --on-error ', 2, ['continue ', 'quit ', 'terminate ']),
+    ('bst --use-remotes ', 2, ['all ', 'user ', 'none ']),
     ('bst show --deps ', 3, ['all ', 'build ', 'none ', 'plan ', 'run ']),
     ('bst show --deps=', 2, ['all ', 'build ', 'none ', 'plan ', 'run ']),
     ('bst show --deps b', 3, ['build ']),