Skip to content

Commit

Permalink
fix: update docstring and remove return url
Browse files Browse the repository at this point in the history
  • Loading branch information
CatStark committed Oct 6, 2020
1 parent f36aba8 commit 9b4a5c0
Show file tree
Hide file tree
Showing 2 changed files with 15 additions and 18 deletions.
23 changes: 15 additions & 8 deletions jina/flow/__init__.py
Expand Up @@ -170,7 +170,6 @@ def __init__(self, args: 'argparse.Namespace' = None, **kwargs):
self._build_level = FlowBuildLevel.EMPTY
self._pod_name_counter = 0
self._last_changed_pod = ['gateway'] #: default first pod is gateway, will add when build()
self._url = ''
self._update_args(args, **kwargs)

def _update_args(self, args, **kwargs):
Expand Down Expand Up @@ -790,14 +789,22 @@ def my_reader():
"""
self._get_client(**kwargs).search(input_fn, output_fn, **kwargs)

def plot(self, output='', copy_flow: bool = True) -> 'Flow':
def plot(self, output: str=None, copy_flow: bool = False) -> 'Flow':
"""
Output the mermaid graph for visualization
:return: the flow
"""
Creates a mermaid graph for the Flow.
If a file name is provided it will create a jpg image with that name,
otherwise it will display the URL for mermaid
Example,
.. highlight:: python
.. code-block:: python
flow = Flow().add(name='pod_a').plot('flow_test.jpg')
:param output: a filename specifying the name of the image to be created
:return: the flow
"""

op_flow = copy.deepcopy(self) if copy_flow else self
url = ''

mermaid_graph = ['graph TD']
for node, v in self._pod_nodes.items():
for need in sorted(v.needs):
Expand All @@ -806,7 +813,7 @@ def plot(self, output='', copy_flow: bool = True) -> 'Flow':
if output:
self._mermaidstr_to_jpg(mermaid_str, output)
else:
self._url = self._mermaidstr_to_url(mermaid_str)
url = self._mermaidstr_to_url(mermaid_str)

return op_flow

Expand Down Expand Up @@ -838,7 +845,7 @@ def _mermaidstr_to_jpg(self, mermaid_str, output) -> None:
req = Request('https://mermaid.ink/img/%s' % encoded_str, headers={'User-Agent': 'Mozilla/5.0'})
with open(output, 'wb') as fp:
fp.write(urlopen(req).read())
self.logger.info('done')
self.logger.info('dreturn 'https://mermaidjs.github.io/mermaid-live-editor/#/view/' + encoded_strone')

def dry_run(self, **kwargs):
"""Send a DRYRUN request to this flow, passing through all pods in this flow,
Expand Down
10 changes: 0 additions & 10 deletions tests/unit/flow/test_flow_visualization.py
Expand Up @@ -4,16 +4,6 @@
from jina.flow import Flow


def test_visualization_url():
flow = (Flow().add(name='pod_a')
.add(name='pod_b', needs='gateway')
.join(needs=['pod_a', 'pod_b']).plot())

url_split = flow._url.split('view/') #check that has info after standard URL text

assert url_split is not ' '


def test_visualization_with_yml_file_img(tmpdir):
cur_dir = os.path.dirname(os.path.abspath(__file__))
tmpfile = os.path.join(tmpdir, 'flow_test.jpg')
Expand Down

0 comments on commit 9b4a5c0

Please sign in to comment.