Skip to content

Commit

Permalink
feat(sdk): port cli code from v1 to v2 (#7547)
Browse files Browse the repository at this point in the history
* port cli

* fix docker mock
  • Loading branch information
connor-mccarthy authored Apr 13, 2022
1 parent 94960cf commit d46fafe
Show file tree
Hide file tree
Showing 21 changed files with 2,750 additions and 3 deletions.
13 changes: 13 additions & 0 deletions sdk/python/kfp/cli/__init__.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,13 @@
# Copyright 2018 The Kubeflow Authors
#
# Licensed under the Apache License, Version 2.0 (the "License");
# you may not use this file except in compliance with the License.
# You may obtain a copy of the License at
#
# http://www.apache.org/licenses/LICENSE-2.0
#
# Unless required by applicable law or agreed to in writing, software
# distributed under the License is distributed on an "AS IS" BASIS,
# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
# See the License for the specific language governing permissions and
# limitations under the License.
82 changes: 82 additions & 0 deletions sdk/python/kfp/cli/cli.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,82 @@
# Copyright 2018 The Kubeflow Authors
#
# Licensed under the Apache License, Version 2.0 (the "License");
# you may not use this file except in compliance with the License.
# You may obtain a copy of the License at
#
# http://www.apache.org/licenses/LICENSE-2.0
#
# Unless required by applicable law or agreed to in writing, software
# distributed under the License is distributed on an "AS IS" BASIS,
# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
# See the License for the specific language governing permissions and
# limitations under the License.

import logging
import sys

import click
import typer
from kfp.cli import components
from kfp.cli.diagnose_me_cli import diagnose_me
from kfp.cli.experiment import experiment
from kfp.cli.output import OutputFormat
from kfp.cli.pipeline import pipeline
from kfp.cli.recurring_run import recurring_run
from kfp.cli.run import run
from kfp.client import Client

_NO_CLIENT_COMMANDS = ['diagnose_me', 'components']


@click.group()
@click.option('--endpoint', help='Endpoint of the KFP API service to connect.')
@click.option('--iap-client-id', help='Client ID for IAP protected endpoint.')
@click.option(
'-n',
'--namespace',
default='kubeflow',
show_default=True,
help='Kubernetes namespace to connect to the KFP API.')
@click.option(
'--other-client-id',
help='Client ID for IAP protected endpoint to obtain the refresh token.')
@click.option(
'--other-client-secret',
help='Client ID for IAP protected endpoint to obtain the refresh token.')
@click.option(
'--output',
type=click.Choice(list(map(lambda x: x.name, OutputFormat))),
default=OutputFormat.table.name,
show_default=True,
help='The formatting style for command output.')
@click.pass_context
def cli(ctx: click.Context, endpoint: str, iap_client_id: str, namespace: str,
other_client_id: str, other_client_secret: str, output: OutputFormat):
"""kfp is the command line interface to KFP service.
Feature stage:
[Alpha](https://github.com/kubeflow/pipelines/blob/07328e5094ac2981d3059314cc848fbb71437a76/docs/release/feature-stages.md#alpha)
"""
if ctx.invoked_subcommand in _NO_CLIENT_COMMANDS:
# Do not create a client for these subcommands
return
ctx.obj['client'] = Client(endpoint, iap_client_id, namespace,
other_client_id, other_client_secret)
ctx.obj['namespace'] = namespace
ctx.obj['output'] = output


def main():
logging.basicConfig(format='%(message)s', level=logging.INFO)
cli.add_command(run)
cli.add_command(recurring_run)
cli.add_command(pipeline)
cli.add_command(diagnose_me, 'diagnose_me')
cli.add_command(experiment)
cli.add_command(typer.main.get_command(components.app))
try:
cli(obj={}, auto_envvar_prefix='KFP')
except Exception as e:
click.echo(str(e), err=True)
sys.exit(1)
Loading

0 comments on commit d46fafe

Please sign in to comment.