config.set: allow override section

This commit is contained in:
Gregory Becker 2024-11-25 15:05:03 -08:00
parent 83624551e0
commit ced6f984ea
2 changed files with 12 additions and 3 deletions

View File

@ -672,11 +672,12 @@ def set(self, path: str, value: Any, scope: Optional[str] = None) -> None:
return
parts = process_config_path(path)
section = parts.pop(0)
section = parts[0]
section_data = self.get_config(section, scope=scope)
data = section_data
full_data = {section: section_data}
data = full_data
while len(parts) > 1:
key = parts.pop(0)
@ -699,7 +700,7 @@ def set(self, path: str, value: Any, scope: Optional[str] = None) -> None:
# update new value
data[parts[0]] = value
self.update_config(section, section_data, scope=scope)
self.update_config(section, full_data[section], scope=scope)
def __iter__(self):
"""Iterate over scopes in this configuration."""

View File

@ -1208,8 +1208,16 @@ def test_internal_config_list_override(mock_low_high_config, write_config_file):
def test_set_section_override(mock_low_high_config, write_config_file):
write_config_file("config", config_merge_list, "low")
wanted_list = config_override_list["config"]["build_stage:"]
# Ensure test validity:
assert wanted_list != mock_low_high_config.get("config:build_stage")
# Test both bare section with full value and section override in path
with spack.config.override("config::build_stage", wanted_list):
assert mock_low_high_config.get("config:build_stage") == wanted_list
with spack.config.override("config::", {"build_stage": wanted_list}):
assert mock_low_high_config.get("config:build_stage") == wanted_list
assert config_merge_list["config"]["build_stage"] == mock_low_high_config.get(
"config:build_stage"
)