Skip to main content

A simple package to add code highlighting to the python debugger (PDB).

Project description

PDB Color

Add some color to the python debugger.

Using PDB:

Code example using PDB

Using PDB Color:

Code example using PDB

Installation

Install with pip.

pip install pdbcolor

Setup

Python can be configured to use PDB Color by changing the PYTHONBREAKPOINT environment variable. To use PDB Color temporarily, add the PYTHONBREAKPOINT=pdbcolor.set_trace prefix before running your python script:

PYTHONBREAKPOINT=pdbcolor.set_trace python3 main.py

To make PDB Color the default for all Python sessions, set the PYTHONBREAKPOINT environment variable to pdbcolor.set_trace. On Mac and Linux, you can do this with the export command:

export PYTHONBREAKPOINT=pdbcolor.set_trace

Add this line to your terminal configuration file (e.g. .bashrc or .zshrc) to ensure the setting persists across terminal settings.

Autocomplete

PDB Color also has autocompletion by default which can be triggered using the TAB key. For example:

$ python3 main.py
> /home/alex/documents/pdbcolor/main.py(9)<module>()
-> y = 2
(Pdb) str.
str.capitalize(    str.isalpha(       str.ljust(         str.rpartition(
str.casefold(      str.isascii(       str.lower(         str.rsplit(
str.center(        str.isdecimal(     str.lstrip(        str.rstrip(
str.count(         str.isdigit(       str.maketrans(     str.split(
str.encode(        str.isidentifier(  str.mro()          str.splitlines(
str.endswith(      str.islower(       str.partition(     str.startswith(
str.expandtabs(    str.isnumeric(     str.removeprefix(  str.strip(
str.find(          str.isprintable(   str.removesuffix(  str.swapcase(
str.format(        str.isspace(       str.replace(       str.title(
str.format_map(    str.istitle(       str.rfind(         str.translate(
str.index(         str.isupper(       str.rindex(        str.upper(
str.isalnum(       str.join(          str.rjust(         str.zfill(
(Pdb) str.

Post-mortem debugging

PDB can can be triggered post-mortem (after an exception has been raised) with the following command:

python3 -m pdb -c continue main.py

PDB Color can be used instead by replacing pdb with pdbcolor.

python3 -m pdbcolor -c continue main.py

Pytest

To use PDB Color with pytest, use --pdbcls=pdbcolor:PdbColor. For example:

python3 -m pytest --pdbcls=pdbcolor:PdbColor

This drops you into PDB Color when a breakpoint is reached.

If you get a pytest OS error such as:

OSError: pytest: reading from stdin while output is captured!  Consider using `-s`.

Using the -s flag stops the error but, for those interested, the error is usually caused by setting PYTHONBREAKPOINT=pdbcolor.set_trace. Changing this back to its default value should stop the error without needing the -s flag. For example:

PYTHONBREAKPOINT=pdb.set_trace python3 -m pytest --pdbcls=pdbcolor:PdbColor

To save on typing, consider adding the following aliases to your terminal configuration file:

alias pdb='PYTHONBREAKPOINT=pdb.set_trace'
alias pdc='PYTHONBREAKPOINT=pdbcolor.set_trace'

The previous command then becomes:

pdb python3 -m pytest --pdbcls=pdbcolor:PdbColor

Project details


Download files

Download the file for your platform. If you're not sure which to choose, learn more about installing packages.

Source Distribution

pdbcolor-0.4.2.tar.gz (8.4 kB view details)

Uploaded Source

Built Distribution

If you're not sure about the file name format, learn more about wheel file names.

pdbcolor-0.4.2-py3-none-any.whl (7.2 kB view details)

Uploaded Python 3

File details

Details for the file pdbcolor-0.4.2.tar.gz.

File metadata

  • Download URL: pdbcolor-0.4.2.tar.gz
  • Upload date:
  • Size: 8.4 kB
  • Tags: Source
  • Uploaded using Trusted Publishing? Yes
  • Uploaded via: twine/6.1.0 CPython/3.12.9

File hashes

Hashes for pdbcolor-0.4.2.tar.gz
Algorithm Hash digest
SHA256 af8682c9c787706184739cf6803368b2ff5078b34e3b9542f1dd13c410f2f649
MD5 665454c7015617e26cf682dec58f9103
BLAKE2b-256 c739dea37247042adad98a9125c3ad1ad831477986c4ed6b64ee80c5d84cd62b

See more details on using hashes here.

Provenance

The following attestation bundles were made for pdbcolor-0.4.2.tar.gz:

Publisher: workflow.yml on Alex-JG3/pdbcolor

Attestations: Values shown here reflect the state when the release was signed and may no longer be current.

File details

Details for the file pdbcolor-0.4.2-py3-none-any.whl.

File metadata

  • Download URL: pdbcolor-0.4.2-py3-none-any.whl
  • Upload date:
  • Size: 7.2 kB
  • Tags: Python 3
  • Uploaded using Trusted Publishing? Yes
  • Uploaded via: twine/6.1.0 CPython/3.12.9

File hashes

Hashes for pdbcolor-0.4.2-py3-none-any.whl
Algorithm Hash digest
SHA256 1f6882875e2405282cdf807406a75952adf0e9a5e2ff53bbfeade6630e3e7b8f
MD5 c55636f999d601b1e69791e5b84ab738
BLAKE2b-256 b3fbe8e3a81a56550cded033fd21dc625389b45b1724a1ca2c34dd3abb7bf1ad

See more details on using hashes here.

Provenance

The following attestation bundles were made for pdbcolor-0.4.2-py3-none-any.whl:

Publisher: workflow.yml on Alex-JG3/pdbcolor

Attestations: Values shown here reflect the state when the release was signed and may no longer be current.

Supported by

AWS Cloud computing and Security Sponsor Datadog Monitoring Depot Continuous Integration Fastly CDN Google Download Analytics Pingdom Monitoring Sentry Error logging StatusPage Status page