Permalink
Browse files

Merge pull request #564 from jonathanslenders/feature/shell_plus/prom…

…pt-toolkit-integration

Added python-prompt-toolkit integration for shell_plus
  • Loading branch information...
trbs committed Sep 29, 2014
2 parents 302e1ba + a21d642 commit 510201103d9c2f5e3ce41d974e588011b8eab4ab
Showing with 22 additions and 0 deletions.
  1. +22 −0 django_extensions/management/commands/shell_plus.py
@@ -16,6 +16,8 @@ class Command(NoArgsCommand):
help='Tells Django to use plain Python, not BPython nor IPython.'),
make_option('--bpython', action='store_true', dest='bpython',
help='Tells Django to use BPython, not IPython.'),
make_option('--ptpython', action='store_true', dest='ptpython',
help='Tells Django to use PTPython, not IPython.'),
make_option('--ipython', action='store_true', dest='ipython',
help='Tells Django to use IPython, not BPython.'),
make_option('--notebook', action='store_true', dest='notebook',
@@ -30,6 +32,8 @@ class Command(NoArgsCommand):
help='Ignore autoloading of some apps/models. Can be used several times.'),
make_option('--quiet-load', action='store_true', default=False, dest='quiet_load',
help='Do not display loaded models messages'),
make_option('--vi', action='store_true', default=False, dest='vi_mode',
help='Load Vi key bindings (for --ptpython)'),
)
help = "Like the 'shell' command but autoloads the models of all installed Django apps."
@@ -41,6 +45,7 @@ def handle_noargs(self, **options):
use_ipython = options.get('ipython', False)
use_bpython = options.get('bpython', False)
use_plain = options.get('plain', False)
use_ptpython = options.get('ptpython', False)
use_pythonrc = options.get('use_pythonrc', True)
if options.get("print_sql", False):
@@ -183,7 +188,21 @@ def run_ipython():
shell.mainloop()
return run_ipython
def get_ptpython():
try:
from prompt_toolkit.contrib.repl import embed
except ImportError:
return traceback.format_exc()
def run_ptpython():
imported_objects = import_objects(options, self.style)
history_filename = os.path.expanduser('~/.ptpython_history')
embed(globals=imported_objects, history_filename=history_filename,
vi_mode=options.get('vi_mode', False))
return run_ptpython
shells = (
('ptpython', get_ptpython),
('bpython', get_bpython),
('ipython', get_ipython),
('plain', get_plain),
@@ -207,6 +226,9 @@ def run_ipython():
elif use_bpython:
shell = get_bpython()
shell_name = "BPython"
elif use_ptpython:
shell = get_ptpython()
shell_name = "ptpython"
elif SETTINGS_SHELL_PLUS:
shell_name = SETTINGS_SHELL_PLUS
shell = dict(shells)[shell_name]()

0 comments on commit 5102011

Please sign in to comment.