##// END OF EJS Templates
Skip documenting aliases to other magic commands
Thomas Kluyver -
Show More
@@ -1,15 +1,10 b''
1 from IPython.core.alias import Alias
1 from IPython.core.alias import Alias
2 from IPython.core.interactiveshell import InteractiveShell
2 from IPython.core.interactiveshell import InteractiveShell
3 from IPython.core.magic import MagicAlias
3 from IPython.utils.text import dedent, indent
4 from IPython.utils.text import dedent, indent
4
5
5 shell = InteractiveShell.instance()
6 shell = InteractiveShell.instance()
6 magic_docs = shell.magics_manager.lsmagic_docs()
7 magics = shell.magics_manager.magics
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
8
14 def _strip_underline(line):
9 def _strip_underline(line):
15 chars = set(line.strip())
10 chars = set(line.strip())
@@ -18,7 +13,8 b' def _strip_underline(line):'
18 else:
13 else:
19 return line
14 return line
20
15
21 def format_docstring(docstring):
16 def format_docstring(func):
17 docstring = (func.__doc__ or "Undocumented").rstrip()
22 docstring = indent(dedent(docstring))
18 docstring = indent(dedent(docstring))
23 # Sphinx complains if indented bits have rst headings in, so strip out
19 # Sphinx complains if indented bits have rst headings in, so strip out
24 # any underlines in the docstring.
20 # any underlines in the docstring.
@@ -34,13 +30,14 b' output = ['
34 # Case insensitive sort by name
30 # Case insensitive sort by name
35 def sortkey(s): return s[0].lower()
31 def sortkey(s): return s[0].lower()
36
32
37 for name, docstring in sorted(line_magics.items(), key=sortkey):
33 for name, func in sorted(magics['line'].items(), key=sortkey):
38 if isalias(name):
34 if isinstance(func, Alias) or isinstance(func, MagicAlias):
39 # Aliases are magics, but shouldn't be documented here
35 # Aliases are magics, but shouldn't be documented here
36 # Also skip aliases to other magics
40 continue
37 continue
41 output.extend([".. magic:: {}".format(name),
38 output.extend([".. magic:: {}".format(name),
42 "",
39 "",
43 format_docstring(docstring),
40 format_docstring(func),
44 ""])
41 ""])
45
42
46 output.extend([
43 output.extend([
@@ -49,16 +46,18 b' output.extend(['
49 "",
46 "",
50 ])
47 ])
51
48
52 for name, docstring in sorted(cell_magics.items(), key=sortkey):
49 for name, func in sorted(magics['cell'].items(), key=sortkey):
53 if name == "!":
50 if name == "!":
54 # Special case - don't encourage people to use %%!
51 # Special case - don't encourage people to use %%!
55 continue
52 continue
56 if docstring == line_magics.get(name, 'QQQP'):
53 if func == magics['line'].get(name, 'QQQP'):
57 # Don't redocument line magics that double as cell magics
54 # Don't redocument line magics that double as cell magics
58 continue
55 continue
56 if isinstance(func, MagicAlias):
57 continue
59 output.extend([".. cellmagic:: {}".format(name),
58 output.extend([".. cellmagic:: {}".format(name),
60 "",
59 "",
61 format_docstring(docstring),
60 format_docstring(func),
62 ""])
61 ""])
63
62
64 with open("source/interactive/magics-generated.txt", "w") as f:
63 with open("source/interactive/magics-generated.txt", "w") as f:
General Comments 0
You need to be logged in to leave comments. Login now