<

e4faed1246d8 "package dependency install sequence"

installed = set()
processing = set()
def install(x):

    if x in installed:return

    if x in processing: raise Exception("cyclic dependency")
    processing.add(x)

    dependencies = get_dependencies(x)
    for d in dependencies:
        install(d)

    installed.add(x)
    processing.remove(x)

    print(x)

def get_dependencies(x):
    return pkgs.get(x, [])

if __name__ == '__main__':
    # question. note the order is arbitrary
    pkgs = dict()
    pkgs[4]= [5]
    pkgs[2]= [4,5]
    pkgs[1]= [2,3,4,5]


    for p in pkgs.keys():
        install(p)