Skip to content

Commit

Permalink
Fix conan graph info --format=html reporting misleading conflicting…
Browse files Browse the repository at this point in the history
… nodes (conan-io#15196)

* Fix graph info --format=html conflict report misleading nodes

* Add node map test
  • Loading branch information
AbrilRBS authored Dec 1, 2023
1 parent 3f3fd45 commit dc98b6a
Show file tree
Hide file tree
Showing 3 changed files with 14 additions and 10 deletions.
5 changes: 3 additions & 2 deletions conan/cli/formatters/graph/graph.py
Original file line number Diff line number Diff line change
Expand Up @@ -54,7 +54,8 @@ def data(self):
class _Grapher(object):
def __init__(self, deps_graph):
self._deps_graph = deps_graph
self.nodes, self.edges = self._build_graph()
self.node_map, self.edges = self._build_graph()
self.nodes = self.node_map.values()

def _build_graph(self):
graph_nodes = self._deps_graph.by_levels()
Expand All @@ -73,7 +74,7 @@ def _build_graph(self):
dst = _node_map[node_to]
edges.append((src, dst))

return _node_map.values(), edges
return _node_map, edges

@staticmethod
def binary_color(node):
Expand Down
16 changes: 8 additions & 8 deletions conan/cli/formatters/graph/info_graph_html.py
Original file line number Diff line number Diff line change
Expand Up @@ -56,7 +56,7 @@
font: { color: "{% if highlight_node %}white{% else %}black{% endif %}" },
fulllabel: '<h3>{{ node.label }}</h3>' +
'<ul>' +
' <li><b>id</b>: {{ node.package_id }}</li>' +
' <li><b>package id</b>: {{ node.package_id }}</li>' +
{%- for key, value in node.data().items() %}
{%- if value %}
{%- if key in ['url', 'homepage'] %}
Expand Down Expand Up @@ -92,22 +92,22 @@
{% if error["context"].node.id is not none %}
// Add edge from node that introduces the conflict to the new error node
edges.push({from: {{ error["context"].node.id }},
edges.push({from: {{ graph.node_map[error["context"].node].id }},
to: "{{ error["type"] }}",
color: "red",
dashes: true,
dashes: false,
title: "Conflict",
physics: false,
color: "red",
arrows: "to;from"})
arrows: "to"})
{% endif %}
{% if error["context"].prev_node is none and error["context"].base_previous.id is not none %}
// Add edge from base node to the new error node
edges.push({from: {{ error["context"].base_previous.id }},
edges.push({from: {{ graph.node_map[error["context"].base_previous].id }},
to: "{{ error["type"] }}",
color: "red",
dashes: true,
dashes: false,
title: "Conflict",
physics: false,
color: "red",
Expand All @@ -116,13 +116,13 @@
{% if error["context"].prev_node is not none and error["context"].prev_node.id is not none %}
// Add edge from previous node that already had conflicting dependency
edges.push({from: {{ error["context"].prev_node.id }},
edges.push({from: {{ graph.node_map[error["context"].prev_node].id }},
to: "{{ error["type"] }}",
color: "red",
dashes: true,
title: "Conflict",
physics: false,
color: "red",
color: "gray",
arrows: "to;from"})
{% endif %}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -201,6 +201,9 @@ def test_graph_info_html_output():
assert "// Add edge from base node to the new error node" not in tc.out
assert "// Add edge from previous node that already had conflicting dependency" in tc.out

# Ensure mapping is preserved, ui is node id 3 before ordering, but 2 after
assert "id: 2,\n label: 'ui/1.0'" in tc.out

tc.run("graph info openimageio/ --format=html", assert_error=True)
assert "// Add error conflict node" in tc.out
assert "// Add edge from node that introduces the conflict to the new error node" in tc.out
Expand Down

0 comments on commit dc98b6a

Please sign in to comment.