18 from typing
import Any, List, Dict, Optional, Tuple
22 from ..base_parameter
import BaseParameter
23 from ..utils
import validateRangeStructure
24 from ....project
import ProjectType
30 class RangeParameter(BaseParameter[Dict[str, int]]):
33 def types(self) -> List[type]:
36 def validate(self) -> Tuple[bool, Optional[str]]:
37 if not isinstance(self.value, dict):
40 isValid, message = validateRangeStructure(self.name, self.value, self.required)
42 return isValid, message
44 if self.value[
"to"] > RANGE_LIMIT:
45 return False, f
"Range value \"to\" must not exceed 2^32"
47 if not self.value[
"to"] > self.value[
"from"]:
48 return False, f
"Range value \"to\" must not be greater then \"from\""
50 if not self.value[
"step"] <= self.value[
"to"] - self.value[
"from"]:
51 return False, f
"Range value \"step\" must be lower or equal to the distance between \"from\" and \"to\""
55 def parseValue(self, type_: ProjectType) -> Optional[Any]:
56 if self.value
is None:
59 return range(self.value[
"from"], self.value[
"to"], self.value[
"step"])
61 def overrideValue(self, value: Optional[Any]) -> Optional[Any]:
62 if value
is None or self.value
is None:
66 args = value.split(
" ")
67 parsedValue: Dict[str, int] = {}
71 if len(args)
not in [2, 3]:
74 parsedValue[
"from"] = int(args[0])
75 parsedValue[
"to"] = int(args[1])
76 parsedValue[
"step"] = int(args[2])
if len(args) == 3
else 1
79 except ValueError
as e:
80 logging.getLogger(
"coretexpylib").warning(f
">> [Coretex] Failed to override range parameter \"{self.name}\". | {e}")