Skip to content

Commit

Permalink
chore(sdk): clean up v2 CLI (#7558)
Browse files Browse the repository at this point in the history
* remove linting comments

* move global variable to local

* simplify diagnose_me command

* use f-strings

* idiomatic python refactorings

* remove unused import

* add typestub library

* silence unresolvable mypy error

* update type information

* remove unused variable

* remove unused import

* use __main__.py for cli entrypoint

* expand imports
  • Loading branch information
connor-mccarthy authored Apr 20, 2022
1 parent 265e9f5 commit b58a31b
Show file tree
Hide file tree
Showing 21 changed files with 160 additions and 174 deletions.
4 changes: 4 additions & 0 deletions mypy.ini
Original file line number Diff line number Diff line change
@@ -0,0 +1,4 @@
# Global options:

[mypy]
ignore_missing_imports = true
41 changes: 41 additions & 0 deletions sdk/python/kfp/cli/__main__.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,41 @@
# Copyright 2018-2022 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 cli
from kfp.cli import components
from kfp.cli import diagnose_me_cli
from kfp.cli import experiment
from kfp.cli import pipeline
from kfp.cli import recurring_run
from kfp.cli import run


def main():
logging.basicConfig(format='%(message)s', level=logging.INFO)
cli.cli.add_command(run.run)
cli.cli.add_command(recurring_run.recurring_run)
cli.cli.add_command(pipeline.pipeline)
cli.cli.add_command(diagnose_me_cli.diagnose_me)
cli.cli.add_command(experiment.experiment)
cli.cli.add_command(typer.main.get_command(components.app))
try:
cli.cli(obj={}, auto_envvar_prefix='KFP')
except Exception as e:
click.echo(str(e), err=True)
sys.exit(1)
30 changes: 2 additions & 28 deletions sdk/python/kfp/cli/cli.py
Original file line number Diff line number Diff line change
Expand Up @@ -12,22 +12,10 @@
# 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.')
Expand Down Expand Up @@ -58,25 +46,11 @@ def cli(ctx: click.Context, endpoint: str, iap_client_id: str, namespace: str,
Feature stage:
[Alpha](https://github.com/kubeflow/pipelines/blob/07328e5094ac2981d3059314cc848fbb71437a76/docs/release/feature-stages.md#alpha)
"""
if ctx.invoked_subcommand in _NO_CLIENT_COMMANDS:
NO_CLIENT_COMMANDS = ['diagnose_me', 'components']
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 b58a31b

Please sign in to comment.