@@ -117,6 +117,17 @@ import unittest
117117from pprint import pprint
118118from collections import defaultdict
119119
120+
121+def debug(msg, *args, **kwargs):
122+ if False:
123+ print(
124+ "DEBUG: {}".format(
125+ msg.format(*args, **kwargs)
126+ ),
127+ file=sys.stderr
128+ )
129+
130+
120131# Find paths in the original dataset which are never referenced by
121132# any other paths
122133def find_roots(closures):
@@ -330,6 +341,7 @@ class TestMakeLookup(unittest.TestCase):
330341def make_graph_segment_from_root(root, lookup):
331342 children = {}
332343 for ref in lookup[root]:
344+ debug("Making graph segments on {}".format(ref))
333345 children[ref] = make_graph_segment_from_root(ref, lookup)
334346 return children
335347
@@ -384,6 +396,7 @@ class TestMakeGraphSegmentFromRoot(unittest.TestCase):
384396def graph_popularity_contest(full_graph):
385397 popularity = defaultdict(int)
386398 for path, subgraph in full_graph.items():
399+ debug("Calculating popularity under {}".format(path))
387400 popularity[path] += 1
388401 subcontest = graph_popularity_contest(subgraph)
389402 for subpath, subpopularity in subcontest.items():
@@ -474,6 +487,7 @@ def main():
474487 filename = sys.argv[1]
475488 key = sys.argv[2]
476489
490+ debug("Loading from {}", filename)
477491 with open(filename) as f:
478492 data = json.load(f)
479493
@@ -497,14 +511,21 @@ def main():
497511 # ]
498512 graph = data[key]
499513
514+ debug("Finding roots from {}", key)
500515 roots = find_roots(graph);
516+ debug("Making lookup for {}", key)
501517 lookup = make_lookup(graph)
502518
503519 full_graph = {}
504520 for root in roots:
521+ debug("Making full graph for {}", root)
505522 full_graph[root] = make_graph_segment_from_root(root, lookup)
506523
507− ordered = order_by_popularity(graph_popularity_contest(full_graph))
524+ debug("Running contest")
525+ contest = graph_popularity_contest(full_graph)
526+ debug("Ordering by popularity")
527+ ordered = order_by_popularity(contest)
528+ debug("Checking for missing paths")
508529 missing = []
509530 for path in all_paths(graph):
510531 if path not in ordered: