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 - Fixed the non-string items in the command-line arguments #1197

Merged
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
28 changes: 16 additions & 12 deletions sdk/python/kfp/dsl/_container_op.py
Original file line number Diff line number Diff line change
Expand Up @@ -14,7 +14,7 @@

import re
import warnings
from typing import Any, Dict, List, TypeVar, Union, Callable
from typing import Any, Dict, List, TypeVar, Union, Callable, Optional, Sequence
from kubernetes.client.models import (
V1Container, V1EnvVar, V1EnvFromSource, V1SecurityContext, V1Probe,
V1ResourceRequirements, V1VolumeDevice, V1VolumeMount, V1ContainerPort,
Expand Down Expand Up @@ -72,11 +72,15 @@ def _proxy_container_op_props(cls: "ContainerOp"):
return cls


def as_list(value: Any, if_none: Union[None, List] = None) -> List:
def as_string_list(list_or_str: Optional[Union[Any, Sequence[Any]]]) -> List[str]:
"""Convert any value except None to a list if not already a list."""
if value is None:
return if_none
return value if isinstance(value, list) else [value]
if list_or_str is None:
return None
if isinstance(list_or_str, Sequence) and not isinstance(list_or_str, str):
list_value = list_or_str
else:
list_value = [list_or_str]
return [str(item) for item in list_value]


def create_and_append(current_list: Union[List[T], None], item: T) -> List[T]:
Expand Down Expand Up @@ -596,8 +600,8 @@ def __init__(self,
super().__init__(
name=name,
image=image,
command=as_list(command),
args=as_list(args),
command=as_string_list(command),
args=as_string_list(args),
**kwargs)

self.mirror_volume_mounts = mirror_volume_mounts
Expand Down Expand Up @@ -884,8 +888,8 @@ def __init__(self,
self.attrs_with_pipelineparams = BaseOp.attrs_with_pipelineparams + ['_container'] #Copying the BaseOp class variable!

# convert to list if not a list
command = as_list(command)
arguments = as_list(arguments)
command = as_string_list(command)
arguments = as_string_list(arguments)

# `container` prop in `io.argoproj.workflow.v1alpha1.Template`
container_kwargs = container_kwargs or {}
Expand Down Expand Up @@ -961,15 +965,15 @@ def command(self):

@command.setter
def command(self, value):
self._container.command = as_list(value)
self._container.command = as_string_list(value)

@property
def arguments(self):
return self._container.args

@arguments.setter
def arguments(self, value):
self._container.args = as_list(value)
self._container.args = as_string_list(value)

@property
def container(self):
Expand Down Expand Up @@ -1017,4 +1021,4 @@ def _set_metadata(self, metadata):

# proxy old ContainerOp properties to ContainerOp.container
# with PendingDeprecationWarning.
ContainerOp = _proxy_container_op_props(ContainerOp)
ContainerOp = _proxy_container_op_props(ContainerOp)