Skip to content
Snippets Groups Projects
Commit 4b2f51d0 authored by Peter Josef Scheibel's avatar Peter Josef Scheibel Committed by Todd Gamblin
Browse files

env: preserve command_line as the scope of highest precedence

parent d1cce990
Branches
Tags v4.3.0
No related merge requests found
......@@ -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
......
......@@ -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
......
0% Loading or .
You are about to add 0 people to the discussion. Proceed with caution.
Please register or to comment