Skip to content
Snippets Groups Projects
Unverified Commit d2f56830 authored by Massimiliano Culpo's avatar Massimiliano Culpo Committed by GitHub
Browse files

"spack config update" can handle comments in YAML files (#18045)

fixes #18031

With this fix "spack config update" can update YAML
files that contain comments, while previously it
couldn't.
parent 29818fda
No related branches found
No related tags found
No related merge requests found
...@@ -363,7 +363,7 @@ def config_update(args): ...@@ -363,7 +363,7 @@ def config_update(args):
scope.name, args.section scope.name, args.section
) )
with open(cfg_file) as f: with open(cfg_file) as f:
data = syaml.load(f) or {} data = syaml.load_config(f) or {}
data = data.pop(args.section, {}) data = data.pop(args.section, {})
update_fn(data) update_fn(data)
......
...@@ -515,6 +515,42 @@ def test_updating_multiple_scopes_at_once(packages_yaml_v015): ...@@ -515,6 +515,42 @@ def test_updating_multiple_scopes_at_once(packages_yaml_v015):
check_update(data) check_update(data)
@pytest.mark.regression('18031')
def test_config_update_can_handle_comments(mutable_config):
# Create an outdated config file with comments
scope = spack.config.default_modify_scope()
cfg_file = spack.config.config.get_config_filename(scope, 'packages')
with open(cfg_file, mode='w') as f:
f.write("""
packages:
# system cmake in /usr
cmake:
paths:
cmake@3.14.0: /usr
# Another comment after the outdated section
buildable: False
""")
# Try to update it, it should not raise errors
config('update', '-y', 'packages')
# Check data
data = spack.config.get('packages', scope=scope)
assert 'paths' not in data['cmake']
assert 'externals' in data['cmake']
externals = data['cmake']['externals']
assert len(externals) == 1
assert externals[0]['spec'] == 'cmake@3.14.0'
assert externals[0]['prefix'] == '/usr'
# Check the comment is there
with open(cfg_file) as f:
text = ''.join(f.readlines())
assert '# system cmake in /usr' in text
assert '# Another comment after the outdated section' in text
def check_update(data): def check_update(data):
"""Check that the data from the packages_yaml_v015 """Check that the data from the packages_yaml_v015
has been updated. has been updated.
......
0% Loading or .
You are about to add 0 people to the discussion. Proceed with caution.
Please register or to comment