@@ -75,6 +75,19 @@ checknullconvert(::Type{T}, x::Ptr, ambig::Bool = false) where {T} = begin
75
75
C. takeresult (T)
76
76
end
77
77
78
+ file_to_pymodule (fname:: String ) = begin
79
+ isfile (fname) || return nothing
80
+ modules = PyDict {String} (pyimport (" sys" ). modules)
81
+ for (n,m) in modules
82
+ if pyhasattr (m, :__file__ )
83
+ fname2 = pystr (String, m. __file__)
84
+ if isfile (fname2) && realpath (fname) == realpath (fname2)
85
+ return n
86
+ end
87
+ end
88
+ end
89
+ end
90
+
78
91
function Base. showerror (io:: IO , e:: PyException )
79
92
print (io, " Python: " )
80
93
@@ -169,15 +182,24 @@ function Base.showerror(io::IO, e::PyException)
169
182
$(fs :: Vector{Tuple{String, String, Int}} ) = [(x.name, x.filename, x.lineno) for x in traceback.extract_tb($(e. bref) )]
170
183
```
171
184
for (i, (name, fname, lineno)) in enumerate (reverse (fs))
172
- println (io)
173
- printstyled (io, " [" , i, " ] " )
174
- printstyled (io, name, bold = true )
175
- printstyled (io, " at " )
176
- # if (m=match(r"^(.*):([0-9]+)$", fname)) !== nothing
177
- # fname = m.captures[1]
178
- # lineno += parse(Int, m.captures[2]) - 1
179
- # end
180
- printstyled (io, fname, " :" , lineno, bold = true )
185
+ if VERSION < v " 1.6.0-rc1"
186
+ println (io)
187
+ printstyled (io, " [" , i, " ] " )
188
+ printstyled (io, name, bold = true )
189
+ printstyled (io, " at " )
190
+ printstyled (io, fname, " :" , lineno, bold = true )
191
+ else
192
+ println (io)
193
+ printstyled (io, " [" , i, " ] " )
194
+ printstyled (io, name, bold = true )
195
+ println (io)
196
+ printstyled (io, " @ " , color = :light_black )
197
+ mod = file_to_pymodule (fname)
198
+ if mod != = nothing
199
+ printstyled (io, mod, " " , color = :magenta )
200
+ end
201
+ printstyled (io, fname, " :" , lineno, color = :light_black )
202
+ end
181
203
end
182
204
catch err
183
205
print (io, " <error while printing stacktrace: $err >" )
0 commit comments