Skip to content
Permalink
Browse files

feat(composer): add composer and mermaid renderer

  • Loading branch information...
hanxiao committed Jul 16, 2019
1 parent d1680e8 commit 033a4b9c65bab6f9c392eedd9c4e3d233d00c3be
@@ -49,7 +49,7 @@ def _import(module_name, class_name):
if class_name in cls2file: if class_name in cls2file:
return getattr(importlib.import_module('gnes.%s.%s' % (module_name, cls2file[class_name])), class_name) return getattr(importlib.import_module('gnes.%s.%s' % (module_name, cls2file[class_name])), class_name)


search_modules = ['encoder', 'indexer', 'preprocessor', 'router', 'module'] search_modules = ['encoder', 'indexer', 'preprocessor', 'router']


for m in search_modules: for m in search_modules:
r = _import(m, name) r = _import(m, name)
@@ -245,7 +245,8 @@ def load_yaml(cls: Type[T], filename: Union[str, TextIO]) -> T:
with open(filename) as fp: with open(filename) as fp:
return yaml.load(fp) return yaml.load(fp)
else: else:
return yaml.load(filename) with filename:
return yaml.load(filename)


@staticmethod @staticmethod
@profiling @profiling
@@ -33,6 +33,24 @@ def set_base_parser():
return parser return parser




def set_composer_parser(parser=None):
if not parser:
parser = set_base_parser()
parser.add_argument('--port',
type=int,
default=8800,
help='host port of the grpc service')
parser.add_argument('--name',
type=str,
default='GNES instance',
help='name of the instance')
parser.add_argument('--yaml_path', type=argparse.FileType('r'),
help='yaml config of the service')
parser.add_argument('--html_path', type=argparse.FileType('w', encoding='utf8'),
help='render the network graph in HTML with mermaid.js')
return parser


def set_service_parser(parser=None): def set_service_parser(parser=None):
from ..service.base import SocketType, BaseService from ..service.base import SocketType, BaseService
if not parser: if not parser:
@@ -127,8 +145,6 @@ def set_indexer_service_parser(parser=None):
if not parser: if not parser:
parser = set_base_parser() parser = set_base_parser()
set_loadable_service_parser(parser) set_loadable_service_parser(parser)
parser.add_argument('--top_k', type=int, default=10,
help='number of top results to retrieve')
parser.set_defaults(yaml_path=pkg_resources.resource_stream( parser.set_defaults(yaml_path=pkg_resources.resource_stream(
'gnes', '/'.join(('resources', 'config', 'indexer', 'default.yml')))) 'gnes', '/'.join(('resources', 'config', 'indexer', 'default.yml'))))


@@ -148,8 +164,8 @@ def _set_grpc_parser(parser=None):
default='0.0.0.0', default='0.0.0.0',
help='host address of the grpc service') help='host address of the grpc service')
parser.add_argument('--grpc_port', parser.add_argument('--grpc_port',
type=str, type=int,
default='8800', default=8800,
help='host port of the grpc service') help='host port of the grpc service')
return parser return parser


@@ -164,7 +180,7 @@ def set_grpc_frontend_parser(parser=None):
return parser return parser




def set_grpc_client_parser(parser=None): def set_cli_client_parser(parser=None):
import sys import sys
if not parser: if not parser:
parser = set_base_parser() parser = set_base_parser()
@@ -216,5 +232,6 @@ def get_main_parser():
set_router_service_parser(sp.add_parser('route', help='start a router service')) set_router_service_parser(sp.add_parser('route', help='start a router service'))
set_preprocessor_service_parser(sp.add_parser('preprocess', help='start a preprocessor service')) set_preprocessor_service_parser(sp.add_parser('preprocess', help='start a preprocessor service'))
set_http_service_parser(sp.add_parser('client_http', help='start a http service')) set_http_service_parser(sp.add_parser('client_http', help='start a http service'))
set_grpc_client_parser(sp.add_parser('client_cli', help='start a grpc client')) set_cli_client_parser(sp.add_parser('client_cli', help='start a grpc client'))
set_composer_parser(sp.add_parser('compose', help='start a GNES composer'))
return parser return parser
No changes.

0 comments on commit 033a4b9

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