env: preserve command_line as the scope of highest precedence

Co-authored-by: Elizabeth Fischer <rpf2116@columbia.edu>
This commit is contained in:
Peter Josef Scheibel 2018-05-18 17:38:28 -07:00 committed by Todd Gamblin
parent d1cce990cd
commit 4b2f51d063
2 changed files with 23 additions and 10 deletions

View file

@ -261,13 +261,26 @@ def __init__(self, *scopes):
def push_scope(self, scope): def push_scope(self, scope):
"""Add a higher precedence scope to the Configuration.""" """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 self.scopes[scope.name] = scope
if cmd_line_scope:
self.scopes['command_line'] = cmd_line_scope
def pop_scope(self): def pop_scope(self):
"""Remove the highest precedence scope and return it.""" """Remove the highest precedence scope and return it."""
name, scope = self.scopes.popitem(last=True) name, scope = self.scopes.popitem(last=True)
return scope return scope
def remove_scope(self, scope_name):
return self.scopes.pop(scope_name)
@property @property
def file_scopes(self): def file_scopes(self):
"""List of writable scopes with an associated file.""" """List of writable scopes with an associated file."""
@ -463,19 +476,16 @@ def override(path_or_scope, value=None):
""" """
if isinstance(path_or_scope, ConfigScope): if isinstance(path_or_scope, ConfigScope):
overrides = path_or_scope
config.push_scope(path_or_scope) config.push_scope(path_or_scope)
yield config
config.pop_scope(path_or_scope)
else: else:
overrides = InternalConfigScope('overrides') overrides = InternalConfigScope('overrides')
config.push_scope(overrides) config.push_scope(overrides)
config.set(path_or_scope, value, scope='overrides') config.set(path_or_scope, value, scope='overrides')
yield config yield config
scope = config.pop_scope() scope = config.remove_scope(overrides.name)
assert scope is overrides assert scope is overrides

View file

@ -254,9 +254,12 @@ def config(configuration_dir):
real_configuration = spack.config.config real_configuration = spack.config.config
spack.config.config = spack.config.Configuration( test_scopes = [
*[spack.config.ConfigScope(name, str(configuration_dir.join(name))) spack.config.ConfigScope(name, str(configuration_dir.join(name)))
for name in ['site', 'system', 'user']]) 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 yield spack.config.config