diff options
| author | MinRK <benjaminrk@gmail.com> | 2013-07-26 14:32:56 -0700 |
|---|---|---|
| committer | Preston Holmes <preston@ptone.com> | 2013-07-30 10:24:16 -0700 |
| commit | bf132bcb8d741a161cd9ff61073ac40e7e873b59 (patch) | |
| tree | 48d49bc87c2b625b1c5c8b7cce174840117e515d | |
| parent | 88e4a3a3d932997aabebba772217f954df2fd65b (diff) | |
[1.6.x] 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.
| -rw-r--r-- | django/core/management/commands/shell.py | 40 |
1 files changed, 26 insertions, 14 deletions
diff --git a/django/core/management/commands/shell.py b/django/core/management/commands/shell.py index 851d4e3cfb..00a6602c0b 100644 --- a/django/core/management/commands/shell.py +++ b/django/core/management/commands/shell.py @@ -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." 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): - try: - from IPython.frontend.terminal.ipapp import TerminalIPythonApp - 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. + """Start any version of IPython""" + for ip in (self._ipython, self._ipython_pre_100, self._ipython_pre_011): try: - from IPython.Shell import IPShell - shell = IPShell(argv=[]) - shell.mainloop() + ip() except ImportError: - # IPython not found at all, raise ImportError - raise + pass + else: + return + # no IPython, raise ImportError + raise ImportError("No IPython") def bpython(self): import bpython |
