Bugfix: spack config change handle string requirements (#42176)
For a requirement like ``` packages: foo: require: - "+debug" ``` (not `one_of:`, `any_of:`, or `spec:`) `spack config change` would ignore the string. This was particularly evident if toggling a variant for a previously unmentioned package: ``` $ spack config change packages:foo:require:+debug $ spack config change packages:foo:require:~debug ``` This fixes that and adds a test for it.
This commit is contained in:
parent
d7bcaa29c0
commit
621e203a8e
@ -304,6 +304,10 @@ def override_cfg_spec(spec_str):
|
|||||||
item["any_of"] = [override_cfg_spec(x) for x in item["any_of"]]
|
item["any_of"] = [override_cfg_spec(x) for x in item["any_of"]]
|
||||||
elif "spec" in item:
|
elif "spec" in item:
|
||||||
item["spec"] = override_cfg_spec(item["spec"])
|
item["spec"] = override_cfg_spec(item["spec"])
|
||||||
|
elif isinstance(item, str):
|
||||||
|
item = override_cfg_spec(item)
|
||||||
|
else:
|
||||||
|
raise ValueError(f"Unexpected requirement: ({type(item)}) {str(item)}")
|
||||||
new_require.append(item)
|
new_require.append(item)
|
||||||
|
|
||||||
spack.config.set(path, new_require, scope=scope)
|
spack.config.set(path, new_require, scope=scope)
|
||||||
|
@ -922,10 +922,22 @@ def test_config_change_existing(mutable_mock_env_path, tmp_path, mock_packages,
|
|||||||
# a spec string that requires enclosing in quotes as
|
# a spec string that requires enclosing in quotes as
|
||||||
# part of the config path
|
# part of the config path
|
||||||
config("change", 'packages:libelf:require:"@0.8.12:"')
|
config("change", 'packages:libelf:require:"@0.8.12:"')
|
||||||
test_spec = spack.spec.Spec("libelf@0.8.12").concretized()
|
spack.spec.Spec("libelf@0.8.12").concretized()
|
||||||
# No need for assert, if there wasn't a failure, we
|
# No need for assert, if there wasn't a failure, we
|
||||||
# changed the requirement successfully.
|
# changed the requirement successfully.
|
||||||
|
|
||||||
|
# Use change to add a requirement for a package that
|
||||||
|
# has no requirements defined
|
||||||
|
config("change", "packages:fftw:require:+mpi")
|
||||||
|
test_spec = spack.spec.Spec("fftw").concretized()
|
||||||
|
assert test_spec.satisfies("+mpi")
|
||||||
|
config("change", "packages:fftw:require:~mpi")
|
||||||
|
test_spec = spack.spec.Spec("fftw").concretized()
|
||||||
|
assert test_spec.satisfies("~mpi")
|
||||||
|
config("change", "packages:fftw:require:@1.0")
|
||||||
|
test_spec = spack.spec.Spec("fftw").concretized()
|
||||||
|
assert test_spec.satisfies("@1.0~mpi")
|
||||||
|
|
||||||
# Use "--match-spec" to change one spec in a "one_of"
|
# Use "--match-spec" to change one spec in a "one_of"
|
||||||
# list
|
# list
|
||||||
config("change", "packages:bowtie:require:@1.2.2", "--match-spec", "@1.2.0")
|
config("change", "packages:bowtie:require:@1.2.2", "--match-spec", "@1.2.0")
|
||||||
|
Loading…
Reference in New Issue
Block a user