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

feat(sdk): CLI - Allow upload_version by the pipeline's name. Fixes #3901 #4087

Merged
merged 24 commits into from
Jul 8, 2020
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
33 changes: 32 additions & 1 deletion sdk/python/kfp/_client.py
Original file line number Diff line number Diff line change
Expand Up @@ -39,7 +39,15 @@
# initialized with host=<inverse proxy endpoint>.
# Set to 55 mins to provide some safe margin.
_GCP_ACCESS_TOKEN_TIMEOUT = datetime.timedelta(minutes=55)

# Operators on scalar values. Only applies to one of |int_value|,
# |long_value|, |string_value| or |timestamp_value|.
_FILTER_OPERATIONS = {"UNKNOWN": 0,
"EQUALS" : 1,
"NOT_EQUALS" : 2,

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Just for my education, is the predicates other than 'EQUALS' being used now in the client?

Copy link
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

No, they are not I kept them on order to have a reference for the alternative since we don't have a proper helper file. Maybe we should remove it. Initially I only. set it to 1, but @Bobgy suggested that we added a mapping in order for readers of the code to understand what it meant.

"GREATER_THAN": 3,
"GREATER_THAN_EQUALS": 5,
"LESS_THAN": 6,
"LESS_THAN_EQUALS": 7}

def _add_generated_apis(target_struct, api_module, api_client):
'''Initializes a hierarchical API object based on the generated API module.
Expand Down Expand Up @@ -304,6 +312,29 @@ def create_experiment(self, name, description=None, namespace=None):
IPython.display.display(IPython.display.HTML(html))
return experiment

def get_pipeline_id(self, name):
"""Returns the pipeline id if a pipeline with the name exsists.
Bobgy marked this conversation as resolved.
Show resolved Hide resolved
Args:
name: pipeline name
Returns:
A response object including a list of experiments and next page token.
"""
pipeline_filter = json.dumps({
"predicates": [
{
"op": _FILTER_OPERATIONS["EQUALS"],
"key": "name",
"stringValue": name,
}
]
})
result = self._pipelines_api.list_pipelines(filter=pipeline_filter)
if len(result.pipelines)==1:
return result.pipelines[0].id
elif len(result.pipelines)>1:
raise ValueError("Multiple pipelines with the name: {} found, the name needs to be unique".format(name))
return None

def list_experiments(self, page_token='', page_size=10, sort_by='', namespace=None):
"""List experiments.
Args:
Expand Down
22 changes: 17 additions & 5 deletions sdk/python/kfp/cli/pipeline.py
Original file line number Diff line number Diff line change
Expand Up @@ -47,7 +47,13 @@ def upload(ctx, pipeline_name, package_file):
"-p",
"--pipeline-id",
help="ID of the pipeline",
required=True
required=False
)
@click.option(
"-n",
"--pipeline-name",
help="Name of pipeline",
required=False
)
@click.option(
"-v",
Expand All @@ -57,15 +63,21 @@ def upload(ctx, pipeline_name, package_file):
)
@click.argument("package-file")
@click.pass_context
def upload_version(ctx, package_file, pipeline_version, pipeline_id):
def upload_version(ctx, package_file, pipeline_version, pipeline_id=None, pipeline_name=None):
"""Upload a version of the KFP pipeline"""
client = ctx.obj["client"]

if bool(pipeline_id) == bool(pipeline_name):
raise ValueError("Need to suppy 'pipeline-name' or 'pipeline-id'")
if pipeline_name!=None:
NikeNano marked this conversation as resolved.
Show resolved Hide resolved
pipeline_id = client.get_pipeline_id(name=pipeline_name)
if pipeline_id==None:
raise ValueError("Can't find a pipeline with name: %s" % pipeline_name)
logging.info("The pipeline id is: %s" % pipeline_id)
version = client.pipeline_uploads.upload_pipeline_version(
package_file, name=pipeline_version, pipelineid=pipeline_id)
logging.info(
"The {} version of the pipeline {} has been submitted\n".format(
pipeline_version, pipeline_id))
"The %s version of the pipeline %s has been submitted\n" %
(pipeline_version, pipeline_id))
_display_pipeline_version(version)


Expand Down