Skip to content
Permalink
Browse files

fix(cli): fix cli client required

  • Loading branch information...
hanxiao committed Sep 12, 2019
1 parent 1d87dfc commit 563a48c7a2f3a98e1f0eef09267f50c96667704f
@@ -17,6 +17,29 @@
import argparse


class ActionNoYes(argparse.Action):
def __init__(self, option_strings, dest, default=None, required=False, help=None):

if default is None:
raise ValueError('you must provide a default with yes/no action')
if len(option_strings) != 1:
raise ValueError('only single argument is allowed with yes/no action')
opt = option_strings[0]
if not opt.startswith('--'):
raise ValueError('yes/no arguments must be prefixed with --')

opt = opt[2:]
opts = ['--' + opt, '--no-' + opt]
super(ActionNoYes, self).__init__(opts, dest, nargs=0, const=None,
default=default, required=required, help=help)

def __call__(self, parser, namespace, values, option_strings=None):
if option_strings.startswith('--no-'):
setattr(namespace, self.dest, False)
else:
setattr(namespace, self.dest, True)


def resolve_py_path(path):
import os
if not os.path.exists(path):
@@ -54,7 +77,8 @@ def set_base_parser():
'It enables large-scale index and semantic search for text-to-text, image-to-image, '
'video-to-video and any content form. Visit %s for tutorials and documentations.' % (
colored('GNES v%s: Generic Neural Elastic Search' % __version__, 'green'),
colored('https://gnes.ai', 'cyan', attrs=['underline'])))
colored('https://gnes.ai', 'cyan', attrs=['underline'])),
formatter_class=argparse.ArgumentDefaultsHelpFormatter)
parser.add_argument('-v', '--version', action='version', version='%(prog)s ' + __version__)
parser.add_argument('--verbose', action='store_true', default=False,
help='turn on detailed logging for debug')
@@ -152,7 +176,7 @@ def set_service_parser(parser=None):
parser.add_argument('--parallel_type', type=ParallelType.from_string, choices=list(ParallelType),
default=ParallelType.PUSH_NONBLOCK,
help='parallel type of the concurrent services')
parser.add_argument('--check_version', action='store_true', default=False,
parser.add_argument('--check_version', action=ActionNoYes, default=True,
help='comparing the GNES and proto version of incoming message with local setup, '
'mismatch raise an exception')
parser.add_argument('--identity', type=str, default=str(uuid.uuid4()).split('-')[0],
@@ -283,7 +307,7 @@ def set_frontend_parser(parser=None):
read_only=True)
parser.add_argument('--max_concurrency', type=int, default=10,
help='maximum concurrent connections allowed')
parser.add_argument('--show_route_table', action='store_true', default=False,
parser.add_argument('--route_table', action=ActionNoYes, default=True,
help='showing a route table with time cost after receiving the result')
return parser

@@ -77,7 +77,7 @@ def remove_envelope(self, m: 'gnes_pb2.Message'):
resp = m.response
resp.request_id = m.envelope.request_id
m.envelope.routes[0].end_time.GetCurrentTime()
if self.args.show_route_table:
if self.args.route_table:
self.logger.info('route: %s' % router2str(m))
route_time = []
k = m.envelope.routes[0]
@@ -22,7 +22,7 @@ def test_cli(self):
])

args = set_frontend_parser().parse_args([
'--show_route_table'

])

p_args = set_router_parser().parse_args([
@@ -33,7 +33,7 @@ def setUp(self):
def test_pymode(self):
os.unsetenv('http_proxy')
os.unsetenv('https_proxy')
args = set_frontend_parser().parse_args(['--show_route_table'])
args = set_frontend_parser().parse_args([])

p_args = set_preprocessor_parser().parse_args([
'--port_in', str(args.port_out),
@@ -56,7 +56,7 @@ def setUp(self):
'--grpc_port', '9999',
'--port_in', str(self.s_args.port_out),
'--port_out', str(self.s_args.port_in),
'--show_route_table'

])

def test_grpc_empty_service(self):
@@ -31,7 +31,7 @@ def _test_multiple_router(self, backend='thread', num_parallel=5):
def _test_grpc_multiple_router(self, backend='thread', num_parallel=5):
args = set_frontend_parser().parse_args([
'--grpc_host', '127.0.0.1',
'--show_route_table'

])

p_args = set_router_parser().parse_args([
@@ -55,7 +55,7 @@ def _test_grpc_multiple_router(self, backend='thread', num_parallel=5):
def _test_grpc_multiple_pub(self, backend='thread', num_parallel=5):
args = set_frontend_parser().parse_args([
'--grpc_host', '127.0.0.1',
'--show_route_table'

])

p_args = set_router_parser().parse_args([
@@ -44,7 +44,7 @@ def setUp(self):
def test_bm_frontend(self):
args = set_frontend_parser().parse_args([
'--grpc_host', '127.0.0.1',
'--show_route_table'

])

p_args = set_router_parser().parse_args([
@@ -65,7 +65,7 @@ def test_bm_frontend(self):
def test_grpc_frontend(self):
args = set_frontend_parser().parse_args([
'--grpc_host', '127.0.0.1',
'--show_route_table'

])

p_args = set_router_parser().parse_args([

0 comments on commit 563a48c

Please sign in to comment.
You can’t perform that action at this time.