Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Fix --fail-graph when there is indirect cycles #1620

Merged
Show file tree
Hide file tree
Changes from 2 commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
45 changes: 45 additions & 0 deletions src/rez/tests/test_utils_resolve_graph.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,45 @@
"""
unit tests for 'utils.resolve_graph' module
"""
from rez.tests.util import TestBase
from rez.utils import resolve_graph
import rez.utils.graph_utils
import unittest


class TestResolveGraph(TestBase):
def test_conflict_graph_with_cycle(self):
""" Tests creating a test digraph which contains a cycle foo-1.0.0 => bar-0.0.1 => !foo-1.0.0
Note that the solver doesn't detect this as a cycle. See #1568
"""

g = '''
digraph g {
_1 [label="foo-1", fontsize="10", fillcolor="#FFFFAA", style="filled,dashed"];
_2 [label="bar", fontsize="10", fillcolor="#FFFFAA", style="filled,dashed"];
_6 [label="foo-1.0.0[]", fontsize="10", fillcolor="#AAFFAA", style="filled"];
_7 [label="bar-0.0.1[]", fontsize="10", fillcolor="#AAFFAA", style="filled"];
_8 [label="!foo-1.0.0", fontsize="10", fillcolor="#F6F6F6", style="filled,dashed"];
_1 -> _6 [arrowsize="0.5"];
_2 -> _7 [arrowsize="0.5"];
_6 -> _2 [arrowsize="0.5"];
_7 -> _8 [arrowsize="0.5"];
_8 -> _6 [arrowsize="1", style="bold", color="red", fontcolor="red", label=CONFLICT];
}
'''
graph = rez.utils.graph_utils.read_graph_from_string(g)
# strip extra quoting from fill color
for k, v in graph.node_attr.items():
for index, a in enumerate(v):
if a[0] == "fillcolor":
stripped_color = a[1].strip("'").strip('"')
v[index] = ("fillcolor", stripped_color)

# attempt to graph result
result = resolve_graph.failure_detail_from_graph(graph)
self.assertTrue("foo-1 --> foo-1.0.0 --> bar-0.0.1 --> !foo-1.0.0" in result)
self.assertTrue("bar --> bar-0.0.1 --> !foo-1.0.0" in result)


if __name__ == '__main__':
unittest.main()
4 changes: 2 additions & 2 deletions src/rez/utils/resolve_graph.py
Original file line number Diff line number Diff line change
Expand Up @@ -53,7 +53,7 @@ def _cycled_detail_from_graph(graph, cycled_edge):
visited = list()
while True:
visited.append(node)
down = next((ne for ne in graph.node_neighbors[node]), None)
down = next((ne for ne in graph.node_neighbors[node] if ne not in visited), None)
if down in cycled_edge:
visited.append(down)
break
Expand Down Expand Up @@ -83,7 +83,7 @@ def _conflicted_detail_from_graph(graph, conflicted_edge):
visited = list()
while True:
visited.append(node)
down = next((ne for ne in graph.node_neighbors[node]), None)
down = next((ne for ne in graph.node_neighbors[node] if ne not in visited), None)
if down is None:
break

Expand Down
Loading