Skip to content
This repository

HTTPS clone URL

Subversion checkout URL

You can clone with HTTPS or Subversion.

Download ZIP
Browse code

Fixed #1202 -- Changed 'manage.py shell' to use IPython if present. A…

…lso 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
  • Loading branch information...
commit 5e6d6fafae96fa55d754e88cc4cf814b75c32c13 1 parent 51f4e95
Adrian Holovaty authored January 12, 2006
24  django/core/management.py
@@ -814,11 +814,19 @@ def createcachetable(tablename):
814 814
     db.db.commit()
815 815
 createcachetable.args = "[tablename]"
816 816
 
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]'
822 830
 
823 831
 # Utilities for command-line script
824 832
 
@@ -878,6 +886,8 @@ def execute_from_command_line(action_mapping=DEFAULT_ACTION_MAPPING):
878 886
         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.')
879 887
     parser.add_option('--pythonpath',
880 888
         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.')
881 891
     options, args = parser.parse_args()
882 892
 
883 893
     # Take care of options.
@@ -913,7 +923,9 @@ def execute_from_command_line(action_mapping=DEFAULT_ACTION_MAPPING):
913 923
                 sys.exit(1)
914 924
         else:
915 925
             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'):
917 929
         action_mapping[action]()
918 930
     elif action == 'inspectdb':
919 931
         try:
13  docs/django-admin.txt
@@ -156,6 +156,19 @@ Port 7000 on IP address 1.2.3.4::
156 156
 
157 157
     django-admin.py runserver 1.2.3.4:7000
158 158
 
  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
+
159 172
 sql [modelmodule modelmodule ...]
160 173
 ---------------------------------
161 174
 

0 notes on commit 5e6d6fa

Please sign in to comment.
Something went wrong with that request. Please try again.