Skip to content
Snippets Groups Projects
Commit 6bbc21b9 authored by Christophe Simonis's avatar Christophe Simonis
Browse files

[FIX] graph.py: correct Node() creation.

Fixes #3730
parent c87b9c65
No related branches found
No related tags found
No related merge requests found
...@@ -56,7 +56,8 @@ class Graph(dict): ...@@ -56,7 +56,8 @@ class Graph(dict):
def add_node(self, name, info): def add_node(self, name, info):
max_depth, father = 0, None max_depth, father = 0, None
for n in [Node(x, self, None) for x in info['depends']]: for d in info['depends']:
n = self.get(d) or Node(d, self, None) # lazy creation, do not use default value for get()
if n.depth >= max_depth: if n.depth >= max_depth:
father = n father = n
max_depth = n.depth max_depth = n.depth
...@@ -117,7 +118,6 @@ class Graph(dict): ...@@ -117,7 +118,6 @@ class Graph(dict):
later.clear() later.clear()
current.remove(package) current.remove(package)
node = self.add_node(package, info) node = self.add_node(package, info)
node.data = info
for kind in ('init', 'demo', 'update'): for kind in ('init', 'demo', 'update'):
if package in tools.config[kind] or 'all' in tools.config[kind] or kind in force: if package in tools.config[kind] or 'all' in tools.config[kind] or kind in force:
setattr(node, kind, True) setattr(node, kind, True)
...@@ -148,6 +148,8 @@ class Graph(dict): ...@@ -148,6 +148,8 @@ class Graph(dict):
yield module yield module
level += 1 level += 1
def __str__(self):
return '\n'.join(str(n) for n in self if n.depth == 0)
class Node(object): class Node(object):
""" One module in the modules dependency graph. """ One module in the modules dependency graph.
...@@ -162,18 +164,21 @@ class Node(object): ...@@ -162,18 +164,21 @@ class Node(object):
inst = graph[name] inst = graph[name]
else: else:
inst = object.__new__(cls) inst = object.__new__(cls)
inst.name = name
inst.info = info
graph[name] = inst graph[name] = inst
return inst return inst
def __init__(self, name, graph, info): def __init__(self, name, graph, info):
self.name = name
self.graph = graph self.graph = graph
self.info = info or getattr(self, 'info', {})
if not hasattr(self, 'children'): if not hasattr(self, 'children'):
self.children = [] self.children = []
if not hasattr(self, 'depth'): if not hasattr(self, 'depth'):
self.depth = 0 self.depth = 0
self.info = info or {}
@property
def data(self):
return self.info
def add_child(self, name, info): def add_child(self, name, info):
node = Node(name, self.graph, info) node = Node(name, self.graph, info)
......
0% Loading or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment