summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorHarmen Stoppels <harmenstoppels@gmail.com>2023-05-16 11:51:52 +0200
committerGitHub <noreply@github.com>2023-05-16 11:51:52 +0200
commite56c90d8397103549c92493722e93fdb43e5512b (patch)
treeb700ddb2d1b3f0b84bbbfe9633ac3b528e0aecce
parent54003d4d72c5f77bf228579e56b8e2e421a19bbb (diff)
downloadspack-e56c90d8397103549c92493722e93fdb43e5512b.tar.gz
spack-e56c90d8397103549c92493722e93fdb43e5512b.tar.bz2
spack-e56c90d8397103549c92493722e93fdb43e5512b.tar.xz
spack-e56c90d8397103549c92493722e93fdb43e5512b.zip
check_modules_set_name: do not check for "enable" key (#37701)
-rw-r--r--lib/spack/spack/cmd/modules/__init__.py30
-rw-r--r--lib/spack/spack/test/modules/common.py30
2 files changed, 46 insertions, 14 deletions
diff --git a/lib/spack/spack/cmd/modules/__init__.py b/lib/spack/spack/cmd/modules/__init__.py
index 107189f814..60a7475f3a 100644
--- a/lib/spack/spack/cmd/modules/__init__.py
+++ b/lib/spack/spack/cmd/modules/__init__.py
@@ -116,21 +116,23 @@ def one_spec_or_raise(specs):
def check_module_set_name(name):
- modules_config = spack.config.get("modules")
- valid_names = set(
- [
- key
- for key, value in modules_config.items()
- if isinstance(value, dict) and value.get("enable", [])
- ]
- )
- if "enable" in modules_config and modules_config["enable"]:
- valid_names.add("default")
+ modules = spack.config.get("modules")
+ if name != "prefix_inspections" and name in modules:
+ return
+
+ names = [k for k in modules if k != "prefix_inspections"]
- if name not in valid_names:
- msg = "Cannot use invalid module set %s." % name
- msg += " Valid module set names are %s" % list(valid_names)
- raise spack.config.ConfigError(msg)
+ if not names:
+ raise spack.config.ConfigError(
+ f"Module set configuration is missing. Cannot use module set '{name}'"
+ )
+
+ pretty_names = "', '".join(names)
+
+ raise spack.config.ConfigError(
+ f"Cannot use invalid module set '{name}'.",
+ f"Valid module set names are: '{pretty_names}'.",
+ )
_missing_modules_warning = (
diff --git a/lib/spack/spack/test/modules/common.py b/lib/spack/spack/test/modules/common.py
index 77347c8d2b..b778bbac7b 100644
--- a/lib/spack/spack/test/modules/common.py
+++ b/lib/spack/spack/test/modules/common.py
@@ -8,6 +8,8 @@ import sys
import pytest
+import spack.cmd.modules
+import spack.config
import spack.error
import spack.modules.tcl
import spack.package_base
@@ -187,3 +189,31 @@ def test_load_installed_package_not_in_repo(install_mockery, mock_fetch, monkeyp
assert module_path
spack.package_base.PackageBase.uninstall_by_spec(spec)
+
+
+@pytest.mark.regression("37649")
+def test_check_module_set_name(mutable_config):
+ """Tests that modules set name are validated correctly and an error is reported if the
+ name we require does not exist or is reserved by the configuration."""
+
+ # Minimal modules.yaml config.
+ spack.config.set(
+ "modules",
+ {
+ "prefix_inspections": {"./bin": ["PATH"]},
+ # module sets
+ "first": {},
+ "second": {},
+ },
+ )
+
+ # Valid module set name
+ spack.cmd.modules.check_module_set_name("first")
+
+ # Invalid module set names
+ msg = "Valid module set names are"
+ with pytest.raises(spack.config.ConfigError, match=msg):
+ spack.cmd.modules.check_module_set_name("prefix_inspections")
+
+ with pytest.raises(spack.config.ConfigError, match=msg):
+ spack.cmd.modules.check_module_set_name("third")