def parse_value(self, value, load_value=None, target_config=None): """ Parse an individual value from the input. probably this is the most important code in user value parsing :param str value: the value to parse. :return: the parsed value. """ from dbnd._core.utils.task_utils import to_targets from targets.inmemory_target import InMemoryTarget from targets.values.target_values import _TargetValueType from targets import Target if load_value is None: load_value = self.load_on_build value = self._interpolate_from_str(value) if value is None: return value if isinstance(value, six.string_types): # we are in the string mode # it's can be "serialized to string" or path value if load_value: # in case we have simple type -> just load/parse it if self.support_from_str: value = self.parse_from_str(value) value = self.normalize(value) return value # otherwise - the data is "Complex object" # our assumption is that it can not be loaded from string # the value is a path! target_kwargs = {} if target_config: target_kwargs["config"] = target_config # Check for glob path if _is_glob_path(value): from targets import target return target(value, config=target_config) """ it's possible that we have a list of targets, or just a single target (all targets should be loaded as single object). we need to support: 1. /some/path 2. /some/path,.... 3. ["/some_path",..] we will try to parse it as list, if we get list with one element (1) -> we can return it, otherwise we wrap it with MultiTarget """ from targets.values.structure import ListValueType # Parse into value type list list_of_targets = ListValueType().parse_from_str(value) # Apply all values from config list_of_targets = to_targets(list_of_targets, from_string_kwargs=target_kwargs) if len(list_of_targets) == 1: return list_of_targets[0] else: from targets.multi_target import MultiTarget return MultiTarget(list_of_targets) from dbnd._core.task import Task if isinstance(value, Task): return to_targets(value) if isinstance(value, Target): return value # so we have a value that is obviously "Data" type, # we want to be able to support "load_value" behaviour if not load_value and not isinstance(self, _TargetValueType): return InMemoryTarget(value, value_type=self) value = self.normalize(value) return value
known_values.append(NumpyArrayValueType()) except ImportError: pass known_values.extend([ # simple BoolValueType(), IntValueType(), FloatValueType(), # date/time DateValueType(), DateTimeValueType(), TimeDeltaValueType(), DateIntervalValueType(), # structs, ListValueType(), DictValueType(), SetValueType(), TupleValueType(), # targets, path TargetValueType(), TargetPathValueType(), TargetPathLibValueType(), TargetConfigValueType(), CallableValueType(), # str types VersionValueType(), StrValueType(), NullableStrValueType(), ])