@@ -1132,51 +1132,25 @@ def exceptHook(*args):
11321132
11331133 This routine is only used when debug=True is set in the configuration settings
11341134 '''
1135- try :
1136- #from IPython.core import ultratb
1137- import IPython .core .ultratb
1138- except :
1139- pass
1140-
1141- try :
1142- from IPython .terminal .embed import InteractiveShellEmbed
1143- import IPython .core
1144- if sys .platform .startswith ('win' ):
1145- IPython .core .ultratb .FormattedTB (call_pdb = False ,color_scheme = 'NoColor' )(* args )
1146- else :
1147- IPython .core .ultratb .FormattedTB (call_pdb = False ,color_scheme = 'LightBG' )(* args )
1148- from IPython .core import getipython
1149- if getipython .get_ipython () is None :
1150- ipshell = InteractiveShellEmbed .instance ()
1151- else :
1152- ipshell = InteractiveShellEmbed ()
1153- except ImportError :
1154- print ('IPython not installed or is really old' )
1155- return
1156- except TypeError : # Ipython 9.x removes color_scheme
1157- try :
1158- IPython .core .ultratb .FormattedTB (call_pdb = False )(* args )
1159- from IPython .core import getipython
1160- if getipython .get_ipython () is None :
1161- ipshell = InteractiveShellEmbed .instance ()
1162- else :
1163- ipshell = InteractiveShellEmbed ()
1164- except Exception as msg :
1165- print ('IPython patch failed, msg=' ,msg )
1166- import inspect
1167- frame = inspect .getinnerframes (args [2 ])[- 1 ][0 ]
1168- msg = 'Entering IPython console at {0.f_code.co_filename} at line {0.f_lineno}\n ' .format (frame )
1135+ import IPython .core
11691136 savehook = sys .excepthook # save the exception hook
1137+ # show the error
1138+ tb_formatter = IPython .core .ultratb .VerboseTB ()
1139+ print (tb_formatter .text (* args ))
1140+ # get the Ipython shell routine
1141+ if IPython .core .getipython .get_ipython () is None :
1142+ ipshell = IPython .terminal .embed .InteractiveShellEmbed .instance ()
1143+ else :
1144+ ipshell = IPython .terminal .embed .InteractiveShellEmbed ()
1145+ # get to the right frame
11701146 try :
1147+ import inspect
1148+ frame = inspect .getinnerframes (args [2 ])[- 1 ][0 ]
1149+ msg = f'Entering IPython console at { frame .f_code .co_filename } at line { frame .f_lineno } \n '
11711150 ipshell (msg ,local_ns = frame .f_locals ,global_ns = frame .f_globals ) # newest (IPython >= 8)
1172- except DeprecationWarning : # IPython <=7
1173- try : # IPython >=5
1174- class c (object ): pass
1175- pseudomod = c () # create something that acts like a module
1176- pseudomod .__dict__ = frame .f_locals
1177- InteractiveShellEmbed (banner1 = msg )(module = pseudomod ,global_ns = frame .f_globals )
1178- except : # 'IPython <5
1179- InteractiveShellEmbed (banner1 = msg )(local_ns = frame .f_locals ,global_ns = frame .f_globals )
1151+ except :
1152+ msg = 'Entering IPython console (no contex)'
1153+ ipshell (msg )
11801154 sys .excepthook = savehook # reset IPython's change to the exception hook
11811155
11821156def DoNothing ():
0 commit comments