do type inference on strings (this works well for values that are not collections)
This commit is contained in:
committed by
Gregory Becker
parent
469401d4a1
commit
4f5afbe97b
@@ -1374,20 +1374,10 @@ 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, 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 = yaml.load(v)
|
||||
setattr(cls, key, v)
|
||||
else:
|
||||
setattr(cls, key, val)
|
||||
if key not in ["git", "url", "submodules"]:
|
||||
# Infer type
|
||||
val = yaml.load(val)
|
||||
setattr(cls, key, val)
|
||||
if new_overidden_attrs:
|
||||
setattr(cls, "overidden_attrs", dict(new_overidden_attrs))
|
||||
elif hasattr(cls, "overidden_attrs"):
|
||||
|
||||
@@ -100,17 +100,7 @@
|
||||
},
|
||||
"patternProperties": {
|
||||
r"\w[\w-]*": {
|
||||
"type": "object",
|
||||
"additionalProperties": False,
|
||||
"properties": {
|
||||
"value": {
|
||||
"type": "string",
|
||||
},
|
||||
"type": {
|
||||
"type": "string",
|
||||
"enum": ["int", "float", "boolean"],
|
||||
},
|
||||
},
|
||||
"type": "string",
|
||||
},
|
||||
},
|
||||
},
|
||||
|
||||
@@ -202,16 +202,7 @@ def test_config_set_package_property(self, mutable_mock_repo):
|
||||
update_packages(
|
||||
"mpileaks",
|
||||
"package_attributes",
|
||||
{
|
||||
"x": {
|
||||
"value": "1",
|
||||
"type": "int",
|
||||
},
|
||||
"y": {
|
||||
"value": "true",
|
||||
"type": "boolean",
|
||||
},
|
||||
},
|
||||
{"x": "1", "y": "true"},
|
||||
)
|
||||
spec = concretize("mpileaks")
|
||||
assert spec.package.x == 1
|
||||
|
||||
Reference in New Issue
Block a user