check_modules_set_name: do not check for "enable" key (#37701)
This commit is contained in:
parent
54003d4d72
commit
e56c90d839
@ -116,21 +116,23 @@ def one_spec_or_raise(specs):
|
|||||||
|
|
||||||
|
|
||||||
def check_module_set_name(name):
|
def check_module_set_name(name):
|
||||||
modules_config = spack.config.get("modules")
|
modules = spack.config.get("modules")
|
||||||
valid_names = set(
|
if name != "prefix_inspections" and name in modules:
|
||||||
[
|
return
|
||||||
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")
|
|
||||||
|
|
||||||
if name not in valid_names:
|
names = [k for k in modules if k != "prefix_inspections"]
|
||||||
msg = "Cannot use invalid module set %s." % name
|
|
||||||
msg += " Valid module set names are %s" % list(valid_names)
|
if not names:
|
||||||
raise spack.config.ConfigError(msg)
|
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 = (
|
_missing_modules_warning = (
|
||||||
|
@ -8,6 +8,8 @@
|
|||||||
|
|
||||||
import pytest
|
import pytest
|
||||||
|
|
||||||
|
import spack.cmd.modules
|
||||||
|
import spack.config
|
||||||
import spack.error
|
import spack.error
|
||||||
import spack.modules.tcl
|
import spack.modules.tcl
|
||||||
import spack.package_base
|
import spack.package_base
|
||||||
@ -187,3 +189,31 @@ def find_nothing(*args):
|
|||||||
assert module_path
|
assert module_path
|
||||||
|
|
||||||
spack.package_base.PackageBase.uninstall_by_spec(spec)
|
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")
|
||||||
|
Loading…
Reference in New Issue
Block a user