intermediate work on arbitrary types for pkg_attribute

This commit is contained in:
Peter Josef Scheibel
2022-10-21 14:11:33 -06:00
committed by Gregory Becker
parent 2b5be8c52a
commit 4bc2d12a68
3 changed files with 52 additions and 2 deletions

View File

@@ -33,6 +33,8 @@
from llnl.util.compat import Mapping
from llnl.util.filesystem import working_dir
import spack.util.spack_yaml as syaml
import ruamel.yaml as ryaml
import spack.caches
import spack.config
import spack.error
@@ -1374,8 +1376,20 @@ def get_pkg_class(self, pkg_name):
# sets attributes that it used to)
new_overidden_attrs = {}
for key, val in new_cfg_settings.items():
new_overidden_attrs[key] = getattr(cls, key)
setattr(cls, key, val)
if hasattr(cls, key):
new_overidden_attrs[key] = getattr(cls, key)
if isinstance(val, dict):
t = val.get("type", "string")
v = val["value"]
if t == "int":
v = int(v)
elif t == "float":
v = float(v)
elif t == "boolean":
v = ryaml.load(v)
setattr(cls, key, v)
else:
setattr(cls, key, val)
if new_overidden_attrs:
setattr(cls, "overidden_attrs", dict(new_overidden_attrs))
elif hasattr(cls, "overidden_attrs"):

View File

@@ -98,6 +98,21 @@
"type": "boolean",
},
},
"patternProperties": {
r"\w[\w-]*": {
"type": "object",
"additionalProperties": False,
"properties": {
"value": {
"type": "string",
},
"type": {
"type": "string",
"enum": ["int", "float", "boolean"],
},
},
},
},
},
"providers": {
"type": "object",

View File

@@ -195,6 +195,27 @@ 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
"""
update_packages(
"mpileaks",
"package_attributes",
{"x": {
"value": "1",
"type": "int",
},
"y": {
"value": "true",
"type": "boolean",
}
},
)
spec = concretize("mpileaks")
assert spec.package.x == 1
assert spec.package.y == True
def test_preferred(self):
""" "Test packages with some version marked as preferred=True"""
spec = Spec("python")