##// END OF EJS Templates
Simplify debugger classes....
Simplify debugger classes. Directly get the color scheme from the interactive shell (which is created if not already present, anyways). The goal is ultimately to allow the IPython debugger to be a drop-in replacement of the stdlib pdb with the same signature (in particular, this would obviate the need for plugins such as nose-ipdb and pytest-ipdb; nose and pytest could instead let their `--pdb` command line arg take an argument specifying the Pdb (sub)class to use, e.g. `py.test --pdb=IPython.core.debugger.Pdb`). Also deprecate the `Tracer` class (and related utilities), which can be fairly trivially replaced by `IPython.core.debugger.Pdb().set_trace()` (we can let `Pdb` catch `BdbQuit` itself).

File last commit:

r21590:1b9c89e1
r22687:ec2d023d
Show More
autogen_magics.py
68 lines | 1.9 KiB | text/x-python | PythonLexer
import os
from IPython.core.alias import Alias
from IPython.core.interactiveshell import InteractiveShell
from IPython.core.magic import MagicAlias
from IPython.utils.text import dedent, indent
shell = InteractiveShell.instance()
magics = shell.magics_manager.magics
def _strip_underline(line):
chars = set(line.strip())
if len(chars) == 1 and ('-' in chars or '=' in chars):
return ""
else:
return line
def format_docstring(func):
docstring = (func.__doc__ or "Undocumented").rstrip()
docstring = indent(dedent(docstring))
# Sphinx complains if indented bits have rst headings in, so strip out
# any underlines in the docstring.
lines = [_strip_underline(l) for l in docstring.splitlines()]
return "\n".join(lines)
output = [
"Line magics",
"===========",
"",
]
# Case insensitive sort by name
def sortkey(s): return s[0].lower()
for name, func in sorted(magics['line'].items(), key=sortkey):
if isinstance(func, Alias) or isinstance(func, MagicAlias):
# Aliases are magics, but shouldn't be documented here
# Also skip aliases to other magics
continue
output.extend([".. magic:: {}".format(name),
"",
format_docstring(func),
""])
output.extend([
"Cell magics",
"===========",
"",
])
for name, func in sorted(magics['cell'].items(), key=sortkey):
if name == "!":
# Special case - don't encourage people to use %%!
continue
if func == magics['line'].get(name, 'QQQP'):
# Don't redocument line magics that double as cell magics
continue
if isinstance(func, MagicAlias):
continue
output.extend([".. cellmagic:: {}".format(name),
"",
format_docstring(func),
""])
here = os.path.dirname(__file__)
dest = os.path.join(here, 'source', 'interactive', 'magics-generated.txt')
with open(dest, "w") as f:
f.write("\n".join(output))