14
14
import bdb
15
15
import logging
16
16
import os
17
+ import re
17
18
import signal
18
19
import sys
19
20
import traceback
@@ -58,6 +59,15 @@ def __init__(self, *args, **kwargs):
58
59
self .update_gui_frontend = False
59
60
self ._spyder_theme = 'dark'
60
61
62
+ # Substrings of the directory where Spyder-kernels is installed
63
+ self ._package_locations = [
64
+ # When the package is properly installed
65
+ os .path .join ("site-packages" , "spyder_kernels" ),
66
+ # When it's installed from the external-deps subrepo. We need this
67
+ # for our tests
68
+ os .path .join ("external-deps" , "spyder-kernels" , "spyder_kernels" )
69
+ ]
70
+
61
71
# register post_execute
62
72
self .events .register ('post_execute' , self .do_post_execute )
63
73
@@ -74,16 +84,37 @@ def ask_exit(self):
74
84
super ().ask_exit ()
75
85
76
86
def _showtraceback (self , etype , evalue , stb ):
77
- """
78
- Don't show a traceback when exiting our debugger after entering
79
- it through a `breakpoint()` call.
80
-
81
- This is because calling `!exit` after `breakpoint()` raises
82
- BdbQuit, which throws a long and useless traceback.
83
- """
87
+ """Handle how tracebacks are displayed in the console."""
88
+ spyder_stb = []
84
89
if etype is bdb .BdbQuit :
85
- stb = ['' ]
86
- super (SpyderShell , self )._showtraceback (etype , evalue , stb )
90
+ # Don't show a traceback when exiting our debugger after entering
91
+ # it through a `breakpoint()` call. This is because calling `!exit`
92
+ # after `breakpoint()` raises BdbQuit, which throws a long and
93
+ # useless traceback.
94
+ spyder_stb .append ('' )
95
+ else :
96
+ # Skip internal frames from the traceback's string representation
97
+ for line in stb :
98
+ if (
99
+ # Verbose mode
100
+ re .match (r"File (.*)" , line )
101
+ # Plain mode
102
+ or re .match (r"\x1b\[(.*) File (.*)" , line )
103
+ ) and (
104
+ # The file line should not contain a location where
105
+ # Spyder-kernels is installed
106
+ any (
107
+ [
108
+ location in line
109
+ for location in self ._package_locations
110
+ ]
111
+ )
112
+ ):
113
+ continue
114
+ else :
115
+ spyder_stb .append (line )
116
+
117
+ super ()._showtraceback (etype , evalue , spyder_stb )
87
118
88
119
def set_spyder_theme (self , theme ):
89
120
"""Set the theme for the console."""
0 commit comments