From 3ed12755d56eec2af85c48d39cadd06b48a1d87c Mon Sep 17 00:00:00 2001 From: timv Date: Wed, 12 Dec 2012 16:19:27 -0500 Subject: [PATCH] ENH: dump-to-file/display stable rendering of chart. --- bin/stdlib.py | 40 ++++++++++++++++++++++++++-------------- 1 file changed, 26 insertions(+), 14 deletions(-) diff --git a/bin/stdlib.py b/bin/stdlib.py index a9ffe53..e8f0e19 100644 --- a/bin/stdlib.py +++ b/bin/stdlib.py @@ -24,19 +24,24 @@ class chart_indirect(dict): chart = chart_indirect() -def dump_charts(): - print - print 'Charts' - print '============' - for x in chart: - print x - - zzz = [(pretty((x,idx)), idx, row, row[-1]) for idx, row in chart[x].data.items()] - zzz.sort() - - for p, i, _, v in zzz: - print '%s: %-30s := %s' % (i, p, v) - print +def dump_charts(out=sys.stdout): + print >> out + print >> out, 'Charts' + print >> out, '============' + + fns = chart.keys() + fns.sort() + + for x in fns: + print >> out, x + print >> out, '=====================================' + + rows = [(pretty((x,idx)), idx, row, row[-1]) for idx, row in chart[x].data.items()] + rows.sort() + + for p, _, _, v in rows: + print >> out, '%-30s := %s' % (p, v) + print >> out class Chart(object): @@ -96,7 +101,10 @@ def pretty(item): row = chart[fn].data[idx] args = row[:-1] fn = ''.join(fn.split('/')[:-1]) # drop arity from name. - return '%s(%s)' % (fn, ','.join(map(pretty, args))) + pretty_args = map(pretty, args) + if not len(pretty_args): # zero arity -> no parens. + return fn + return '%s(%s)' % (fn, ','.join(pretty_args)) def prettify(x): @@ -261,6 +269,10 @@ def run(): finally: dump_charts() + with file(dyna + '.chart', 'wb') as f: + dump_charts(f) + + # Example of reactivity # >>> emit(('rewrite/3', 5), -1000) -- 2.50.1