Improve error message when the graph contains cyclic dependencies
Creates a more helpful exception when trying to compose a graph with cyclic dependencies.
Example message: (helpful part at the bottom)
Traceback (most recent call last):
File "<stdin>", line 1, in <module>
NameError: name 'op3' is not defined
>>> graph = compose(name="graph")(op1, op2, op4)
Traceback (most recent call last):
File "/home/jeremyiv/Documents/graphkit-1/graphkit/network.py", line 119, in compile
ordered_nodes = list(nx.dag.topological_sort(self.graph))
File "/home/jeremyiv/anaconda3/lib/python3.8/site-packages/networkx/algorithms/dag.py", line 210, in topological_sort
raise nx.NetworkXUnfeasible("Graph contains a cycle or graph changed "
networkx.exception.NetworkXUnfeasible: Graph contains a cycle or graph changed during iteration
During handling of the above exception, another exception occurred:
Traceback (most recent call last):
File "<stdin>", line 1, in <module>
File "/home/jeremyiv/Documents/graphkit-1/graphkit/functional.py", line 209, in __call__
net.compile()
File "/home/jeremyiv/Documents/graphkit-1/graphkit/network.py", line 126, in compile
raise Exception(f"Cyclic dependency in graph:\n{_format_cycle(cycle)}")
Exception: Cyclic dependency in graph:
op1 needs "a" from op4.
op4 needs "c" from op1.
I confirm that this contribution is made under the terms of the license found in the root directory of this repository's source tree and that I have the authority necessary to make this contribution on behalf of its copyright owner.
Great!
I would raise the same exception type `networkx.exception.NetworkXUnfeasible.
Ok, made the change. It throws the same NetworkXUnfeasible exception now.
Just to be lcear, have no saying i this project.
Ah... Is this project maintained anymore? Are there better maintained alternatives?
I submitted a lot of fixes and enhancements in #22 (and other issues) a couple of years ago, that were not addressed. Eentually i forked it into https://graphtik.readthedocs.io/.