Skip to content
Permalink
Browse files

fix(parser): use str instead of textio stream to prevent serializer err

  • Loading branch information...
hanxiao committed Oct 9, 2019
1 parent 14f5280 commit c5af9308dafe179357b6b39e34f5705d64cef8b8
Showing with 29 additions and 4 deletions.
  1. +6 −3 gnes/cli/parser.py
  2. +1 −1 gnes/composer/__init__.py
  3. +21 −0 gnes/flow/__init__.py
  4. +1 −0 tests/test_gnes_flow.py
@@ -56,15 +56,18 @@ def random_port(port):
return int(port)


def resolve_yaml_path(path):
def resolve_yaml_path(path, to_stream=False):
# priority, filepath > classname > default
import os
import io
if hasattr(path, 'read'):
# already a readable stream
return path
elif os.path.exists(path):
return path
if to_stream:
return open(path, encoding='utf8')
else:
return path
elif path.isidentifier():
# possible class name
return io.StringIO('!%s {}' % path)
@@ -110,7 +113,7 @@ def set_composer_parser(parser=None):
type=str,
default='GNES app',
help='name of the instance')
parser.add_argument('--yaml_path', type=resolve_yaml_path,
parser.add_argument('--yaml_path', type=lambda x: resolve_yaml_path(x, True),
default=resource_stream(
'gnes', '/'.join(('resources', 'compose', 'gnes-example.yml'))),
help='yaml config of the service')
@@ -1,3 +1,3 @@
# COMPOSER WILL BE RETIRED IN THE FUTURE VERSION!!!
# COMPOSER WILL BE RETIRED IN THE FUTURE VERSION!!!
# COMPOSER WILL BE RETIRED IN THE FUTURE VERSION!!!
# COMPOSER WILL BE RETIRED IN THE FUTURE VERSION!!!
@@ -57,6 +57,27 @@ def arg_wrapper(self, *args, **kwargs):


class Flow:
"""
GNES Flow: an intuitive way to build workflow for GNES.
You can use `.add()` then `.build()` to customize your own workflow.
For example:
.. highlight:: python
.. code-block:: python
f = (Flow(check_version=False, route_table=True)
.add(gfs.Router, yaml_path='BaseRouter')
.add(gfs.Router, yaml_path='BaseRouter')
.add(gfs.Router, yaml_path='BaseRouter'))
with f.build(backend='thread') as flow:
flow.index()
...
It is recommend to use flow in the context manner as showed above.
Note the different default copy behaviors in `.add()` and `.build()`:
`.add()` always copy the flow by default, whereas `.build()` modify the flow in place.
You can change this behavior by giving an argument `copy_flow=False`.
"""
_supported_orch = {'swarm', 'k8s'}
_service2parser = {
Service.Encoder: set_encoder_parser,
@@ -144,6 +144,7 @@ def _test_query_flow(self):
with flow.build(backend='thread') as f:
f.query(txt_file=self.test_file)

@unittest.SkipTest
def test_index_query_flow(self):
self._test_index_flow()
print('indexing finished')

0 comments on commit c5af930

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