From 4b2f51d063111d0966404ff7f1eea627f2d286d8 Mon Sep 17 00:00:00 2001 From: Peter Josef Scheibel Date: Fri, 18 May 2018 17:38:28 -0700 Subject: [PATCH] env: preserve command_line as the scope of highest precedence Co-authored-by: Elizabeth Fischer --- lib/spack/spack/config.py | 24 +++++++++++++++++------- lib/spack/spack/test/conftest.py | 9 ++++++--- 2 files changed, 23 insertions(+), 10 deletions(-) diff --git a/lib/spack/spack/config.py b/lib/spack/spack/config.py index b432d5019d..179972299e 100644 --- a/lib/spack/spack/config.py +++ b/lib/spack/spack/config.py @@ -261,13 +261,26 @@ def __init__(self, *scopes): def push_scope(self, scope): """Add a higher precedence scope to the Configuration.""" + cmd_line_scope = None + if self.scopes: + highest_precedence_scope = list(self.scopes.values())[-1] + if highest_precedence_scope.name == 'command_line': + # If the command-line scope is present, it should always + # be the scope of highest precedence + cmd_line_scope = self.pop_scope() + self.scopes[scope.name] = scope + if cmd_line_scope: + self.scopes['command_line'] = cmd_line_scope def pop_scope(self): """Remove the highest precedence scope and return it.""" name, scope = self.scopes.popitem(last=True) return scope + def remove_scope(self, scope_name): + return self.scopes.pop(scope_name) + @property def file_scopes(self): """List of writable scopes with an associated file.""" @@ -463,20 +476,17 @@ def override(path_or_scope, value=None): """ if isinstance(path_or_scope, ConfigScope): + overrides = path_or_scope config.push_scope(path_or_scope) - yield config - config.pop_scope(path_or_scope) - else: overrides = InternalConfigScope('overrides') - config.push_scope(overrides) config.set(path_or_scope, value, scope='overrides') - yield config + yield config - scope = config.pop_scope() - assert scope is overrides + scope = config.remove_scope(overrides.name) + assert scope is overrides #: configuration scopes added on the command line diff --git a/lib/spack/spack/test/conftest.py b/lib/spack/spack/test/conftest.py index f87c84d942..7de7d1495b 100644 --- a/lib/spack/spack/test/conftest.py +++ b/lib/spack/spack/test/conftest.py @@ -254,9 +254,12 @@ def config(configuration_dir): real_configuration = spack.config.config - spack.config.config = spack.config.Configuration( - *[spack.config.ConfigScope(name, str(configuration_dir.join(name))) - for name in ['site', 'system', 'user']]) + test_scopes = [ + spack.config.ConfigScope(name, str(configuration_dir.join(name))) + for name in ['site', 'system', 'user']] + test_scopes.append(spack.config.InternalConfigScope('command_line')) + + spack.config.config = spack.config.Configuration(*test_scopes) yield spack.config.config