_get_dep_chain: fix KeyError, bug #392059
authorZac Medico <zmedico@gentoo.org>
Sun, 27 Nov 2011 20:52:04 +0000 (12:52 -0800)
committerZac Medico <zmedico@gentoo.org>
Sun, 27 Nov 2011 20:52:04 +0000 (12:52 -0800)
This fixes a regression since commit
57cc4e3e8991e7c4394d1dff7698aa62ed2a286b, which make a faulty
assumption that the digraph contained all of the edges contained in
parent_atoms.

pym/_emerge/depgraph.py

index 484206eb7c14e2a3e2c75a5d8c915e4343089d64..3bda89442f7e520ca533d7c4711a4f0512ba7787 100644 (file)
@@ -2743,6 +2743,7 @@ class depgraph(object):
                node = start_node
                child = None
                all_parents = self._dynamic_config._parent_atoms
+               graph = self._dynamic_config.digraph
 
                if target_atom is not None and isinstance(node, Package):
                        affecting_use = set()
@@ -2801,8 +2802,12 @@ class depgraph(object):
                while node is not None:
                        traversed_nodes.add(node)
 
-                       if isinstance(node, DependencyArg):
-                               if self._dynamic_config.digraph.parent_nodes(node):
+                       if node not in graph:
+                               # The parent is not in the graph due to backtracking.
+                               break
+
+                       elif isinstance(node, DependencyArg):
+                               if graph.parent_nodes(node):
                                        node_type = "set"
                                else:
                                        node_type = "argument"
@@ -2815,13 +2820,21 @@ class depgraph(object):
                                                break
 
                                dep_strings = set()
-                               for priority in self._dynamic_config.digraph.nodes[node][0][child]:
-                                       if priority.buildtime:
-                                               dep_strings.add(node.metadata["DEPEND"])
-                                       if priority.runtime:
-                                               dep_strings.add(node.metadata["RDEPEND"])
-                                       if priority.runtime_post:
-                                               dep_strings.add(node.metadata["PDEPEND"])
+                               priorities = graph.nodes[node][0].get(child)
+                               if priorities is None:
+                                       # This edge comes from _parent_atoms and was not added to
+                                       # the graph, and _parent_atoms does not contain priorities.
+                                       dep_strings.add(node.metadata["DEPEND"])
+                                       dep_strings.add(node.metadata["RDEPEND"])
+                                       dep_strings.add(node.metadata["PDEPEND"])
+                               else:
+                                       for priority in priorities:
+                                               if priority.buildtime:
+                                                       dep_strings.add(node.metadata["DEPEND"])
+                                               if priority.runtime:
+                                                       dep_strings.add(node.metadata["RDEPEND"])
+                                               if priority.runtime_post:
+                                                       dep_strings.add(node.metadata["PDEPEND"])
 
                                affecting_use = set()
                                for dep_str in dep_strings:
@@ -2848,10 +2861,6 @@ class depgraph(object):
 
                                dep_chain.append((pkg_name, node.type_name))
 
-                       if node not in self._dynamic_config.digraph:
-                               # The parent is not in the graph due to backtracking.
-                               break
-
                        # When traversing to parents, prefer arguments over packages
                        # since arguments are root nodes. Never traverse the same
                        # package twice, in order to prevent an infinite loop.