From 02330659d7a53108b66a34b747722e3f25ede560 Mon Sep 17 00:00:00 2001 From: Alexey Volkov Date: Mon, 19 Nov 2018 17:25:08 -0800 Subject: [PATCH] SDK/Components - Renamed DockerContainer spec to to Container --- sdk/python/kfp/compiler/_component_builder.py | 4 +- sdk/python/kfp/components/_python_op.py | 4 +- sdk/python/kfp/components/_structures.py | 12 ++--- .../tests/components/test_components.py | 52 +++++++++---------- .../test_data/python_add.component.yaml | 2 +- 5 files changed, 37 insertions(+), 37 deletions(-) diff --git a/sdk/python/kfp/compiler/_component_builder.py b/sdk/python/kfp/compiler/_component_builder.py index a7c5d165ecfb..71f0a1bee013 100644 --- a/sdk/python/kfp/compiler/_component_builder.py +++ b/sdk/python/kfp/compiler/_component_builder.py @@ -416,7 +416,7 @@ def _generate_pythonop(component_func, target_image, target_component_file=None) component_artifact['outputs'] = [{'name': 'output'}] component_artifact['inputs'] = [] component_artifact['implementation'] = { - 'dockerContainer': { + 'container': { 'image': target_image, 'arguments': [], 'fileOutputs': { @@ -429,7 +429,7 @@ def _generate_pythonop(component_func, target_image, target_component_file=None) 'name': input, 'type': 'str' }) - component_artifact['implementation']['dockerContainer']['arguments'].append({'value': input}) + component_artifact['implementation']['container']['arguments'].append({'value': input}) target_component_file = target_component_file or getattr(component_func, '_component_target_component_file', None) if target_component_file: diff --git a/sdk/python/kfp/components/_python_op.py b/sdk/python/kfp/components/_python_op.py index 4c3e1fe99eba..0b2fc3ecf0e9 100644 --- a/sdk/python/kfp/components/_python_op.py +++ b/sdk/python/kfp/components/_python_op.py @@ -19,7 +19,7 @@ from ._yaml_utils import dump_yaml from ._components import _create_task_factory_from_component_spec -from ._structures import InputSpec, OutputSpec, ImplementationSpec, DockerContainerSpec, ComponentSpec +from ._structures import InputSpec, OutputSpec, ImplementationSpec, ContainerSpec, ComponentSpec from pathlib import Path from typing import TypeVar, Generic @@ -229,7 +229,7 @@ def annotation_to_argument_kind_and_type_name(annotation): inputs=[InputSpec.from_struct(input) for input in inputs], outputs=[OutputSpec.from_struct(output) for output in outputs], implementation=ImplementationSpec( - docker_container=DockerContainerSpec( + container=ContainerSpec( image=base_image, command=['python3', '-c', full_source], arguments=arguments, diff --git a/sdk/python/kfp/components/_structures.py b/sdk/python/kfp/components/_structures.py index cf10884ba4be..885831747fe9 100644 --- a/sdk/python/kfp/components/_structures.py +++ b/sdk/python/kfp/components/_structures.py @@ -16,7 +16,7 @@ 'InputOrOutputSpec', 'InputSpec', 'OutputSpec', - 'DockerContainerSpec', + 'ContainerSpec', 'GraphInputReferenceSpec', 'TaskOutputReferenceSpec', 'DataValueOrReferenceSpec', @@ -111,7 +111,7 @@ class OutputSpec(InputOrOutputSpec): pass -class DockerContainerSpec: +class ContainerSpec: def __init__(self, image:str, command:List=None, arguments:List=None, file_outputs:Mapping[str,str]=None): if not isinstance(image, str): raise ValueError('image must be a string') @@ -126,7 +126,7 @@ def from_struct(spec_dict:Mapping): image = spec_dict.pop('image') - container_spec = DockerContainerSpec(image) + container_spec = ContainerSpec(image) if 'command' in spec_dict: container_spec.command = list(spec_dict.pop('command')) @@ -339,8 +339,8 @@ def from_struct(spec_dict:Mapping): raise ValueError('There must be exactly one implementation') for name, value in spec_dict.items(): - if name == 'dockerContainer': - return ImplementationSpec(DockerContainerSpec.from_struct(value)) + if name == 'container': + return ImplementationSpec(ContainerSpec.from_struct(value)) elif name == 'graph': return ImplementationSpec(GraphSpec.from_struct(value)) else: @@ -349,7 +349,7 @@ def from_struct(spec_dict:Mapping): def to_struct(self): struct = {} if self.docker_container: - struct['dockerContainer'] = self.docker_container.to_struct() + struct['container'] = self.docker_container.to_struct() if self.graph: struct['graph'] = self.graph.to_struct() diff --git a/sdk/python/tests/components/test_components.py b/sdk/python/tests/components/test_components.py index 33f498bf06c8..a7bf943cc581 100644 --- a/sdk/python/tests/components/test_components.py +++ b/sdk/python/tests/components/test_components.py @@ -36,7 +36,7 @@ def test_load_component_from_file(self): arg2 = 5 task1 = task_factory1(arg1, arg2) assert task1.human_name == component_dict['name'] - assert task1.image == component_dict['implementation']['dockerContainer']['image'] + assert task1.image == component_dict['implementation']['container']['image'] assert task1.arguments[0] == str(arg1) assert task1.arguments[1] == str(arg2) @@ -56,7 +56,7 @@ def test_load_component_from_url(self): arg2 = 5 task1 = task_factory1(arg1, arg2) assert task1.human_name == component_dict['name'] - assert task1.image == component_dict['implementation']['dockerContainer']['image'] + assert task1.image == component_dict['implementation']['container']['image'] assert task1.arguments[0] == str(arg1) assert task1.arguments[1] == str(arg2) @@ -64,14 +64,14 @@ def test_load_component_from_url(self): def test_loading_minimal_component(self): component_text = '''\ implementation: - dockerContainer: + container: image: busybox ''' component_dict = load_yaml(component_text) task_factory1 = comp.load_component(text=component_text) task1 = task_factory1() - assert task1.image == component_dict['implementation']['dockerContainer']['image'] + assert task1.image == component_dict['implementation']['container']['image'] @unittest.expectedFailure def test_fail_on_duplicate_input_names(self): @@ -80,7 +80,7 @@ def test_fail_on_duplicate_input_names(self): - {name: Data1} - {name: Data1} implementation: - dockerContainer: + container: image: busybox ''' task_factory1 = comp.load_component_from_text(component_text) @@ -92,7 +92,7 @@ def test_fail_on_duplicate_output_names(self): - {name: Data1} - {name: Data1} implementation: - dockerContainer: + container: image: busybox ''' task_factory1 = comp.load_component_from_text(component_text) @@ -103,7 +103,7 @@ def test_handle_underscored_input_names(self): - {name: Data} - {name: _Data} implementation: - dockerContainer: + container: image: busybox ''' task_factory1 = comp.load_component_from_text(component_text) @@ -114,7 +114,7 @@ def test_handle_underscored_output_names(self): - {name: Data} - {name: _Data} implementation: - dockerContainer: + container: image: busybox ''' task_factory1 = comp.load_component_from_text(component_text) @@ -124,7 +124,7 @@ def test_handle_input_names_with_spaces(self): inputs: - {name: Training data} implementation: - dockerContainer: + container: image: busybox ''' task_factory1 = comp.load_component_from_text(component_text) @@ -134,7 +134,7 @@ def test_handle_output_names_with_spaces(self): outputs: - {name: Training data} implementation: - dockerContainer: + container: image: busybox ''' task_factory1 = comp.load_component_from_text(component_text) @@ -144,7 +144,7 @@ def test_handle_file_outputs_with_spaces(self): outputs: - {name: Output data} implementation: - dockerContainer: + container: image: busybox fileOutputs: Output data: /outputs/output-data @@ -158,7 +158,7 @@ def test_handle_similar_input_names(self): - {name: Input_1} - {name: Input-1} implementation: - dockerContainer: + container: image: busybox ''' task_factory1 = comp.load_component_from_text(component_text) @@ -170,7 +170,7 @@ def test_handle_duplicate_input_output_names(self): outputs: - {name: Data} implementation: - dockerContainer: + container: image: busybox ''' task_factory1 = comp.load_component_from_text(component_text) @@ -182,7 +182,7 @@ def test_fail_on_unknown_value_argument(self): inputs: - {name: Data} implementation: - dockerContainer: + container: image: busybox arguments: - [value, Wrong] @@ -195,7 +195,7 @@ def test_fail_on_unknown_file_output(self): outputs: - {name: Data} implementation: - dockerContainer: + container: image: busybox fileOutputs: Wrong: '/outputs/output.txt' @@ -229,7 +229,7 @@ def test_load_component_from_text_fail_on_none_arg(self): def test_command_yaml_types(self): component_text = '''\ implementation: - dockerContainer: + container: image: busybox arguments: # Nulls: @@ -290,7 +290,7 @@ def test_input_value_resolving(self): inputs: - {name: Data} implementation: - dockerContainer: + container: image: busybox arguments: - --data @@ -306,7 +306,7 @@ def test_output_resolving(self): outputs: - {name: Data} implementation: - dockerContainer: + container: image: busybox arguments: - --output-data @@ -322,7 +322,7 @@ def test_automatic_output_resolving(self): outputs: - {name: Data} implementation: - dockerContainer: + container: image: busybox arguments: - --output-data @@ -339,7 +339,7 @@ def test_command_concat(self): - {name: In1} - {name: In2} implementation: - dockerContainer: + container: image: busybox arguments: - concat: [{value: In1}, {value: In2}] @@ -352,7 +352,7 @@ def test_command_concat(self): def test_command_if_boolean_true_then_else(self): component_text = '''\ implementation: - dockerContainer: + container: image: busybox arguments: - if: @@ -367,7 +367,7 @@ def test_command_if_boolean_true_then_else(self): def test_command_if_boolean_false_then_else(self): component_text = '''\ implementation: - dockerContainer: + container: image: busybox arguments: - if: @@ -382,7 +382,7 @@ def test_command_if_boolean_false_then_else(self): def test_command_if_true_string_then_else(self): component_text = '''\ implementation: - dockerContainer: + container: image: busybox arguments: - if: @@ -397,7 +397,7 @@ def test_command_if_true_string_then_else(self): def test_command_if_false_string_then_else(self): component_text = '''\ implementation: - dockerContainer: + container: image: busybox arguments: - if: @@ -415,7 +415,7 @@ def test_command_if_is_present_then(self): inputs: - {name: In, required: false} implementation: - dockerContainer: + container: image: busybox arguments: - if: @@ -437,7 +437,7 @@ def test_command_if_is_present_then_else(self): inputs: - {name: In, required: false} implementation: - dockerContainer: + container: image: busybox arguments: - if: diff --git a/sdk/python/tests/components/test_data/python_add.component.yaml b/sdk/python/tests/components/test_data/python_add.component.yaml index 84a5647b7288..52779f884ef7 100644 --- a/sdk/python/tests/components/test_data/python_add.component.yaml +++ b/sdk/python/tests/components/test_data/python_add.component.yaml @@ -7,7 +7,7 @@ inputs: outputs: - {name: Output, type: float} implementation: - dockerContainer: + container: image: python:3.5 command: - python