Skip to content

Commit

Permalink
Added support for IPython.start_ipython in shell
Browse files Browse the repository at this point in the history
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.
  • Loading branch information
minrk authored and ptone committed Jul 30, 2013
1 parent dafec05 commit 75cf5fc
Showing 1 changed file with 26 additions and 14 deletions.
40 changes: 26 additions & 14 deletions django/core/management/commands/shell.py
Original file line number Original file line Diff line number Diff line change
Expand Up @@ -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_pre_011(self):
"""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
app = TerminalIPythonApp.instance()
app.initialize(argv=[])
app.start()

def _ipython(self):
"""Start IPython >= 1.0"""
from IPython import start_ipython
start_ipython(argv=[])

def ipython(self): def ipython(self):
try: """Start any version of IPython"""
from IPython.frontend.terminal.ipapp import TerminalIPythonApp for ip in (self._ipython, self._ipython_pre_100, self._ipython_pre_011):
app = TerminalIPythonApp.instance()
app.initialize(argv=[])
app.start()
except ImportError:
# IPython < 0.11
# Explicitly pass an empty list as arguments, because otherwise
# IPython would use sys.argv from this script.
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
Expand Down

0 comments on commit 75cf5fc

Please sign in to comment.