#-------------------------------------------------------------------------------
# Parse python dependencies generated by sfood (from snakefood package) down
# to something useful for our make dependency rules
#-------------------------------------------------------------------------------
import os.path

def parse_sfood_deps(infilename, outfilename):

    # Read the known paths from the input file
    deps = []
    with open(infilename, "r") as f:
        for line in f:
            (froot, fn), (troot, tn) = eval(line)
            if not troot is None:
                deps.append(os.path.join(troot, tn))

    # Now write the unique dependencies
    unique_deps = set(deps)
    with open(outfilename, "a") as f:
        for i, dep in enumerate(unique_deps):
            f.write(" %s \\\n" % dep)
            # f.write(" %s" % dep)
            # if i < len(deps) - 1:
            #     f.write(" \\\n")
            # else:
            #     f.write("\n")

    return
