Skip to content

Commit

Permalink
Added bpython support
Browse files Browse the repository at this point in the history
  • Loading branch information
Ulrich Petri authored and justinabrahms committed Dec 29, 2009
1 parent 312d445 commit ae7a3a0
Showing 1 changed file with 17 additions and 7 deletions.
24 changes: 17 additions & 7 deletions django_extensions/management/commands/shell_plus.py
Original file line number Diff line number Diff line change
Expand Up @@ -4,8 +4,10 @@

class Command(NoArgsCommand):
option_list = NoArgsCommand.option_list + (
make_option('--ipython', action='store_true', dest='ipython',
help='Tells Django to use IPython, not BPython.'),
make_option('--plain', action='store_true', dest='plain',
help='Tells Django to use plain Python, not IPython.'),
help='Tells Django to use plain Python, not BPython nor IPython.'),
make_option('--no-pythonrc', action='store_true', dest='no_pythonrc',
help='Tells Django to use plain Python, not IPython.'),
)
Expand All @@ -20,6 +22,7 @@ def handle_noargs(self, **options):
from django.db.models.loading import get_models, get_apps
loaded_models = get_models()

use_ipython = options.get('ipython', False)
use_plain = options.get('plain', False)
use_pythonrc = not options.get('no_pythonrc', True)

Expand All @@ -42,13 +45,20 @@ def handle_noargs(self, **options):
continue
try:
if use_plain:
# Don't bother loading IPython, because the user wants plain Python.
# Don't bother loading B/IPython, because the user wants plain Python.
raise ImportError
import IPython
# Explicitly pass an empty list as arguments, because otherwise IPython
# would use sys.argv from this script.
shell = IPython.Shell.IPShell(argv=[], user_ns=imported_objects)
shell.mainloop()
try:
if use_ipython:
# User wants IPython
raise ImportError
from bpython import embed
embed(imported_objects)
except ImportError:
import IPython
# Explicitly pass an empty list as arguments, because otherwise IPython
# would use sys.argv from this script.
shell = IPython.Shell.IPShell(argv=[], user_ns=imported_objects)
shell.mainloop()
except ImportError:
# Using normal Python shell
import code
Expand Down

0 comments on commit ae7a3a0

Please sign in to comment.