##// 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
@@ -1,155 +1,162 b''
1 1 # Makefile for Sphinx documentation
2 2 #
3 3
4 4 # You can set these variables from the command line.
5 5 SPHINXOPTS =
6 6 SPHINXBUILD = sphinx-build
7 7 PAPER =
8 8 SRCDIR = source
9 9 BUILDDIR = build
10 10
11 11 # Internal variables.
12 12 PAPEROPT_a4 = -D latex_paper_size=a4
13 13 PAPEROPT_letter = -D latex_paper_size=letter
14 14 ALLSPHINXOPTS = -d build/doctrees $(PAPEROPT_$(PAPER)) $(SPHINXOPTS) $(SRCDIR)
15 15
16 16 .PHONY: help clean html web pickle htmlhelp latex changes linkcheck api
17 17
18 18 default: html
19 19
20 20 help:
21 21 @echo "Please use \`make <target>' where <target> is one of"
22 22 @echo " html standalone HTML files"
23 23 @echo " html_noapi same as above, without the time consuming API docs"
24 24 @echo " pickle pickle files (usable by e.g. sphinx-web)"
25 25 @echo " htmlhelp HTML files and a HTML help project"
26 26 @echo " latex LaTeX files, you can set PAPER=a4 or PAPER=letter"
27 27 @echo " texinfo Texinfo files"
28 28 @echo " info Texinfo files and run them through makeinfo"
29 29 @echo " changes an overview over all changed/added/deprecated items"
30 30 @echo " linkcheck check all external links for integrity (takes a long time)"
31 31 @echo
32 32 @echo "Compound utility targets:"
33 33 @echo "pdf latex and then runs the PDF generation"
34 34 @echo "all html and pdf"
35 35 @echo "dist all, and then puts the results in dist/"
36 36 @echo "gitwash-update update git workflow from source repo"
37 37
38 38 clean_api:
39 39 -rm -rf $(SRCDIR)/api/generated
40 40
41 41 clean: clean_api
42 42 -rm -rf build/* dist/*
43 43 -cd $(SRCDIR)/config/options; cat generated | xargs -r rm -f
44 44 -rm -rf $(SRCDIR)/config/options/generated
45 -rm -f $(SRCDIR)/interactive/magics-generated.txt
45 46
46 47 pdf: latex
47 48 cd build/latex && make all-pdf
48 49
49 50 all: html pdf
50 51
51 52 # For final distribution, only build HTML (our pdf is now so large as to be
52 53 # unusable, takes forever to build and just bloats the downloads). We leave
53 54 # them hardlinked at the top-level so users find them easily, though the
54 55 # original build/html dir is left in-place (useful to reload builds while
55 56 # testing).
56 57 dist: html
57 58 rm -rf html
58 59 cp -al build/html .
59 60 @echo "Build finished. Final docs are in html/"
60 61
61 html: api autoconfig
62 html_noapi: clean_api autoconfig
62 html: api autoconfig automagic
63 html_noapi: clean_api autoconfig automagic
63 64
64 65 html html_noapi:
65 66 mkdir -p build/html build/doctrees
66 67 $(SPHINXBUILD) -b html $(ALLSPHINXOPTS) build/html
67 68 @echo
68 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 77 autoconfig: source/config/options/generated
71 78
72 79 source/config/options/generated:
73 80 python autogen_config.py
74 81 @echo "Created docs for config options"
75 82
76 83 api: source/api/generated/gen.txt
77 84
78 85 source/api/generated/gen.txt:
79 86 python autogen_api.py
80 87 @echo "Build API docs finished."
81 88
82 89 pickle:
83 90 mkdir -p build/pickle build/doctrees
84 91 $(SPHINXBUILD) -b pickle $(ALLSPHINXOPTS) build/pickle
85 92 @echo
86 93 @echo "Build finished; now you can process the pickle files or run"
87 94 @echo " sphinx-web build/pickle"
88 95 @echo "to start the sphinx-web server."
89 96
90 97 web: pickle
91 98
92 99 htmlhelp:
93 100 mkdir -p build/htmlhelp build/doctrees
94 101 $(SPHINXBUILD) -b htmlhelp $(ALLSPHINXOPTS) build/htmlhelp
95 102 @echo
96 103 @echo "Build finished; now you can run HTML Help Workshop with the" \
97 104 ".hhp project file in build/htmlhelp."
98 105
99 106 qthelp:
100 107 mkdir -p build/qthelp
101 108 $(SPHINXBUILD) -b qthelp $(ALLSPHINXOPTS) build/qthelp
102 109 @echo
103 110 @echo "Build finished; now you can run "qcollectiongenerator" with the" \
104 111 ".qhcp project file in $(BUILDDIR)/qthelp, like this:"
105 112 @echo "# qcollectiongenerator $(BUILDDIR)/qthelp/IPython.qhcp"
106 113 @echo "To view the help file:"
107 114 @echo "# assistant -collectionFile $(BUILDDIR)/qthelp/IPython.qhc"
108 115
109 116 latex: api autoconfig
110 117 mkdir -p build/latex build/doctrees
111 118 $(SPHINXBUILD) -b latex $(ALLSPHINXOPTS) build/latex
112 119 @echo
113 120 @echo "Build finished; the LaTeX files are in build/latex."
114 121 @echo "Run \`make all-pdf' or \`make all-ps' in that directory to" \
115 122 "run these through (pdf)latex."
116 123
117 124 changes:
118 125 mkdir -p build/changes build/doctrees
119 126 $(SPHINXBUILD) -b changes $(ALLSPHINXOPTS) build/changes
120 127 @echo
121 128 @echo "The overview file is in build/changes."
122 129
123 130 linkcheck:
124 131 mkdir -p build/linkcheck build/doctrees
125 132 $(SPHINXBUILD) -b linkcheck $(ALLSPHINXOPTS) build/linkcheck
126 133 @echo
127 134 @echo "Link check complete; look for any errors in the above output " \
128 135 "or in build/linkcheck/output.rst."
129 136
130 137 gitwash-update:
131 138 python ../tools/gitwash_dumper.py source/development ipython
132 139
133 140 nightly: dist
134 141 rsync -avH --delete dist/ ipython:www/doc/nightly
135 142
136 143 gh-pages: clean html
137 144 # if VERSION is unspecified, it will be dev
138 145 # For releases, VERSION should be just the major version,
139 146 # e.g. VERSION=2 make gh-pages
140 147 python gh-pages.py $(VERSION)
141 148
142 149 texinfo:
143 150 mkdir -p $(BUILDDIR)/texinfo
144 151 $(SPHINXBUILD) -b texinfo $(ALLSPHINXOPTS) $(BUILDDIR)/texinfo
145 152 @echo
146 153 @echo "Build finished. The Texinfo files are in $(BUILDDIR)/texinfo."
147 154 @echo "Run \`make' in that directory to run these through makeinfo" \
148 155 "(use \`make info' here to do that automatically)."
149 156
150 157 info:
151 158 mkdir -p $(BUILDDIR)/texinfo
152 159 $(SPHINXBUILD) -b texinfo $(ALLSPHINXOPTS) $(BUILDDIR)/texinfo
153 160 @echo "Running Texinfo files through makeinfo..."
154 161 make -C $(BUILDDIR)/texinfo info
155 162 @echo "makeinfo finished; the Info files are in $(BUILDDIR)/texinfo."
@@ -1,16 +1,17 b''
1 1 ==================================
2 2 Using IPython for interactive work
3 3 ==================================
4 4
5 5 .. toctree::
6 6 :maxdepth: 2
7 7
8 8 tutorial
9 9 tips
10 10 reference
11 magics
11 12 shell
12 13 qtconsole
13 14
14 15 .. seealso::
15 16
16 17 :doc:`/notebook/index`
@@ -1,24 +1,24 b''
1 1 import re
2 2 from sphinx import addnodes
3 3
4 4 line_magic_re = re.compile(r"%([\w_]+)")
5 5 cell_magic_re = re.compile(r"%%([\w_]+)")
6 6
7 7 def parse_magic(env, sig, signode):
8 8 m = line_magic_re.match(sig)
9 9 if not m:
10 10 raise Exception("Invalid magic command: %s" % sig)
11 11 signode += addnodes.desc_name(sig, sig)
12 12 return m.group(1)
13 13
14 14 def parse_cell_magic(env, sig, signode):
15 15 m = cell_magic_re.match(sig)
16 16 if not m:
17 17 raise ValueError("Invalid cell magic: %s" % sig)
18 18 signode += addnodes.desc_name(sig, sig)
19 19 return m.group(1)
20 20
21 21
22 22 def setup(app):
23 app.add_object_type('magic', 'magic', '%%%s (magic command)', parse_magic)
24 app.add_object_type('cellmagic', 'cellmagic', '%%%%%s (cell magic)', parse_cell_magic)
23 app.add_object_type('magic', 'magic', 'pair: %s; magic command', parse_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