Skip to content
This repository has been archived by the owner on Feb 22, 2020. It is now read-only.

Commit

Permalink
fix(compose): fix import
Browse files Browse the repository at this point in the history
  • Loading branch information
hanhxiao committed Jul 19, 2019
1 parent 9bbb3c0 commit 69a486e
Show file tree
Hide file tree
Showing 2 changed files with 12 additions and 13 deletions.
16 changes: 8 additions & 8 deletions gnes/cli/parser.py
Original file line number Diff line number Diff line change
Expand Up @@ -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')

Expand All @@ -133,21 +133,21 @@ 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)
return parser


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)
Expand All @@ -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
Expand Down
9 changes: 4 additions & 5 deletions gnes/composer/base.py
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down Expand Up @@ -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 = {}
Expand Down Expand Up @@ -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
Expand Down Expand Up @@ -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:
Expand Down

0 comments on commit 69a486e

Please sign in to comment.