Skip to content

Commit

Permalink
Fix --fail-graph when there is indirect cycles (AcademySoftwareFounda…
Browse files Browse the repository at this point in the history
…tion#1620)

Fix --fail-graph when there is indirect cycles (AcademySoftwareFoundation#1620)

Signed-off-by: Michael Nowakowski <m_nowakowski@apple.com>
Signed-off-by: Jean-Christophe Morin <jean_christophe_morin@hotmail.com>
Co-authored-by: Jean-Christophe Morin <jean_christophe_morin@hotmail.com>
Signed-off-by: Jose Enriquez <jose.enriquez@barnstormvfx.com>
  • Loading branch information
2 people authored and Jose Enriquez committed Feb 14, 2024
1 parent 1105bbf commit dccddda
Show file tree
Hide file tree
Showing 2 changed files with 51 additions and 2 deletions.
49 changes: 49 additions & 0 deletions src/rez/tests/test_utils_resolve_graph.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,49 @@
# SPDX-License-Identifier: Apache-2.0
# Copyright Contributors to the Rez Project


"""
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

0 comments on commit dccddda

Please sign in to comment.