Skip to content

Set break points and print local variables, inspect the call stack or start the Python Debugger.

License

Notifications You must be signed in to change notification settings

JacobKochems/py_debug_utils

Folders and files

NameName
Last commit message
Last commit date

Latest commit

 

History

1 Commit
 
 
 
 
 
 
 
 
 
 
 
 

Repository files navigation

debug_utils

Set break points and print local variables, inspect the call stack or start the Python Debugger.

Acknowledgment

The function pretty_trace() was taken and adapted from here which was written by @toppk.

Dependencies

  • readchar
  • rich

Usage Demo

demo.py:

#!/usr/bin/env python
from debug_utils import debug_break


def fibonacci(n: int) -> int:
    debug_break('n =', n)
    if n in {0, 1}:
        return n
    if n < 0:
        return fibonacci(n + 2) - fibonacci(n + 1)
    else:
        return fibonacci(n - 1) + fibonacci(n - 2)


def main():
    results = list(map(fibonacci, range(-5, 5)))
    print(results)


if __name__ == '__main__':
    main()

Command:

python /path/to/demo.py

Output:

BREAK POINT @ line 6 in ./demo.py:fibonacci():
n = -5
 Quit [q] | Continue [c] | Show Stack Frame [s]
 Show Traceback [t] | Start Python Debugger [d]
╭──────────────── Traceback (most recent call last) ────────────────╮
│ /path/to/demo.py:6 in fibonacci                                   │
│                                                                   │
│    3                                                              │
│    4                                                              │
│    5 def fibonacci(n: int) -> int:                                │
│ ❱  6 │   debug_break('n =', n)                                    │
│    7 │   if n in {0, 1}:                                          │
│    8 │   │   return n                                             │
│    9 │   if n < 0:                                                │
│                                                                   │
│ ╭─ locals ─╮                                                      │
│ │ n = -5   │                                                      │
│ ╰──────────╯                                                      │
╰───────────────────────────────────────────────────────────────────╯
Exception: pretty_trace
 Quit [q] | Continue [c] | Show Stack Frame [s]
 Show Traceback [t] | Start Python Debugger [d]

About

Set break points and print local variables, inspect the call stack or start the Python Debugger.

Resources

License

Stars

Watchers

Forks

Releases

No releases published

Packages

No packages published

Languages