From b9bddd223b96c6f55de32b13dde1e3be3abab5dd Mon Sep 17 00:00:00 2001 From: Han Xiao Date: Wed, 17 Aug 2022 12:37:11 +0200 Subject: [PATCH] fix(cli): jina auth cli error (#5070) * fix(cli): jina auth cli error * style: fix overload and cli autocomplete Co-authored-by: Jina Dev Bot --- extra-requirements.txt | 2 +- jina/parsers/__init__.py | 22 +++++++++++----------- jina/parsers/base.py | 6 +++--- jina/resources/extra-requirements.txt | 2 +- jina_cli/__init__.py | 2 +- jina_cli/api.py | 10 ++++++++++ jina_cli/autocomplete.py | 16 ++++++++-------- tests/unit/test_cli.py | 2 +- 8 files changed, 36 insertions(+), 26 deletions(-) diff --git a/extra-requirements.txt b/extra-requirements.txt index 3928c4eab8c7e..b8cecb9e4b2ef 100644 --- a/extra-requirements.txt +++ b/extra-requirements.txt @@ -33,7 +33,7 @@ grpcio-health-checking>=1.46.0: core pyyaml>=5.3.1: core packaging>=20.0: core docarray>=0.13.14: core -jina-hubble-sdk>=0.12.1: core +jina-hubble-sdk>=0.12.2: core uvloop: perf,standard,devel prometheus_client: perf,standard,devel fastapi>=0.76.0: standard,devel diff --git a/jina/parsers/__init__.py b/jina/parsers/__init__.py index c218df963a1db..40f8be63c7a8d 100644 --- a/jina/parsers/__init__.py +++ b/jina/parsers/__init__.py @@ -238,6 +238,17 @@ def get_main_parser(): ) ) + from hubble.parsers import get_main_parser as get_hubble_parser + + get_hubble_parser( + sp.add_parser( + 'auth', + description='Login to Jina AI with your GitHub/Google/Email account', + formatter_class=_chf, + help='Login to Jina AI', + ) + ) + set_help_parser( sp.add_parser( 'help', @@ -279,15 +290,4 @@ def get_main_parser(): ) ) - from hubble.parsers import get_main_parser as get_hubble_parser - - get_hubble_parser( - sp.add_parser( - 'auth', - description='Login to Jina AI with your GitHub/Google/Email account', - formatter_class=_chf, - help='Login to Jina AI', - ) - ) - return parser diff --git a/jina/parsers/base.py b/jina/parsers/base.py index 0b262bd02b34d..388a2993c98c6 100644 --- a/jina/parsers/base.py +++ b/jina/parsers/base.py @@ -14,10 +14,10 @@ def set_base_parser(): # create the top-level parser urls = { - 'Code': ('💻', 'https://github.com/jina-ai/jina'), + 'Code': ('💻', 'https://oss.jina.ai'), 'Docs': ('📖', 'https://docs.jina.ai'), 'Help': ('💬', 'https://slack.jina.ai'), - 'Hiring!': ('🙌', 'https://career.jina.ai'), + 'Hiring!': ('🙌', 'https://jobs.jina.ai'), } url_str = '\n'.join( f'- {v[0]:<10} {k:10.10}\t{colored(v[1], "cyan", attrs=["underline"])}' @@ -26,7 +26,7 @@ def set_base_parser(): parser = argparse.ArgumentParser( epilog=f''' -Jina (v{colored(__version__, "green")}) is the cloud-native neural search framework powered by deep learning. +Jina v{colored(__version__, "green")}: build cross-modal and multimodal applications on the cloud. {url_str} diff --git a/jina/resources/extra-requirements.txt b/jina/resources/extra-requirements.txt index 3928c4eab8c7e..b8cecb9e4b2ef 100644 --- a/jina/resources/extra-requirements.txt +++ b/jina/resources/extra-requirements.txt @@ -33,7 +33,7 @@ grpcio-health-checking>=1.46.0: core pyyaml>=5.3.1: core packaging>=20.0: core docarray>=0.13.14: core -jina-hubble-sdk>=0.12.1: core +jina-hubble-sdk>=0.12.2: core uvloop: perf,standard,devel prometheus_client: perf,standard,devel fastapi>=0.76.0: standard,devel diff --git a/jina_cli/__init__.py b/jina_cli/__init__.py index c7f9deabcfc92..3c77211dfce94 100644 --- a/jina_cli/__init__.py +++ b/jina_cli/__init__.py @@ -10,7 +10,7 @@ def _get_run_args(print_args: bool = True): console = get_rich_console() - silent_print = {'help', 'hub', 'export'} + silent_print = {'help', 'hub', 'export', 'auth'} parser = get_main_parser() if len(sys.argv) > 1: diff --git a/jina_cli/api.py b/jina_cli/api.py index fd34b795244ea..7930f697f99c1 100644 --- a/jina_cli/api.py +++ b/jina_cli/api.py @@ -210,3 +210,13 @@ def help(args: 'Namespace'): from jina_cli.lookup import lookup_and_print lookup_and_print(args.query.lower()) + + +def auth(args: 'Namespace'): + """ + Authenticate a user + :param args: arguments coming from the CLI. + """ + from hubble import api + + getattr(api, args.cli2.replace('-', '_'))(args) diff --git a/jina_cli/autocomplete.py b/jina_cli/autocomplete.py index fc7db3b918008..bdb8b5b97bcba 100644 --- a/jina_cli/autocomplete.py +++ b/jina_cli/autocomplete.py @@ -11,11 +11,11 @@ 'new', 'gateway', 'hub', + 'auth', 'help', 'pod', 'deployment', 'client', - 'auth', ], 'completions': { 'executor': [ @@ -183,6 +183,13 @@ '--force', ], 'hub': ['--help', 'new', 'push', 'pull'], + 'auth login': ['--help', '--force'], + 'auth logout': ['--help'], + 'auth token create': ['--help', '--expire'], + 'auth token delete': ['--help'], + 'auth token list': ['--help'], + 'auth token': ['--help', 'create', 'delete', 'list'], + 'auth': ['--help', 'login', 'logout', 'token'], 'help': ['--help'], 'pod': [ '--help', @@ -306,12 +313,5 @@ '--return-responses', '--protocol', ], - 'auth login': ['--help', '--force'], - 'auth logout': ['--help'], - 'auth token create': ['--help', '--expire'], - 'auth token delete': ['--help'], - 'auth token list': ['--help'], - 'auth token': ['--help', 'create', 'delete', 'list'], - 'auth': ['--help', 'login', 'logout', 'token'], }, } diff --git a/tests/unit/test_cli.py b/tests/unit/test_cli.py index f589fb878c94d..d6149f0cd3fbd 100644 --- a/tests/unit/test_cli.py +++ b/tests/unit/test_cli.py @@ -28,7 +28,7 @@ def test_help_lookup(cli, capsys): assert cli in nkw2kw lookup_and_print(cli) captured = capsys.readouterr() - assert captured.out + assert 'Traceback (most recent call last)' not in captured.out def test_main_cli():