Skip to content

Commit

Permalink
Tolerate components w/o description, sanitize parameter names
Browse files Browse the repository at this point in the history
* Many kubeflow/pipelines components do not have a description
* Replace characters in component parameter names that are not
  allowed in Python identifiers

Related machine-learning-exchange#286

Signed-off-by: Christian Kadner <[email protected]>
  • Loading branch information
ckadner committed Jan 19, 2022
1 parent 8b0fb80 commit bd25d9b
Show file tree
Hide file tree
Showing 2 changed files with 10 additions and 6 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -366,7 +366,7 @@ def _upload_component_yaml(yaml_file_content: AnyStr, name=None, existing_id=Non
component_id = existing_id or generate_id(name=name or yaml_dict["name"])
created_at = datetime.now()
name = name or yaml_dict["name"]
description = (yaml_dict["description"] or "").strip()[:255]
description = (yaml_dict.get("description") or name).strip()[:255]
filter_categories = yaml_dict.get("filter_categories") or dict()

metadata = ApiMetadata(annotations=template_metadata.get("annotations"),
Expand Down
14 changes: 9 additions & 5 deletions api/server/swagger_server/gateways/kubeflow_pipeline_service.py
Original file line number Diff line number Diff line change
Expand Up @@ -11,6 +11,7 @@
from datetime import datetime

from kfp import Client as KfpClient
from kfp.components._naming import _sanitize_python_function_name as sanitize

from kfp_server_api import ApiRun
from kfp_server_api import ApiPipeline as KfpPipeline
Expand Down Expand Up @@ -100,13 +101,16 @@ def quote_string_value(value):

def generate_method_arg_from_parameter(parameter):

param_name = sanitize(parameter.name)

if parameter.value or parameter.default:
value = quote_string_value(parameter.value or parameter.default)
arg = f"{parameter.name}={value}"
arg = f"{param_name}={value}"
elif parameter.value == '' or parameter.default == '': # TODO: should empty string != None ?
arg = f"{parameter.name}=''"
arg = f"{param_name}=''"
else:
arg = parameter.name
arg = param_name

return arg


Expand All @@ -128,9 +132,9 @@ def generate_component_run_script(component: ApiComponent, component_template_ur

pipeline_method_args = generate_pipeline_method_args(component.parameters)

parameter_names = ",".join([p.name for p in component.parameters])
parameter_names = ",".join([sanitize(p.name) for p in component.parameters])

parameter_dict = json.dumps({p.name: run_parameters.get(p.name) or p.default or ""
parameter_dict = json.dumps({sanitize(p.name): run_parameters.get(p.name) or p.default or ""
for p in component.parameters},
indent=4).replace('"', "'")

Expand Down

0 comments on commit bd25d9b

Please sign in to comment.