diff --git a/graph.py b/graph.py index 00a0a93..7bd909d 100755 --- a/graph.py +++ b/graph.py @@ -1,23 +1,21 @@ #!/usr/bin/env python3 import json -import typing import os +from typing import Dict -def as_graphviz(recipes: dict): + +def graph_all(recipes: dict) -> None: print("digraph G {") for result, method in recipes.items(): for variation in method: - for input in variation["input"]: - print(f"{input} -> {result}") + for i in variation["input"]: + print(f"{i} -> {result}") print("}") -if __name__ == '__main__': - root = os.path.dirname(__file__) - recipe_root = os.path.join(root, 'data', 'recipes') - +def load_recipes(recipe_root: str) -> dict: recipes = dict() for dirname, dirs, files in os.walk(recipe_root): @@ -29,4 +27,10 @@ if __name__ == '__main__': recipes[name] = variations - as_graphviz(recipes) + return recipes + + +if __name__ == '__main__': + root = os.path.dirname(__file__) + recipe_root = os.path.join(root, 'data', 'recipes') + graph_all(load_recipes(recipe_root))