18 from typing
import Dict, Any
22 from .utils
import getValueParamType
23 from .base_parameter
import BaseParameter
24 from .parameter_type
import ParameterType
25 from .parameters
import *
26 from ...secret
import AWSSecret, GitSecret, CredentialsSecret
29 def cleanParamDict(value: Dict[str, Any]) -> Dict[str, Any]:
30 if not "data_type" in value:
31 value[
"data_type"] =
None
33 if not "value" in value:
36 if not "required" in value:
37 value[
"required"] =
False
39 if not "description" in value:
40 value[
"description"] =
""
42 dataName: str = value[
"name"]
43 dataType = value[
"data_type"]
44 dataValue = value[
"value"]
46 if dataType
is None and dataValue
is None:
47 value[
"data_type"] = ParameterType.string.value
49 if dataType
is None and dataValue
is not None:
50 value[
"data_type"] = getValueParamType(dataValue, dataName).value
54 def create(value: Dict[str, Any]) -> BaseParameter:
56 dataType = value.get(
"data_type")
58 if not isinstance(dataType, str):
59 raise ValueError(
"\"data_type\" is not of type \"str\"")
63 inflection.camelize(key, uppercase_first_letter =
False): value
64 for key, value
in value.items()
67 parameterType = ParameterType(dataType)
69 if parameterType == ParameterType.integer:
70 return IntParameter(**value)
72 if parameterType == ParameterType.floatingPoint:
73 return FloatParameter(**value)
75 if parameterType == ParameterType.string:
76 return StrParameter(**value)
78 if parameterType == ParameterType.boolean:
79 return BoolParameter(**value)
81 if parameterType == ParameterType.dataset:
82 return DatasetParameter(**value)
84 if parameterType == ParameterType.model:
85 return ModelParameter(**value)
87 if parameterType == ParameterType.imuVectors:
88 return IMUVectorsParameter(**value)
90 if parameterType == ParameterType.enum:
91 return EnumParameter(**value)
93 if parameterType == ParameterType.range:
94 return RangeParameter(**value)
96 if parameterType == ParameterType.awsSecret:
97 return SecretParameter(AWSSecret, **value)
99 if parameterType == ParameterType.gitSecret:
100 return SecretParameter(GitSecret, **value)
102 if parameterType == ParameterType.credentialsSecret:
103 return SecretParameter(CredentialsSecret, **value)
105 if parameterType == ParameterType.intList:
106 return ListIntParameter(**value)
108 if parameterType == ParameterType.floatList:
109 return ListFloatParameter(**value)
111 if parameterType == ParameterType.strList:
112 return ListStrParameter(**value)
114 if parameterType == ParameterType.datasetList:
115 return ListDatasetParameter(**value)
117 if parameterType == ParameterType.modelList:
118 return ListModelParameter(**value)
120 if parameterType == ParameterType.enumList:
121 return ListEnumParameter(**value)
123 if parameterType == ParameterType.awsSecretList:
124 return ListSecretParameter(AWSSecret, **value)
126 if parameterType == ParameterType.gitSecretList:
127 return ListSecretParameter(GitSecret, **value)
129 if parameterType == ParameterType.credentialsSecretList:
130 return ListSecretParameter(CredentialsSecret, **value)
132 raise ValueError(f
"Unknown parameter type \"{parameterType}\"")