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