config.set: allow override section
This commit is contained in:
parent
83624551e0
commit
ced6f984ea
@ -672,11 +672,12 @@ def set(self, path: str, value: Any, scope: Optional[str] = None) -> None:
|
|||||||
return
|
return
|
||||||
|
|
||||||
parts = process_config_path(path)
|
parts = process_config_path(path)
|
||||||
section = parts.pop(0)
|
section = parts[0]
|
||||||
|
|
||||||
section_data = self.get_config(section, scope=scope)
|
section_data = self.get_config(section, scope=scope)
|
||||||
|
|
||||||
data = section_data
|
full_data = {section: section_data}
|
||||||
|
data = full_data
|
||||||
while len(parts) > 1:
|
while len(parts) > 1:
|
||||||
key = parts.pop(0)
|
key = parts.pop(0)
|
||||||
|
|
||||||
@ -699,7 +700,7 @@ def set(self, path: str, value: Any, scope: Optional[str] = None) -> None:
|
|||||||
# update new value
|
# update new value
|
||||||
data[parts[0]] = 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):
|
def __iter__(self):
|
||||||
"""Iterate over scopes in this configuration."""
|
"""Iterate over scopes in this configuration."""
|
||||||
|
@ -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):
|
def test_set_section_override(mock_low_high_config, write_config_file):
|
||||||
write_config_file("config", config_merge_list, "low")
|
write_config_file("config", config_merge_list, "low")
|
||||||
wanted_list = config_override_list["config"]["build_stage:"]
|
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):
|
with spack.config.override("config::build_stage", wanted_list):
|
||||||
assert mock_low_high_config.get("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(
|
assert config_merge_list["config"]["build_stage"] == mock_low_high_config.get(
|
||||||
"config:build_stage"
|
"config:build_stage"
|
||||||
)
|
)
|
||||||
|
Loading…
Reference in New Issue
Block a user