add placeholders for assigning collection types

This commit is contained in:
Peter Josef Scheibel
2022-10-21 15:02:06 -06:00
committed by Gregory Becker
parent 4f5afbe97b
commit 8dbd7b423b
3 changed files with 24 additions and 7 deletions

View File

@@ -1374,6 +1374,12 @@ def get_pkg_class(self, pkg_name):
# sets attributes that it used to)
new_overidden_attrs = {}
for key, val in new_cfg_settings.items():
if hasattr(cls, key):
new_overidden_attrs[key] = getattr(cls, key)
if isinstance(val, list):
raise spack.config.ConfigError("Unsupported attribute value: list")
elif isinstance(val, dict):
raise spack.config.ConfigError("Unsupported attribute value: dict")
if key not in ["git", "url", "submodules"]:
# Infer type
val = yaml.load(val)

View File

@@ -99,8 +99,15 @@
},
},
"patternProperties": {
r"\w[\w-]*": {
"type": "string",
r"\w+": {
"oneOf": [
{"type": "string"},
{"type": "array", "items": {"type": "string"}},
{
"type": "object",
"patternProperties": {r"\w+": {"type": "string"}},
},
]
},
},
},

View File

@@ -179,7 +179,7 @@ def test_preferred_providers(self):
spec = concretize("mpileaks")
assert "zmpi" in spec
def test_config_set_url_for_package(self, mutable_mock_repo):
def test_config_set_pkg_property_url(self, mutable_mock_repo):
"""Test preferred providers of virtual packages are
applied correctly
"""
@@ -195,10 +195,8 @@ def test_config_set_url_for_package(self, mutable_mock_repo):
spec = concretize("mpileaks")
assert spec.package.fetcher[0].url == "http://www.llnl.gov/mpileaks-2.3.tar.gz"
def test_config_set_package_property(self, mutable_mock_repo):
"""Test preferred providers of virtual packages are
applied correctly
"""
def test_config_set_pkg_property_new(self, mutable_mock_repo):
"""Test that you can set arbitrary attributes on the Package class"""
update_packages(
"mpileaks",
"package_attributes",
@@ -208,6 +206,12 @@ def test_config_set_package_property(self, mutable_mock_repo):
assert spec.package.x == 1
assert spec.package.y == True
def test_config_set_pkg_property_collecton_unsupported(self, mutable_mock_repo):
"""Test that an error is raised if you attempt to assign a list value"""
update_packages("mpileaks", "package_attributes", {"x": ["a", "b"]})
with pytest.raises(ConfigError):
spec = concretize("mpileaks")
def test_preferred(self):
""" "Test packages with some version marked as preferred=True"""
spec = Spec("python")