From e201af864fab593380082e2e01126b5e6cca9b3d 2020-10-26 21:05:19 From: Matthias Bussonnier Date: 2020-10-26 21:05:19 Subject: [PATCH] Merge pull request #12633 from NotWearingPants/cleanup/autogen_shortcuts.py --- diff --git a/docs/autogen_shortcuts.py b/docs/autogen_shortcuts.py index 38af9b1..802fa03 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 @@ -77,16 +77,18 @@ for kb in ipy_bindings: if __name__ == '__main__': - - 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)) + here = Path(__file__).parent + dest = here / "source" / "config" / "shortcuts" + + def sort_key(item): + k, v = item + shortcut, flt = k + return (str(shortcut), str(flt)) + + 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=sort_key): + csv.write(":kbd:`{}`\t{}\t{}\n".format(shortcut, flt, v))