How to use the pysnooper.tracer.get_source_from_frame function in PySnooper

To help you get started, we’ve selected a few PySnooper examples, based on popular ways it is used in public projects.

Secure your code as it's written. Use Snyk Code to scan source code in minutes - no build needed - and fix issues immediately.

github ydf0509 / distributed_framework / function_scheduling_distributed_framework / utils / custom_pysnooper.py View on Github external
if key not in old_local_reprs:
                newish_local_reprs[key] = value
            elif old_local_reprs[key] != value:
                modified_local_reprs[key] = value

        newish_string = ('Starting var:.. ' if event == 'call' else
                         'New var:....... ')
        for name, value_repr in newish_local_reprs.items():
            self.write('{indent}{newish_string}{name} = {value_repr}'.format(
                **locals()))
        for name, value_repr in modified_local_reprs.items():
            self.write('{indent}Modified var:.. {name} = {value_repr}'.format(
                **locals()))

        now_string = datetime.datetime.now().time().isoformat()
        source_line = get_source_from_frame(frame)[frame.f_lineno - 1]
        # print(frame)
        # print(dir(frame.f_code))
        # print(frame.f_code.co_filename)
        file_name_and_line = f'{frame.f_code.co_filename}:{frame.f_lineno}'
        # print(file_name_and_line)

        # self.write('{indent}{now_string} {event:9} '
        #            '{frame.f_lineno:4} {source_line}'.format(**locals()))
        file_name_and_line2 = f'"{file_name_and_line}"'
        self.write('{indent}{now_string} {event:9} '  # REMIND 主要是修改了这一行,使debug可点击。
                   '{file_name_and_line2:100} {source_line}'.format(**locals()))
        return self.trace