@@ -72,11 +72,11 @@ def detect_best_shell():
7272 return 'code'
7373
7474
75- def get_bpython (options , extra_args ):
76- try :
77- from bpython import embed # NOQA F841
78- except ImportError :
79- return traceback . format_exc ()
75+ def get_bpython (options , extra_args = None ):
76+ if extra_args is None :
77+ extra_args = {}
78+
79+ from bpython import embed # NOQA F841
8080
8181 def launch_bpython ():
8282 imported_objects = get_launch_args (** options )
@@ -104,15 +104,11 @@ def launch_ipython():
104104
105105 return launch_ipython
106106 except ImportError :
107- str_exc = traceback .format_exc ()
108107 # IPython < 0.11
109108 # Explicitly pass an empty list as arguments, because otherwise
110109 # IPython would use sys.argv from this script.
111110 # Notebook not supported for IPython < 0.11.
112- try :
113- from IPython .Shell import IPShell
114- except ImportError :
115- return str_exc + "\n " + traceback .format_exc ()
111+ from IPython .Shell import IPShell
116112
117113 def launch_ipython ():
118114 imported_objects = get_launch_args (** options )
@@ -122,30 +118,26 @@ def launch_ipython():
122118 return launch_ipython
123119
124120
125- def get_ptpython (self , options ):
121+ def get_ptpython (options , vi_mode = False ):
126122 try :
127123 from ptpython .repl import embed , run_config
128124 except ImportError :
129- tb = traceback .format_exc ()
130- try : # prompt_toolkit < v0.27
131- from prompt_toolkit .contrib .repl import embed , run_config
132- except ImportError :
133- return tb
125+ from prompt_toolkit .contrib .repl import embed , run_config
134126
135- def run_ptpython ():
127+ def launch_ptpython ():
136128 imported_objects = get_launch_args (** options )
137129 history_filename = os .path .expanduser ('~/.ptpython_history' )
138130 embed (
139131 globals = imported_objects ,
140132 history_filename = history_filename ,
141- vi_mode = options [ ' vi_mode' ] ,
133+ vi_mode = vi_mode ,
142134 configure = run_config ,
143135 )
144136
145- return run_ptpython
137+ return launch_ptpython
146138
147139
148- def get_ptipython (options ):
140+ def get_ptipython (options , vi_mode = False ):
149141 """Based on django-extensions
150142
151143 Run renamed to launch, get_imported_objects renamed to get_launch_args
@@ -154,20 +146,17 @@ def get_ptipython(options):
154146 from ptpython .ipython import embed
155147 from ptpython .repl import run_config
156148 except ImportError :
157- tb = traceback .format_exc ()
158- try : # prompt_toolkit < v0.27
159- from prompt_toolkit .contrib .ipython import embed
160- from prompt_toolkit .contrib .repl import run_config
161- except ImportError :
162- return tb
149+ # prompt_toolkit < v0.27
150+ from prompt_toolkit .contrib .ipython import embed
151+ from prompt_toolkit .contrib .repl import run_config
163152
164153 def launch_ptipython ():
165154 imported_objects = get_launch_args (** options )
166155 history_filename = os .path .expanduser ('~/.ptpython_history' )
167156 embed (
168157 user_ns = imported_objects ,
169158 history_filename = history_filename ,
170- vi_mode = options [ ' vi_mode' ] ,
159+ vi_mode = vi_mode ,
171160 configure = run_config ,
172161 )
173162
@@ -226,30 +215,25 @@ def get_code(use_pythonrc, imported_objects):
226215 pythonrc_code = handle .read ()
227216 # Match the behavior of the cpython shell where an error in
228217 # PYTHONSTARTUP prints an exception and continues.
229- try :
230- exec (compile (pythonrc_code , pythonrc , 'exec' ), imported_objects )
231- except Exception :
232- import traceback
233-
234- traceback .print_exc ()
218+ exec (compile (pythonrc_code , pythonrc , 'exec' ), imported_objects )
235219
236220 def launch_code ():
237221 code .interact (local = imported_objects )
238222
239223 return launch_code
240224
241225
242- def launch (shell = 'best' , use_pythonrc = False , ** kwargs ):
226+ def launch (shell = 'best' , use_pythonrc = False , use_vi_mode = False , ** kwargs ):
243227 # Also allowing passing shell='code' to force using code.interact
244228 imported_objects = get_launch_args (** kwargs )
245229
246230 if shell == 'best' :
247231 shell = detect_best_shell ()
248232
249233 if shell == 'ptipython' :
250- launch = get_ptipython (options = kwargs )
234+ launch = get_ptipython (options = kwargs , vi_mode = use_vi_mode )
251235 elif shell == 'ptpython' :
252- launch = get_ptpython (options = kwargs )
236+ launch = get_ptpython (options = kwargs , vi_mode = use_vi_mode )
253237 elif shell == 'ipython' :
254238 launch = get_ipython (options = kwargs )
255239 elif shell == 'bpython' :
0 commit comments