summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorPeter Scheibel <scheibel1@llnl.gov>2024-01-19 00:10:39 -0800
committerGitHub <noreply@github.com>2024-01-19 08:10:39 +0000
commit621e203a8e4411393e261444f3f1ddf2fd002701 (patch)
tree712a7b8a1b5c3fa4f2f077b68c76a5b2e02b9641
parentd7bcaa29c06381984745e992d74c3c722e0f81a9 (diff)
downloadspack-621e203a8e4411393e261444f3f1ddf2fd002701.tar.gz
spack-621e203a8e4411393e261444f3f1ddf2fd002701.tar.bz2
spack-621e203a8e4411393e261444f3f1ddf2fd002701.tar.xz
spack-621e203a8e4411393e261444f3f1ddf2fd002701.zip
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.
-rw-r--r--lib/spack/spack/cmd/config.py4
-rw-r--r--lib/spack/spack/test/cmd/env.py14
2 files changed, 17 insertions, 1 deletions
diff --git a/lib/spack/spack/cmd/config.py b/lib/spack/spack/cmd/config.py
index adfe286c37..ee0bad2bae 100644
--- a/lib/spack/spack/cmd/config.py
+++ b/lib/spack/spack/cmd/config.py
@@ -304,6 +304,10 @@ def _config_change_requires_scope(path, spec, scope, match_spec=None):
item["any_of"] = [override_cfg_spec(x) for x in item["any_of"]]
elif "spec" in item:
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)
spack.config.set(path, new_require, scope=scope)
diff --git a/lib/spack/spack/test/cmd/env.py b/lib/spack/spack/test/cmd/env.py
index 0908ae3be3..1d3380b8a6 100644
--- a/lib/spack/spack/test/cmd/env.py
+++ b/lib/spack/spack/test/cmd/env.py
@@ -922,10 +922,22 @@ spack:
# a spec string that requires enclosing in quotes as
# part of the config path
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
# 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"
# list
config("change", "packages:bowtie:require:@1.2.2", "--match-spec", "@1.2.0")