From bd7f7dd7436895a53c6d36d02d722ffa11fac763 Mon Sep 17 00:00:00 2001 From: Danny Robson Date: Sun, 28 Apr 2019 08:26:43 +1000 Subject: [PATCH] graph: avoid variable shadowing and typing warnings --- graph.py | 22 +++++++++++++--------- 1 file changed, 13 insertions(+), 9 deletions(-) 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))