From d49eece03553c030c2ef79e3ee0fa083263cecc7 2020-10-16 18:08:18 From: NotWearingPants Date: 2020-10-16 18:08:18 Subject: [PATCH] use pathlib in docs/autogen_shortcuts.py + minor refactor --- diff --git a/docs/autogen_shortcuts.py b/docs/autogen_shortcuts.py index 2cd9019..e752384 100755 --- a/docs/autogen_shortcuts.py +++ b/docs/autogen_shortcuts.py @@ -1,4 +1,4 @@ -from os.path import abspath, dirname, join +from pathlib import Path from IPython.terminal.shortcuts import create_ipython_shortcuts @@ -75,16 +75,10 @@ for kb in ipy_bindings: if __name__ == '__main__': + here = Path(__file__).parent + dest = here / 'source' / 'config' / 'shortcuts' - sort_key = lambda k:(str(k[0][1]),str(k[0][0])) - - here = abspath(dirname(__file__)) - dest = join(here, 'source', 'config', 'shortcuts') - - with open(join(dest, 'single_filtered.csv'), 'w') as csv: - for k, v in sorted(single_filter.items(), key=sort_key): - csv.write(':kbd:`{}`\t{}\t{}\n'.format(k[0], k[1], v)) - - with open(join(dest, 'multi_filtered.csv'), 'w') as csv: - for k, v in sorted(multi_filter.items(), key=sort_key): - csv.write(':kbd:`{}`\t{}\t{}\n'.format(k[0], k[1], v)) + for filters, output_filename in [(single_filter, 'single_filtered'), (multi_filter, 'multi_filtered')]: + with (dest / '{}.csv'.format(output_filename)).open('w') as csv: + for (shortcut, flt), v in sorted(filters.items(), key=lambda ((shortcut, flt), v): (str(shortcut), str(flt))): + csv.write(':kbd:`{}`\t{}\t{}\n'.format(shortcut, flt, v))