in debug/NicerTrace.py [0:0]
def globaltrace_lt(self, frame, why, arg):
"""Handler for call events.
If the code block being entered is to be ignored, returns `None',
else returns self.localtrace.
This is an override to properly show full package names:
1. if it's under site-packages or core python dir - convert to package name
2. otherwise show full path to the python file - usually uninstalled packages
Additionally enter frames now include the line number since some packages have multiple
methods that have the same name and there is no telling which one of them was called.
It was written against https://github.com/python/cpython/blob/3.8/Lib/trace.py. If you're
using a different python version you may have to adapt it should the core implementation
change (but it's unlikely)
"""
if why == "call":
code = frame.f_code
# print(f"\n\n{frame.f_code=}")
# print(dir(code))
filename = frame.f_globals.get("__file__", None)
if filename:
lineno = code.co_firstlineno
# python's trace fails to get the full package name - let's fix it
# strip the common path of python library
modulename = self.strip_py_dirs(filename)
if filename != modulename:
# the package was installed under /.../site-packages, /.../lib/python3.8
modulename, ext = os.path.splitext(modulename)
modulename = modulename.replace("/", ".")
else:
# still full path, because the package is not installed
modulename = filename
if modulename is not None:
# XXX: ignoremods may not work now as before
ignore_it = self.ignore.names(filename, modulename)
if not ignore_it:
if self.trace:
if self.log_pids:
print(os.getpid(), end=" ")
print(f" {modulename}:{lineno} {code.co_name}")
return self.localtrace
else:
return None