Added support for IPython.start_ipython in shell
IPython 1.0 introduces an actual stable public API function for starting a normal (non-embedded) IPython session. This is an official public API, which is promised to survive implementation changes.
This commit is contained in:
parent
dafec05548
commit
75cf5fc7f0
|
@ -19,23 +19,35 @@ class Command(NoArgsCommand):
|
||||||
help = "Runs a Python interactive interpreter. Tries to use IPython or bpython, if one of them is available."
|
help = "Runs a Python interactive interpreter. Tries to use IPython or bpython, if one of them is available."
|
||||||
requires_model_validation = False
|
requires_model_validation = False
|
||||||
|
|
||||||
def ipython(self):
|
def _ipython_pre_011(self):
|
||||||
try:
|
"""Start IPython pre-0.11"""
|
||||||
|
from IPython.Shell import IPShell
|
||||||
|
shell = IPShell(argv=[])
|
||||||
|
shell.mainloop()
|
||||||
|
|
||||||
|
def _ipython_pre_100(self):
|
||||||
|
"""Start IPython pre-1.0.0"""
|
||||||
from IPython.frontend.terminal.ipapp import TerminalIPythonApp
|
from IPython.frontend.terminal.ipapp import TerminalIPythonApp
|
||||||
app = TerminalIPythonApp.instance()
|
app = TerminalIPythonApp.instance()
|
||||||
app.initialize(argv=[])
|
app.initialize(argv=[])
|
||||||
app.start()
|
app.start()
|
||||||
except ImportError:
|
|
||||||
# IPython < 0.11
|
def _ipython(self):
|
||||||
# Explicitly pass an empty list as arguments, because otherwise
|
"""Start IPython >= 1.0"""
|
||||||
# IPython would use sys.argv from this script.
|
from IPython import start_ipython
|
||||||
|
start_ipython(argv=[])
|
||||||
|
|
||||||
|
def ipython(self):
|
||||||
|
"""Start any version of IPython"""
|
||||||
|
for ip in (self._ipython, self._ipython_pre_100, self._ipython_pre_011):
|
||||||
try:
|
try:
|
||||||
from IPython.Shell import IPShell
|
ip()
|
||||||
shell = IPShell(argv=[])
|
|
||||||
shell.mainloop()
|
|
||||||
except ImportError:
|
except ImportError:
|
||||||
# IPython not found at all, raise ImportError
|
pass
|
||||||
raise
|
else:
|
||||||
|
return
|
||||||
|
# no IPython, raise ImportError
|
||||||
|
raise ImportError("No IPython")
|
||||||
|
|
||||||
def bpython(self):
|
def bpython(self):
|
||||||
import bpython
|
import bpython
|
||||||
|
|
Loading…
Reference in New Issue