graph: avoid variable shadowing and typing warnings

This commit is contained in:
Danny Robson 2019-04-28 08:26:43 +10:00
parent 0f5b1d01ec
commit bd7f7dd743

View File

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