diff options
author | Peter Josef Scheibel <scheibel1@llnl.gov> | 2018-05-18 17:38:28 -0700 |
---|---|---|
committer | Todd Gamblin <tgamblin@llnl.gov> | 2018-11-09 00:31:24 -0800 |
commit | 4b2f51d063111d0966404ff7f1eea627f2d286d8 (patch) | |
tree | a6003f55664c6e7525ff82a38bb8006967836693 /lib | |
parent | d1cce990cd682ce76eebec9d311e2c10d0082d82 (diff) | |
download | spack-4b2f51d063111d0966404ff7f1eea627f2d286d8.tar.gz spack-4b2f51d063111d0966404ff7f1eea627f2d286d8.tar.bz2 spack-4b2f51d063111d0966404ff7f1eea627f2d286d8.tar.xz spack-4b2f51d063111d0966404ff7f1eea627f2d286d8.zip |
env: preserve command_line as the scope of highest precedence
Co-authored-by: Elizabeth Fischer <rpf2116@columbia.edu>
Diffstat (limited to 'lib')
-rw-r--r-- | lib/spack/spack/config.py | 24 | ||||
-rw-r--r-- | 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 @@ class Configuration(object): 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 |