Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Exporting graph in JSON format via output-raw cli command #955

Merged
merged 1 commit into from
Feb 24, 2022
Merged
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
18 changes: 15 additions & 3 deletions metaflow/cli.py
Original file line number Diff line number Diff line change
Expand Up @@ -174,10 +174,22 @@ def help(ctx):


@cli.command(help="Output internal state of the flow graph.")
@click.option("--json", is_flag=True, help="Output the flow graph in JSON format.")
@click.pass_obj
def output_raw(obj):
echo("Internal representation of the flow:", fg="magenta", bold=False)
echo_always(str(obj.graph), err=False)
def output_raw(obj, json):
if json:
import json as _json

_msg = "Internal representation of the flow in JSON format:"
_graph_dict, _graph_struct = obj.graph.output_steps()
_graph = _json.dumps(
dict(graph=_graph_dict, graph_structure=_graph_struct), indent=4
)
else:
_graph = str(obj.graph)
_msg = "Internal representation of the flow:"
echo(_msg, fg="magenta", bold=False)
echo_always(_graph, err=False)


@cli.command(help="Visualize the flow with Graphviz.")
Expand Down