import networkx as nx
import re
regex = re.compile('^([A-Z]+)::Requires\\s+=\\s([A-Z"]+)$')
G = nx.DiGraph()
roots = set()
for l in raw.splitlines():
    if len(l):
        target, prereq = regex.match(l).groups()
if prereq == '""':
    roots.add(target)
else:
    G.add_edge(prereq, target)
Build a dependency graph in python