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):
"""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

View file

@ -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