##// END OF EJS Templates
Merge pull request #9664 from klonuo/keyboard_shortcuts_docs...
Matthias Bussonnier -
r22621:1b3bb723 merge
parent child Browse files
Show More
@@ -0,0 +1,83 b''
1 from os.path import abspath, dirname, join
2
3 from IPython.terminal.interactiveshell import KeyBindingManager
4
5
6 def name(c):
7 s = c.__class__.__name__
8 return log_filters[s] if s in log_filters.keys() else s
9
10
11 def sentencize(s):
12 """Extract first sentence
13 """
14 s = s.replace('\n', ' ').strip().split('.')
15 s = s[0] if len(s) else s
16 try:
17 return " ".join(s.split())
18 except AttributeError:
19 return s
20
21
22 def most_common(lst, n=3):
23 """Most common elements occurring more then `n` times
24 """
25 from collections import Counter
26
27 c = Counter(lst)
28 return [k for (k, v) in c.items() if k and v > n]
29
30
31 def multi_filter_str(flt):
32 """Yield readable conditional filter
33 """
34 assert hasattr(flt, 'filters'), 'Conditional filter required'
35
36 yield name(flt)
37 for subfilter in flt.filters:
38 yield name(subfilter)
39 if hasattr(subfilter, 'filter'):
40 yield name(subfilter.filter)
41
42
43 log_filters = dict(_AndList='(And)', _OrList='(Or)', _Invert='(Inv)')
44
45 kbm = KeyBindingManager.for_prompt()
46 ipy_bindings = kbm.registry.key_bindings
47
48 dummy_docs = [] # ignore bindings without proper documentation
49
50 common_docs = most_common([kb.handler.__doc__ for kb in ipy_bindings])
51 if common_docs:
52 dummy_docs.extend(common_docs)
53
54 dummy_docs = list(set(dummy_docs))
55
56 single_filter = dict()
57 multi_filter = dict()
58 for kb in ipy_bindings:
59 doc = kb.handler.__doc__
60 if not doc or doc in dummy_docs:
61 continue
62
63 shortcut = ' '.join([k if isinstance(k, str) else k.name for k in kb.keys])
64 shortcut += shortcut.endswith('\\') and '\\' or ''
65 if hasattr(kb.filter, 'filters'):
66 flt = ' '.join(multi_filter_str(kb.filter))
67 multi_filter[(shortcut, flt)] = sentencize(doc)
68 else:
69 single_filter[(shortcut, name(kb.filter))] = sentencize(doc)
70
71
72 if __name__ == '__main__':
73
74 here = abspath(dirname(__file__))
75 dest = join(here, 'source', 'config', 'shortcuts')
76
77 with open(join(dest, 'single_filtered.csv'), 'w') as csv:
78 for k, v in sorted(single_filter.items()):
79 csv.write(':kbd:`{}`\t{}\t{}\n'.format(k[0], k[1], v))
80
81 with open(join(dest, 'multi_filtered.csv'), 'w') as csv:
82 for k, v in sorted(multi_filter.items()):
83 csv.write(':kbd:`{}`\t{}\t{}\n'.format(k[0], k[1], v))
@@ -0,0 +1,25 b''
1 =================
2 IPython shortcuts
3 =================
4
5 Available shortcut in IPython terminal.
6
7
8 Single Filtered shortcuts
9 =========================
10
11 .. csv-table::
12 :header: Shortcut,Filter,Description
13 :widths: 30, 30, 100
14 :delim: tab
15 :file: single_filtered.csv
16
17
18 Multi Filtered shortcuts
19 =========================
20
21 .. csv-table::
22 :header: Shortcut,Filter,Description
23 :widths: 30, 30, 100
24 :delim: tab
25 :file: multi_filtered.csv
@@ -42,6 +42,7 b' clean_api:'
42 clean: clean_api
42 clean: clean_api
43 -rm -rf build/* dist/*
43 -rm -rf build/* dist/*
44 -rm -f $(SRCDIR)/config/options/config-generated.txt
44 -rm -f $(SRCDIR)/config/options/config-generated.txt
45 -rm -f $(SRCDIR)/config/shortcuts/*.csv
45 -rm -f $(SRCDIR)/interactive/magics-generated.txt
46 -rm -f $(SRCDIR)/interactive/magics-generated.txt
46
47
47 pdf: latex
48 pdf: latex
@@ -59,8 +60,8 b' dist: html'
59 cp -al build/html .
60 cp -al build/html .
60 @echo "Build finished. Final docs are in html/"
61 @echo "Build finished. Final docs are in html/"
61
62
62 html: api autoconfig automagic
63 html: api autoconfig automagic autogen_shortcuts
63 html_noapi: clean_api autoconfig automagic
64 html_noapi: clean_api autoconfig automagic autogen_shortcuts
64
65
65 html html_noapi:
66 html html_noapi:
66 mkdir -p build/html build/doctrees
67 mkdir -p build/html build/doctrees
@@ -86,6 +87,10 b' source/api/generated/gen.txt:'
86 $(PYTHON) autogen_api.py
87 $(PYTHON) autogen_api.py
87 @echo "Build API docs finished."
88 @echo "Build API docs finished."
88
89
90 autogen_shortcuts:
91 $(PYTHON) autogen_shortcuts.py
92 @echo "Created docs for shortcuts"
93
89 pickle:
94 pickle:
90 mkdir -p build/pickle build/doctrees
95 mkdir -p build/pickle build/doctrees
91 $(SPHINXBUILD) -b pickle $(ALLSPHINXOPTS) build/pickle
96 $(SPHINXBUILD) -b pickle $(ALLSPHINXOPTS) build/pickle
@@ -25,6 +25,7 b' FOR %%L IN (html html_noapi pickle htmlhelp latex changes linkcheck) DO ('
25 MD build\%1 || GOTO DIR_EXIST
25 MD build\%1 || GOTO DIR_EXIST
26 %PYTHON% autogen_config.py && ECHO Created docs for config options
26 %PYTHON% autogen_config.py && ECHO Created docs for config options
27 %PYTHON% autogen_magics.py && ECHO Created docs for line ^& cell magics
27 %PYTHON% autogen_magics.py && ECHO Created docs for line ^& cell magics
28 %PYTHON% autogen_shortcuts.py && ECHO Created docs for shortcuts
28 IF NOT "%1" == "html_noapi" (
29 IF NOT "%1" == "html_noapi" (
29 %PYTHON% autogen_api.py && ECHO Build API docs finished
30 %PYTHON% autogen_api.py && ECHO Build API docs finished
30 %SPHINXBUILD% -b %1 %ALLSPHINXOPTS% build\%1
31 %SPHINXBUILD% -b %1 %ALLSPHINXOPTS% build\%1
1 NO CONTENT: modified file chmod 100644 => 100755
NO CONTENT: modified file chmod 100644 => 100755
@@ -12,6 +12,7 b' Configuring IPython'
12
12
13 intro
13 intro
14 options/index
14 options/index
15 shortcuts/index
15 details
16 details
16
17
17 .. seealso::
18 .. seealso::
General Comments 0
You need to be logged in to leave comments. Login now