Skip to content

cansarigol/pdbr

Repository files navigation

pdbr

PyPI version Python Version

pdbr is intended to make the PDB results more colorful. it uses Rich library to carry out that.

Installing

Install with pip or your favorite PyPi package manager.

pip install pdbr

Breakpoint

In order to use breakpoint(), set PYTHONBREAKPOINT with "pdbr.set_trace"

import os

os.environ["PYTHONBREAKPOINT"] = "pdbr.set_trace"

or just import pdbr

import pdbr

New commands

vars(v)

Get the local variables list as table.

varstree(vt)

Get the local variables list as tree.

inspect(i) / inspectall(ia)

rich.inspect

pp

rich.pretty.pprint

Config

Style

In order to use Rich's traceback, style, and theme, set setup.cfg.

[pdbr]
style = yellow
use_traceback = True
theme = friendly

History

store_history setting is used to keep and reload history, even the prompt is closed and opened again.

[pdbr]
...
store_history=.pdbr_history

Celery

In order to use Celery remote debugger with pdbr, use celery_set_trace as below sample. For more information see the Celery user guide.

from celery import Celery

app = Celery('tasks', broker='pyamqp://guest@localhost//')

@app.task
def add(x, y):
    
    import pdbr; pdbr.celery_set_trace()
    
    return x + y

Vscode user snippet

To create or edit your own snippets, select User Snippets under File > Preferences (Code > Preferences on macOS), and then select python.json.

Place the below snippet in json file for pdbr.

{
  ...
  "pdbr": {
        "prefix": "pdbr",
        "body": "import pdbr; pdbr.set_trace()",
        "description": "Code snippet for pdbr debug"
    },
}

For Celery debug.

{
  ...
  "rdbr": {
        "prefix": "rdbr",
        "body": "import pdbr; pdbr.celery_set_trace()",
        "description": "Code snippet for Celery pdbr debug"
    },
}

Samples

Traceback