in tfx/types/component_spec.py [0:0]
def _parse_parameters(self, raw_args: Mapping[str, Any]):
"""Parse arguments to ComponentSpec."""
unparsed_args = set(raw_args.keys())
inputs = {}
outputs = {}
self.exec_properties = {}
# First, check that the arguments are set.
for arg_name, arg in itertools.chain(self.PARAMETERS.items(),
self.INPUTS.items(),
self.OUTPUTS.items()):
if arg_name not in unparsed_args:
if arg.optional:
continue
else:
raise ValueError('Missing argument %r to %s.' %
(arg_name, self.__class__))
unparsed_args.remove(arg_name)
# Type check the argument.
value = raw_args[arg_name]
if arg.optional and value is None:
continue
arg.type_check(arg_name, value)
# Populate the appropriate dictionary for each parameter type.
for arg_name, arg in self.PARAMETERS.items():
if arg.optional and arg_name not in raw_args:
continue
value = raw_args[arg_name]
if (inspect.isclass(arg.type) and
issubclass(arg.type, message.Message) and value and
not _is_runtime_param(value)):
if arg.use_proto:
if isinstance(value, dict):
value = proto_utils.dict_to_proto(value, arg.type())
elif isinstance(value, str):
value = proto_utils.json_to_proto(value, arg.type())
else:
# Create deterministic json string as it will be stored in metadata
# for cache check.
if isinstance(value, dict):
value = json_utils.dumps(value)
elif not isinstance(value, str):
value = proto_utils.proto_to_json(value)
self.exec_properties[arg_name] = value
for arg_dict, param_dict in ((self.INPUTS, inputs), (self.OUTPUTS,
outputs)):
for arg_name, arg in arg_dict.items():
if arg.optional and not raw_args.get(arg_name):
continue
value = raw_args[arg_name]
param_dict[arg_name] = value
self.inputs = inputs
self.outputs = outputs