@@ -72,11 +72,11 @@ def detect_best_shell():
72
72
return 'code'
73
73
74
74
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
80
80
81
81
def launch_bpython ():
82
82
imported_objects = get_launch_args (** options )
@@ -104,15 +104,11 @@ def launch_ipython():
104
104
105
105
return launch_ipython
106
106
except ImportError :
107
- str_exc = traceback .format_exc ()
108
107
# IPython < 0.11
109
108
# Explicitly pass an empty list as arguments, because otherwise
110
109
# IPython would use sys.argv from this script.
111
110
# 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
116
112
117
113
def launch_ipython ():
118
114
imported_objects = get_launch_args (** options )
@@ -122,30 +118,26 @@ def launch_ipython():
122
118
return launch_ipython
123
119
124
120
125
- def get_ptpython (self , options ):
121
+ def get_ptpython (options , vi_mode = False ):
126
122
try :
127
123
from ptpython .repl import embed , run_config
128
124
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
134
126
135
- def run_ptpython ():
127
+ def launch_ptpython ():
136
128
imported_objects = get_launch_args (** options )
137
129
history_filename = os .path .expanduser ('~/.ptpython_history' )
138
130
embed (
139
131
globals = imported_objects ,
140
132
history_filename = history_filename ,
141
- vi_mode = options [ ' vi_mode' ] ,
133
+ vi_mode = vi_mode ,
142
134
configure = run_config ,
143
135
)
144
136
145
- return run_ptpython
137
+ return launch_ptpython
146
138
147
139
148
- def get_ptipython (options ):
140
+ def get_ptipython (options , vi_mode = False ):
149
141
"""Based on django-extensions
150
142
151
143
Run renamed to launch, get_imported_objects renamed to get_launch_args
@@ -154,20 +146,17 @@ def get_ptipython(options):
154
146
from ptpython .ipython import embed
155
147
from ptpython .repl import run_config
156
148
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
163
152
164
153
def launch_ptipython ():
165
154
imported_objects = get_launch_args (** options )
166
155
history_filename = os .path .expanduser ('~/.ptpython_history' )
167
156
embed (
168
157
user_ns = imported_objects ,
169
158
history_filename = history_filename ,
170
- vi_mode = options [ ' vi_mode' ] ,
159
+ vi_mode = vi_mode ,
171
160
configure = run_config ,
172
161
)
173
162
@@ -226,30 +215,25 @@ def get_code(use_pythonrc, imported_objects):
226
215
pythonrc_code = handle .read ()
227
216
# Match the behavior of the cpython shell where an error in
228
217
# 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 )
235
219
236
220
def launch_code ():
237
221
code .interact (local = imported_objects )
238
222
239
223
return launch_code
240
224
241
225
242
- def launch (shell = 'best' , use_pythonrc = False , ** kwargs ):
226
+ def launch (shell = 'best' , use_pythonrc = False , use_vi_mode = False , ** kwargs ):
243
227
# Also allowing passing shell='code' to force using code.interact
244
228
imported_objects = get_launch_args (** kwargs )
245
229
246
230
if shell == 'best' :
247
231
shell = detect_best_shell ()
248
232
249
233
if shell == 'ptipython' :
250
- launch = get_ptipython (options = kwargs )
234
+ launch = get_ptipython (options = kwargs , vi_mode = use_vi_mode )
251
235
elif shell == 'ptpython' :
252
- launch = get_ptpython (options = kwargs )
236
+ launch = get_ptpython (options = kwargs , vi_mode = use_vi_mode )
253
237
elif shell == 'ipython' :
254
238
launch = get_ipython (options = kwargs )
255
239
elif shell == 'bpython' :
0 commit comments