##// END OF EJS Templates
Updated Text Quote formatting
Adam Hackbarth -
Show More
@@ -1,67 +1,67 b''
1 1 from pathlib import Path
2 2 from IPython.core.alias import Alias
3 3 from IPython.core.interactiveshell import InteractiveShell
4 4 from IPython.core.magic import MagicAlias
5 5 from IPython.utils.text import dedent, indent
6 6
7 7 shell = InteractiveShell.instance()
8 8 magics = shell.magics_manager.magics
9 9
10 10 def _strip_underline(line):
11 11 chars = set(line.strip())
12 if len(chars) == 1 and ('-' in chars or '=' in chars):
12 if len(chars) == 1 and ("-" in chars or "=" in chars):
13 13 return ""
14 14 else:
15 15 return line
16 16
17 17 def format_docstring(func):
18 18 docstring = (func.__doc__ or "Undocumented").rstrip()
19 19 docstring = indent(dedent(docstring))
20 20 # Sphinx complains if indented bits have rst headings in, so strip out
21 21 # any underlines in the docstring.
22 22 lines = [_strip_underline(l) for l in docstring.splitlines()]
23 23 return "\n".join(lines)
24 24
25 25 output = [
26 26 "Line magics",
27 27 "===========",
28 28 "",
29 29 ]
30 30
31 31 # Case insensitive sort by name
32 32 def sortkey(s): return s[0].lower()
33 33
34 for name, func in sorted(magics['line'].items(), key=sortkey):
34 for name, func in sorted(magics["line"].items(), key=sortkey):
35 35 if isinstance(func, Alias) or isinstance(func, MagicAlias):
36 36 # Aliases are magics, but shouldn't be documented here
37 37 # Also skip aliases to other magics
38 38 continue
39 39 output.extend([".. magic:: {}".format(name),
40 40 "",
41 41 format_docstring(func),
42 42 ""])
43 43
44 44 output.extend([
45 45 "Cell magics",
46 46 "===========",
47 47 "",
48 48 ])
49 49
50 for name, func in sorted(magics['cell'].items(), key=sortkey):
50 for name, func in sorted(magics["cell"].items(), key=sortkey):
51 51 if name == "!":
52 52 # Special case - don't encourage people to use %%!
53 53 continue
54 if func == magics['line'].get(name, 'QQQP'):
54 if func == magics["line"].get(name, "QQQP"):
55 55 # Don't redocument line magics that double as cell magics
56 56 continue
57 57 if isinstance(func, MagicAlias):
58 58 continue
59 59 output.extend([".. cellmagic:: {}".format(name),
60 60 "",
61 61 format_docstring(func),
62 62 ""])
63 63
64 64 src_path = Path(__file__).parent
65 dest = src_path.joinpath('source', 'interactive', 'magics-generated.txt')
65 dest = src_path.joinpath("source", "interactive", "magics-generated.txt")
66 66 with open(dest, "w") as f:
67 67 f.write("\n".join(output))
General Comments 0
You need to be logged in to leave comments. Login now