From d7ac3f897de9ab83256e343610e4e91db32ac2b2 Mon Sep 17 00:00:00 2001 From: Kaushik Kulkarni Date: Tue, 2 Jun 2020 01:29:47 -0500 Subject: [PATCH 1/2] raise CycleError with a cyclic path --- pytools/graph.py | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/pytools/graph.py b/pytools/graph.py index 3ae19a6..4c06891 100644 --- a/pytools/graph.py +++ b/pytools/graph.py @@ -209,7 +209,7 @@ def compute_topological_order(graph): for child in children: # note: each iteration removes child from children if child in visiting: - raise CycleError() + raise CycleError("Cycle: {}".format(visiting)) if child in visited: continue -- GitLab From 72c06d595950b282f6058ce0146696f5deb78434 Mon Sep 17 00:00:00 2001 From: Kaushik Kulkarni Date: Tue, 2 Jun 2020 16:44:46 -0500 Subject: [PATCH 2/2] cycle error only contains one node in a cyclic path --- pytools/graph.py | 11 ++++++++--- 1 file changed, 8 insertions(+), 3 deletions(-) diff --git a/pytools/graph.py b/pytools/graph.py index 4c06891..49c8f64 100644 --- a/pytools/graph.py +++ b/pytools/graph.py @@ -169,8 +169,13 @@ def compute_sccs(graph): # {{{ compute topological order class CycleError(Exception): - """Raised when a topological ordering cannot be computed due to a cycle.""" - pass + """ + Raised when a topological ordering cannot be computed due to a cycle. + + :attr node: Node in a directed graph that is part of a cycle. + """ + def __init__(self, node): + self.node = node def compute_topological_order(graph): @@ -209,7 +214,7 @@ def compute_topological_order(graph): for child in children: # note: each iteration removes child from children if child in visiting: - raise CycleError("Cycle: {}".format(visiting)) + raise CycleError(child) if child in visited: continue -- GitLab