From 981a36d5a3b53089bf50317a7c74caa83f6ae8b7 Mon Sep 17 00:00:00 2001 From: Julian Giamblanco Date: Fri, 24 Apr 2020 08:56:45 -0700 Subject: [PATCH 1/5] Change Graph.__getitem__ to shorthand for get_cursor --- bonobo/structs/graphs.py | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/bonobo/structs/graphs.py b/bonobo/structs/graphs.py index 103ee06f..acc35154 100644 --- a/bonobo/structs/graphs.py +++ b/bonobo/structs/graphs.py @@ -102,8 +102,8 @@ def __len__(self): """ return len(self.nodes) - def __getitem__(self, key): - return self.nodes[key] + def __getitem__(self, ref): + return self.get_cursor(ref) def __enter__(self): return self.get_cursor().__enter__() From b2ee474366cf96dc907de4a314155f0406863791 Mon Sep 17 00:00:00 2001 From: Julian Giamblanco Date: Thu, 30 Apr 2020 07:42:39 -0700 Subject: [PATCH 2/5] Use Graph.nodes[] instead of Graph.__getitem__ --- tests/structs/test_graphs.py | 10 +++++----- 1 file changed, 5 insertions(+), 5 deletions(-) diff --git a/tests/structs/test_graphs.py b/tests/structs/test_graphs.py index 5dcb10fb..273c8dc2 100644 --- a/tests/structs/test_graphs.py +++ b/tests/structs/test_graphs.py @@ -90,16 +90,16 @@ def test_graph_topological_sort(): g.add_chain(a1, a2, a3, _input=None, _output=None) assert g.topologically_sorted_indexes == (0, 1, 2) - assert g[0] == a1 - assert g[1] == a2 - assert g[2] == a3 + assert g.nodes[0] == a1 + assert g.nodes[1] == a2 + assert g.nodes[2] == a3 g.add_chain(b1, b2, _output=a2) assert g.topologically_sorted_indexes[-2:] == (1, 2) assert g.topologically_sorted_indexes.index(3) < g.topologically_sorted_indexes.index(4) - assert g[3] == b1 - assert g[4] == b2 + assert g.nodes[3] == b1 + assert g.nodes[4] == b2 def test_connect_two_chains(): From 4ed2beee22be0e13d68894454196fdb3e2dc369a Mon Sep 17 00:00:00 2001 From: Julian Giamblanco Date: Fri, 1 May 2020 11:41:13 -0700 Subject: [PATCH 3/5] Replace test uses of get_cursor with __getitem__ --- tests/structs/test_graphs_new_syntax.py | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/tests/structs/test_graphs_new_syntax.py b/tests/structs/test_graphs_new_syntax.py index 0009d684..32ee9fc3 100644 --- a/tests/structs/test_graphs_new_syntax.py +++ b/tests/structs/test_graphs_new_syntax.py @@ -18,7 +18,7 @@ def test_get_cursor(): def test_get_cursor_in_a_vacuum(): g = Graph() - cursor = g.get_cursor(None) + cursor = g[None] assert cursor.graph is g assert cursor.first is None @@ -71,7 +71,7 @@ def test_cursor_to_fork_a_graph(): g = Graph() g >> a >> b >> c - g.get_cursor(b) >> d >> e + g[b] >> d >> e assert len(g) == 5 assert g.outputs_of(BEGIN) == {g.index_of(a)} From 849a56362cdad27bc4889b59ed34dbf818f115e3 Mon Sep 17 00:00:00 2001 From: Julian Giamblanco Date: Fri, 1 May 2020 12:12:17 -0700 Subject: [PATCH 4/5] Replace old use of Graph[i] with Graph.nodes[i] --- bonobo/structs/graphs.py | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/bonobo/structs/graphs.py b/bonobo/structs/graphs.py index acc35154..46a5750d 100644 --- a/bonobo/structs/graphs.py +++ b/bonobo/structs/graphs.py @@ -313,7 +313,7 @@ def graphviz(self): for i in self.outputs_of(BEGIN): g.edge("BEGIN", str(i)) for ix in self.topologically_sorted_indexes: - g.node(str(ix), label=get_name(self[ix])) + g.node(str(ix), label=get_name(self.nodes[ix])) for iy in self.outputs_of(ix): g.edge(str(ix), str(iy)) self._graphviz = g From 416759c23c7e236a6b56fe758e9d87cb05485834 Mon Sep 17 00:00:00 2001 From: Julian Giamblanco Date: Fri, 1 May 2020 12:12:17 -0700 Subject: [PATCH 5/5] Replace old use of Graph[i] with Graph.nodes[i] --- bonobo/structs/graphs.py | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/bonobo/structs/graphs.py b/bonobo/structs/graphs.py index acc35154..cca65ff9 100644 --- a/bonobo/structs/graphs.py +++ b/bonobo/structs/graphs.py @@ -313,7 +313,7 @@ def graphviz(self): for i in self.outputs_of(BEGIN): g.edge("BEGIN", str(i)) for ix in self.topologically_sorted_indexes: - g.node(str(ix), label=get_name(self[ix])) + g.node(str(ix), label=get_name(self.nodes[ix])) for iy in self.outputs_of(ix): g.edge(str(ix), str(iy)) self._graphviz = g @@ -331,5 +331,5 @@ def _repr_html_(self): def _get_graphviz_node_id(graph, i): escaped_index = str(i) - escaped_name = json.dumps(get_name(graph[i])) + escaped_name = json.dumps(get_name(graph.nodes[i])) return "{{{} [label={}]}}".format(escaped_index, escaped_name)