Skip to content

Commit

Permalink
SDK/Components - Renamed DockerContainer spec to to Container
Browse files Browse the repository at this point in the history
  • Loading branch information
Ark-kun committed Nov 20, 2018
1 parent f28a989 commit 0233065
Show file tree
Hide file tree
Showing 5 changed files with 37 additions and 37 deletions.
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 @@ -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': {
Expand All @@ -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:
Expand Down
4 changes: 2 additions & 2 deletions sdk/python/kfp/components/_python_op.py
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down Expand Up @@ -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,
Expand Down
12 changes: 6 additions & 6 deletions sdk/python/kfp/components/_structures.py
Original file line number Diff line number Diff line change
Expand Up @@ -16,7 +16,7 @@
'InputOrOutputSpec',
'InputSpec',
'OutputSpec',
'DockerContainerSpec',
'ContainerSpec',
'GraphInputReferenceSpec',
'TaskOutputReferenceSpec',
'DataValueOrReferenceSpec',
Expand Down Expand Up @@ -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')
Expand All @@ -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'))
Expand Down Expand Up @@ -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:
Expand All @@ -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()

Expand Down
52 changes: 26 additions & 26 deletions sdk/python/tests/components/test_components.py
Original file line number Diff line number Diff line change
Expand Up @@ -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)
Expand All @@ -56,22 +56,22 @@ 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)

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):
Expand All @@ -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)
Expand All @@ -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)
Expand All @@ -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)
Expand All @@ -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)
Expand All @@ -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)
Expand All @@ -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)
Expand All @@ -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
Expand All @@ -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)
Expand All @@ -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)
Expand All @@ -182,7 +182,7 @@ def test_fail_on_unknown_value_argument(self):
inputs:
- {name: Data}
implementation:
dockerContainer:
container:
image: busybox
arguments:
- [value, Wrong]
Expand All @@ -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'
Expand Down Expand Up @@ -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:
Expand Down Expand Up @@ -290,7 +290,7 @@ def test_input_value_resolving(self):
inputs:
- {name: Data}
implementation:
dockerContainer:
container:
image: busybox
arguments:
- --data
Expand All @@ -306,7 +306,7 @@ def test_output_resolving(self):
outputs:
- {name: Data}
implementation:
dockerContainer:
container:
image: busybox
arguments:
- --output-data
Expand All @@ -322,7 +322,7 @@ def test_automatic_output_resolving(self):
outputs:
- {name: Data}
implementation:
dockerContainer:
container:
image: busybox
arguments:
- --output-data
Expand All @@ -339,7 +339,7 @@ def test_command_concat(self):
- {name: In1}
- {name: In2}
implementation:
dockerContainer:
container:
image: busybox
arguments:
- concat: [{value: In1}, {value: In2}]
Expand All @@ -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:
Expand All @@ -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:
Expand All @@ -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:
Expand All @@ -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:
Expand All @@ -415,7 +415,7 @@ def test_command_if_is_present_then(self):
inputs:
- {name: In, required: false}
implementation:
dockerContainer:
container:
image: busybox
arguments:
- if:
Expand All @@ -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:
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -7,7 +7,7 @@ inputs:
outputs:
- {name: Output, type: float}
implementation:
dockerContainer:
container:
image: python:3.5
command:
- python
Expand Down

0 comments on commit 0233065

Please sign in to comment.