diff --git a/gnes/cli/parser.py b/gnes/cli/parser.py index f19e0d53..da089722 100644 --- a/gnes/cli/parser.py +++ b/gnes/cli/parser.py @@ -56,7 +56,7 @@ 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 @@ -64,7 +64,10 @@ def resolve_yaml_path(path): # 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') diff --git a/gnes/composer/__init__.py b/gnes/composer/__init__.py index a8b8435d..e2c07daa 100644 --- a/gnes/composer/__init__.py +++ b/gnes/composer/__init__.py @@ -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!!! \ No newline at end of file diff --git a/gnes/flow/__init__.py b/gnes/flow/__init__.py index 1549f865..b8ed4622 100644 --- a/gnes/flow/__init__.py +++ b/gnes/flow/__init__.py @@ -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, diff --git a/tests/test_gnes_flow.py b/tests/test_gnes_flow.py index a76ed421..69b15c09 100644 --- a/tests/test_gnes_flow.py +++ b/tests/test_gnes_flow.py @@ -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')