From 3094e43f9fb75e502a3b5c1dde85670c8dd94790 Mon Sep 17 00:00:00 2001 From: Romain Dorgueil Date: Sun, 29 Jul 2018 16:17:31 +0100 Subject: [PATCH] feat: implements right shift operator to provide an interface similar to airflow. --- bonobo/structs/graphs.py | 13 +++++++++++++ 1 file changed, 13 insertions(+) diff --git a/bonobo/structs/graphs.py b/bonobo/structs/graphs.py index 4cc939b..62ccacb 100644 --- a/bonobo/structs/graphs.py +++ b/bonobo/structs/graphs.py @@ -11,6 +11,16 @@ from bonobo.util import get_name GraphRange = namedtuple('GraphRange', ['graph', 'input', 'output']) +class GraphCursor: + def __init__(self, graph, node): + self.graph = graph + self.node = node + + def __rshift__(self, other): + """ Self >> Other """ + chain = self.graph.add_chain(other, _input=self.node) + return GraphCursor(chain.graph, chain.output) + class Graph: """ @@ -35,6 +45,9 @@ class Graph: def __getitem__(self, key): return self.nodes[key] + def get_cursor(self, ref=BEGIN): + return GraphCursor(self, self._resolve_index(ref)) + def outputs_of(self, idx, create=False): """ Get a set of the outputs for a given node index. """