#!/usr/bin/env python3 import json import typing import os def as_graphviz(recipes: dict): print("digraph G {") for result, method in recipes.items(): for variation in method: for input in variation["input"]: print(f"{input} -> {result}") print("}") if __name__ == '__main__': root = os.path.dirname(__file__) recipe_root = os.path.join(root, 'data', 'recipes') recipes = dict() for dirname, dirs, files in os.walk(recipe_root): for f in files: path = os.path.join(dirname, f) name, _ = os.path.splitext(f) with open(path, 'r') as src: variations = json.load(src) recipes[name] = variations as_graphviz(recipes)