##// END OF EJS Templates
Generate documentation of line & cell magics
Thomas Kluyver -
Show More
@@ -0,0 +1,45 b''
1 from IPython.core.alias import Alias
2 from IPython.core.interactiveshell import InteractiveShell
3 from IPython.utils.text import dedent, indent
4
5 shell = InteractiveShell.instance()
6 magic_docs = shell.magics_manager.lsmagic_docs()
7
8 def isalias(name):
9 return isinstance(shell.magics_manager.magics['line'], Alias)
10
11 line_magics = magic_docs['line']
12 cell_magics = magic_docs['cell']
13
14 output = [
15 "Line magics",
16 "===========",
17 "",
18 ]
19
20 for name, docstring in sorted(line_magics.items()):
21 if isalias(name):
22 # Aliases are magics, but shouldn't be documented here
23 continue
24 output.extend([".. magic:: %{}".format(name),
25 "",
26 indent(dedent(docstring)),
27 ""])
28
29 output.extend([
30 "Cell magics"
31 "==========="
32 "",
33 ])
34
35 for name, docstring in sorted(cell_magics.items()):
36 if docstring == line_magics.get(name, 'QQQP'):
37 # Don't redocument line magics that double as cell magics
38 continue
39 output.extend([".. cellmagic:: %%{}".format(name),
40 "",
41 indent(dedent(docstring)),
42 ""])
43
44 with open("source/interactive/magics-generated.txt", "w") as f:
45 f.write("\n".join(output)) No newline at end of file
@@ -0,0 +1,5 b''
1 =======================
2 Built-in magic commands
3 =======================
4
5 .. include:: magics-generated.txt
@@ -42,6 +42,7 b' clean: clean_api'
42 -rm -rf build/* dist/*
42 -rm -rf build/* dist/*
43 -cd $(SRCDIR)/config/options; cat generated | xargs -r rm -f
43 -cd $(SRCDIR)/config/options; cat generated | xargs -r rm -f
44 -rm -rf $(SRCDIR)/config/options/generated
44 -rm -rf $(SRCDIR)/config/options/generated
45 -rm -f $(SRCDIR)/interactive/magics-generated.txt
45
46
46 pdf: latex
47 pdf: latex
47 cd build/latex && make all-pdf
48 cd build/latex && make all-pdf
@@ -58,8 +59,8 b' dist: html'
58 cp -al build/html .
59 cp -al build/html .
59 @echo "Build finished. Final docs are in html/"
60 @echo "Build finished. Final docs are in html/"
60
61
61 html: api autoconfig
62 html: api autoconfig automagic
62 html_noapi: clean_api autoconfig
63 html_noapi: clean_api autoconfig automagic
63
64
64 html html_noapi:
65 html html_noapi:
65 mkdir -p build/html build/doctrees
66 mkdir -p build/html build/doctrees
@@ -67,6 +68,12 b' html html_noapi:'
67 @echo
68 @echo
68 @echo "Build finished. The HTML pages are in build/html."
69 @echo "Build finished. The HTML pages are in build/html."
69
70
71 automagic: source/interactive/magics-generated.txt
72
73 source/interactive/magics-generated.txt:
74 python autogen_magics.py
75 @echo "Created docs for line & cell magics"
76
70 autoconfig: source/config/options/generated
77 autoconfig: source/config/options/generated
71
78
72 source/config/options/generated:
79 source/config/options/generated:
@@ -8,6 +8,7 b' Using IPython for interactive work'
8 tutorial
8 tutorial
9 tips
9 tips
10 reference
10 reference
11 magics
11 shell
12 shell
12 qtconsole
13 qtconsole
13
14
@@ -20,5 +20,5 b' def parse_cell_magic(env, sig, signode):'
20
20
21
21
22 def setup(app):
22 def setup(app):
23 app.add_object_type('magic', 'magic', '%%%s (magic command)', parse_magic)
23 app.add_object_type('magic', 'magic', 'pair: %s; magic command', parse_magic)
24 app.add_object_type('cellmagic', 'cellmagic', '%%%%%s (cell magic)', parse_cell_magic)
24 app.add_object_type('cellmagic', 'cellmagic', 'pair: %s; cell magic', parse_cell_magic)
General Comments 0
You need to be logged in to leave comments. Login now