Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

SDK/Components - Switching to map-based syntax for the arguments. #29

Merged
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
4 changes: 2 additions & 2 deletions sdk/python/kfp/compiler/_component_builder.py
Original file line number Diff line number Diff line change
Expand Up @@ -319,7 +319,7 @@ def _generate_pythonop(component_func, target_image):
'name': input,
'type': 'str'
})
component_artifact['implementation']['dockerContainer']['arguments'].append(['Value', input])
component_artifact['implementation']['dockerContainer']['arguments'].append({'value': input})
return _create_task_factory_from_component_dict(component_artifact)

def build_python_component(component_func, staging_gcs_path, target_image, build_image=True, timeout=600, namespace='kubeflow'):
Expand Down Expand Up @@ -370,4 +370,4 @@ def build_docker_image(staging_gcs_path, target_image, dockerfile_path, timeout=
logging.getLogger().setLevel('INFO')
builder = ImageBuilder(gcs_base=staging_gcs_path, target_image=target_image)
builder.build_image_from_dockerfile(dockerfile_path=dockerfile_path, timeout=timeout, namespace=namespace)
logging.info('Build image complete.')
logging.info('Build image complete.')
20 changes: 10 additions & 10 deletions sdk/python/kfp/components/_python_op.py
Original file line number Diff line number Diff line change
Expand Up @@ -64,24 +64,24 @@ def _func_to_component_spec(func, extra_code='', base_image=_default_base_image)

def annotation_to_argument_kind_and_type_name(annotation):
if not annotation or annotation == inspect.Parameter.empty:
return ('Value', None)
return ('value', None)
if hasattr(annotation, '__origin__'): #Generic type
type_name = annotation.__origin__.__name__
type_args = annotation.__args__
#if len(type_args) != 1:
# raise TypeError('Unsupported generic type {}'.format(type_name))
inner_type = type_args[0]
if type_name == InputFile.__name__:
return ('File', inner_type.__name__)
return ('file', inner_type.__name__)
elif type_name == OutputFile.__name__:
return ('Output', inner_type.__name__)
return ('output', inner_type.__name__)
if isinstance(annotation, type):
return ('Value', annotation.__name__)
return ('value', annotation.__name__)
else:
#!!! It's important to preserve string anotations as strings. Annotations that are neither types nor strings are converted to strings.
#Materializer adds double quotes to the types it does not recognize. - fix it to not quote strings.
#We need two kind of strings: we can use any type name for component YAML, but for generated Python code we must use valid python type annotations.
return ('Value', "'" + str(annotation) + "'")
return ('value', "'" + str(annotation) + "'")

for parameter in parameters:
annotation = parameter.annotation
Expand All @@ -91,14 +91,14 @@ def annotation_to_argument_kind_and_type_name(annotation):
parameter_to_type_name[parameter.name] = parameter_type_name

#TODO: Humanize the input/output names
arguments.append([argument_kind, parameter.name])
arguments.append({argument_kind: parameter.name})

parameter_spec = OrderedDict([('name', parameter.name)])
if parameter_type_name:
parameter_spec['type'] = parameter_type_name
if argument_kind == 'Value' or argument_kind == 'File':
if argument_kind == 'value' or argument_kind == 'file':
inputs.append(parameter_spec)
elif argument_kind == 'Output':
elif argument_kind == 'output':
outputs.append(parameter_spec)
else:
#Cannot happen
Expand All @@ -120,15 +120,15 @@ def annotation_to_argument_kind_and_type_name(annotation):
output_spec['type'] = output_type_name
outputs.append(output_spec)
extra_output_names.append(field_name)
arguments.append(['Output', field_name])
arguments.append({'output': field_name})
else:
output_spec = OrderedDict([('name', single_output_name_const)])
(_, output_type_name) = annotation_to_argument_kind_and_type_name(signature.return_annotation)
if output_type_name:
output_spec['type'] = output_type_name
outputs.append(output_spec)
extra_output_names.append(single_output_pythonic_name_const)
arguments.append(['Output', single_output_name_const])
arguments.append({'output': single_output_name_const})

func_name=func.__name__

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -30,6 +30,6 @@ implementation:
import fire
fire.Fire(add_wrapper)
arguments:
- [Value, a]
- [Value, b]
- [Output, Output]
- {value: a}
- {value: b}
- {output: Output}