def create_graph(module_list): module_list = set(module_list) all_deps = set() graph = Graph() for module in module_list: info = get_module_info(module) deps = info.get('depends', []) + [ d for d in info.get('extras_depend', []) if d in module_list] node = graph.add(module, deps) assert node.info is None node.info = info all_deps.update(deps) missing = all_deps - module_list if missing: raise MissingDependenciesException(list(missing)) return graph
def create_graph(module_list): graph = Graph() packages = [] for module in module_list: info = get_module_info(module) packages.append((module, info.get('depends', []), info.get('extras_depend', []), info)) current, later = set([x[0] for x in packages]), set() all_packages = set(current) while packages and current > later: package, deps, xdep, info = packages[0] # if all dependencies of 'package' are already in the graph, # add 'package' in the graph all_deps = deps + [x for x in xdep if x in all_packages] if reduce(lambda x, y: x and y in graph, all_deps, True): if package not in current: packages.pop(0) continue later.clear() current.remove(package) graph.add_node(package, all_deps) node = Node(package, graph) node.info = info else: later.add(package) packages.append((package, deps, xdep, info)) packages.pop(0) missings = set() for package, deps, _, _ in packages: if package not in later: continue missings |= set((x for x in deps if x not in graph)) if missings: raise MissingDependenciesException( list(missings - set((p[0] for p in packages)))) return graph, packages, later