diff --git a/bonobo/commands/graph.py b/bonobo/commands/graph.py index b8bbdf9..7afa8de 100644 --- a/bonobo/commands/graph.py +++ b/bonobo/commands/graph.py @@ -1,22 +1,32 @@ import json +import itertools + from bonobo.util.objects import get_name -from bonobo.commands.run import read_file +from bonobo.commands.run import read, register_generic_run_arguments from bonobo.constants import BEGIN -def execute(file): - graph, plugins, services = read_file(file) +def execute(filename, module, install=False, quiet=False, verbose=False): + graph, plugins, services = read(filename, module, install, quiet, verbose) print('digraph {') print(' rankdir = LR;') print(' "BEGIN" [shape="point"];') + for i in graph.outputs_of(BEGIN): - print(' "BEGIN" -> ' + json.dumps(get_name(graph.nodes[i])) + ';') + print(' "BEGIN" -> ' + json.dumps(get_name(graph[i])) + ';') + + for ix in graph.topologically_sorted_indexes: + for iy in graph.outputs_of(ix): + print(' {} -> {};'.format( + json.dumps(get_name(graph[ix])), + json.dumps(get_name(graph[iy])) + )) + print('}') def register(parser): - import argparse - parser.add_argument('file', type=argparse.FileType()) + register_generic_run_arguments(parser) return execute diff --git a/bonobo/commands/run.py b/bonobo/commands/run.py index 58cd82d..604fc39 100644 --- a/bonobo/commands/run.py +++ b/bonobo/commands/run.py @@ -40,7 +40,7 @@ def _install_requirements(requirements): importlib.reload(site) -def execute(filename, module, install=False, quiet=False, verbose=False): +def read(filename, module, install=False, quiet=False, verbose=False): import runpy from bonobo import Graph, settings @@ -86,6 +86,12 @@ def execute(filename, module, install=False, quiet=False, verbose=False): filename, context.get(DEFAULT_SERVICES_ATTR)() if DEFAULT_SERVICES_ATTR in context else None ) + return graph, plugins, services + + +def execute(filename, module, install=False, quiet=False, verbose=False): + graph, plugins, services = read(filename, module, install, quiet, verbose) + return bonobo.run( graph, plugins=plugins,