Skip to content

Commit 5e6d6fa

Browse files
Fixed #1202 -- Changed 'manage.py shell' to use IPython if present. Also added '--plain' option, which overrides IPython to use the standard Python interactive prompt
git-svn-id: http://code.djangoproject.com/svn/django/trunk@1930 bcc190cf-cafb-0310-a4f2-bffc1f526a37
1 parent 51f4e95 commit 5e6d6fa

File tree

2 files changed

+31
-6
lines changed

2 files changed

+31
-6
lines changed

‎django/core/management.py

+18-6
Original file line numberDiff line numberDiff line change
@@ -814,11 +814,19 @@ def createcachetable(tablename):
814814
db.db.commit()
815815
createcachetable.args = "[tablename]"
816816

817-
def run_shell():
818-
"Runs a Python interactive interpreter"
819-
import code
820-
code.interact()
821-
run_shell.args = ''
817+
def run_shell(use_plain=False):
818+
"Runs a Python interactive interpreter. Tries to use IPython, if it's available."
819+
try:
820+
if use_plain:
821+
# Don't bother loading IPython, because the user wants plain Python.
822+
raise ImportError
823+
import IPython
824+
shell = IPython.Shell.IPShell()
825+
shell.mainloop()
826+
except ImportError:
827+
import code
828+
code.interact()
829+
run_shell.args = '[--plain]'
822830

823831
# Utilities for command-line script
824832

@@ -878,6 +886,8 @@ def execute_from_command_line(action_mapping=DEFAULT_ACTION_MAPPING):
878886
help='Python path to settings module, e.g. "myproject.settings.main". If this isn\'t provided, the DJANGO_SETTINGS_MODULE environment variable will be used.')
879887
parser.add_option('--pythonpath',
880888
help='Lets you manually add a directory the Python path, e.g. "/home/djangoprojects/myproject".')
889+
parser.add_option('--plain', action='store_true', dest='plain',
890+
help='Tells Django to use plain Python, not IPython, for "shell" command.')
881891
options, args = parser.parse_args()
882892

883893
# Take care of options.
@@ -913,7 +923,9 @@ def execute_from_command_line(action_mapping=DEFAULT_ACTION_MAPPING):
913923
sys.exit(1)
914924
else:
915925
action_mapping[action](username, email, password)
916-
elif action in ('init', 'shell', 'validate'):
926+
elif action == 'shell':
927+
action_mapping[action](options.plain is True)
928+
elif action in ('init', 'validate'):
917929
action_mapping[action]()
918930
elif action == 'inspectdb':
919931
try:

‎docs/django-admin.txt

+13
Original file line numberDiff line numberDiff line change
@@ -156,6 +156,19 @@ Port 7000 on IP address 1.2.3.4::
156156

157157
django-admin.py runserver 1.2.3.4:7000
158158

159+
shell
160+
-----
161+
162+
Starts the Python interactive interpreter.
163+
164+
**New in Django development version:** Uses IPython_, if it's installed. If you
165+
have IPython installed and want to force use of the "plain" Python interpreter,
166+
use the ``--plain`` option, like so::
167+
168+
django-admin.py shell --plain
169+
170+
.. _IPython: http://ipython.scipy.org/
171+
159172
sql [modelmodule modelmodule ...]
160173
---------------------------------
161174

0 commit comments

Comments
 (0)