From 69a486e5092d0e5b7b0e84a907cd5a9294dc01b9 Mon Sep 17 00:00:00 2001 From: hanhxiao Date: Fri, 19 Jul 2019 14:28:09 +0800 Subject: [PATCH] fix(compose): fix import --- gnes/cli/parser.py | 16 ++++++++-------- gnes/composer/base.py | 9 ++++----- 2 files changed, 12 insertions(+), 13 deletions(-) diff --git a/gnes/cli/parser.py b/gnes/cli/parser.py index e71b2e42..c90a5f56 100644 --- a/gnes/cli/parser.py +++ b/gnes/cli/parser.py @@ -116,12 +116,12 @@ def _set_client_parser(parser=None): def set_loadable_service_parser(parser=None): if not parser: parser = set_base_parser() - import pkg_resources + from pkg_resources import resource_stream from ..service.base import SocketType set_service_parser(parser) parser.add_argument('--yaml_path', type=argparse.FileType('r'), - default=pkg_resources.resource_stream( + default=resource_stream( 'gnes', '/'.join(('resources', 'config', 'encoder', 'default.yml'))), help='yaml config of the service') @@ -133,9 +133,9 @@ def set_loadable_service_parser(parser=None): def set_preprocessor_service_parser(parser=None): if not parser: parser = set_base_parser() - import pkg_resources + from pkg_resources import resource_stream set_loadable_service_parser(parser) - parser.set_defaults(yaml_path=pkg_resources.resource_stream( + parser.set_defaults(yaml_path=resource_stream( 'gnes', '/'.join(('resources', 'config', 'preprocessor', 'default.yml')))) parser.set_defaults(read_only=True) @@ -143,11 +143,11 @@ def set_preprocessor_service_parser(parser=None): def set_router_service_parser(parser=None): - import pkg_resources + from pkg_resources import resource_stream if not parser: parser = set_base_parser() set_loadable_service_parser(parser) - parser.set_defaults(yaml_path=pkg_resources.resource_stream( + parser.set_defaults(yaml_path=resource_stream( 'gnes', '/'.join(('resources', 'config', 'router', 'default.yml')))) parser.set_defaults(read_only=True) @@ -156,12 +156,12 @@ def set_router_service_parser(parser=None): def set_indexer_service_parser(parser=None): from ..service.base import SocketType - import pkg_resources + from pkg_resources import resource_stream if not parser: parser = set_base_parser() set_loadable_service_parser(parser) - parser.set_defaults(yaml_path=pkg_resources.resource_stream( + parser.set_defaults(yaml_path=resource_stream( 'gnes', '/'.join(('resources', 'config', 'indexer', 'default.yml')))) # encoder's port_out is indexer's port_in diff --git a/gnes/composer/base.py b/gnes/composer/base.py index 603c5ce7..cf0e04ad 100644 --- a/gnes/composer/base.py +++ b/gnes/composer/base.py @@ -4,7 +4,7 @@ from collections import defaultdict from typing import Dict, List -import pkg_resources +from pkg_resources import resource_stream from ruamel.yaml import YAML, StringIO from ruamel.yaml.comments import CommentedMap from termcolor import colored @@ -140,7 +140,7 @@ def build_layers(self) -> List['YamlGraph.Layer']: @staticmethod def build_dockerswarm(all_layers: List['YamlGraph.Layer'], docker_img: str = 'gnes/gnes:latest', volumes: Dict = None, networks: Dict = None) -> str: - with pkg_resources.resource_stream('gnes', '/'.join(('resources', 'compose', 'gnes-swarm.yml'))) as r: + with resource_stream('gnes', '/'.join(('resources', 'compose', 'gnes-swarm.yml'))) as r: swarm_lines = _yaml.load(r) taboo = {'name', 'replicas', 'yaml_path'} config_dict = {} @@ -233,8 +233,7 @@ def build_shell(all_layers: List['YamlGraph.Layer'], log_redirect: str = None) - shell_lines.append('gnes %s %s %s &' % ( cmd, args, '>> %s 2>&1' % log_redirect if log_redirect else '')) - r = pkg_resources.resource_stream('gnes', '/'.join(('resources', 'compose', 'gnes-shell.sh'))) - with r: + with resource_stream('gnes', '/'.join(('resources', 'compose', 'gnes-shell.sh'))) as r: return r.read().decode().replace('{{gnes-template}}', '\n'.join(shell_lines)) @staticmethod @@ -282,7 +281,7 @@ def build_mermaid(all_layers: List['YamlGraph.Layer'], mermaid_leftright: bool = @staticmethod def build_html(generate_dict: Dict[str, str]) -> str: - with pkg_resources.resource_stream('gnes', '/'.join(('resources', 'compose', 'gnes-board.html'))) as r: + with resource_stream('gnes', '/'.join(('resources', 'compose', 'gnes-board.html'))) as r: html = r.read().decode() for k, v in generate_dict.items(): if v: