Skip to main content

A light weighted module aimed to help debug experience

Project description

debugprint

pypi license version last_commit

A light weighted module aimed to help debug experience

Install

pip install debugp

Usage

Use dp() to show the expression value and keep evaluate.

import numpy as np
from debugprint import dp

dp(
    np.dot(
        np.array([1, 2, 3]),
        np.array([[1], [2], [3]]), 
    )
)
[21:37:28] Debug info of line 11 in <module>:                  debugprint.py:50
        np.dot(np.array([1, 2, 3]), np.array([[1], [2], [3]])): [14]

dp() support printing multiple expressions at the same time, and returns the result in a tuple

from debugprint import dp as _dp

def print_arguments(*args):
    print(args)

print_arguments(
    *_dp(1 + 2 * 3, [x for x in range(10) if x % 3 == 0])
)
[08:34:17] Debug info of line 9 in <module>:                      debugprint.py:50                                                                                                                                                         debugprint.py:50
        1 + 2 * 3: 7
        [x for x in range(10) if x % 3 == 0]: [0, 3, 6, 9]
(7, [0, 3, 6, 9])

You can use dp() multiple times in a line

from debugprint import dp as _dp

a = 2
_dp(_dp(1 + 2 * 3) >> _dp(a))
[08:49:04] Debug info of line 5 in <module>:                                                                                                                                                                              debugprint.py:27
        1 + 2 * 3: 7
        a: 2
        _dp(1 + 2 * 3) >> _dp(a): 1

Configuration

Style

You can change the default color with dp_conf

from debugprint import *

dp_conf.pseudo = "yellow"

a = 2
dp(dp(1 + 2 * 3) >> dp(a))

Before:

before

After:

after

Enable / Disable

You can enable or disable debug print by manipulating dp_conf.enabled

from debugprint import *

a = 1
dp_conf.enabled = False
dp(dp(1 + 2 * 3) >> dp(a))  # Won't print a thing!

Print Hook

You can use a custom function to convert object to string!

from debugprint import *
from objprint import objstr

class A:
    def __init__(self, foo, bar):
        self.foo = foo
        self.bar = bar
        self.baz = B()

class B:
    def __init__(self):
        self.x = 1
        self.y = 2

obj = A("foo", "bar")
dp(obj) # information from repr(obj) is not helpful

dp_conf.print_hook = objstr # change the hook from repr to objstr
dp(obj)
[09:50:25] Debug info of line 17 in <module>:                                                                                                                                                                             debugprint.py:27
        obj: <__main__.A object at 0x000001985793E950>
        
           Debug info of line 20 in <module>:                                                                                                                                                                             debugprint.py:27
        obj: <A 0x1985793e950
                  .bar = 'bar',
                  .baz = <B 0x1985793e8f0
                    .x = 1,
                    .y = 2
                  >,
                  .foo = 'foo'
                >

You can find more detail in debugprint/config.py

Known Bugs

  1. Cannot use dp() in the python interactive console
  2. dp() does not work when multiple statements in one line, i.e. dp(1); dp(2)
  3. Three layers of nested dp() in different lines produces unexpected context hint
dp(
    dp(
        (1, (
            dp(2)))
    ) + (2,)
)
[13:45:35] Debug info of line 9 in <module>:                                                                                                                                                                              debugprint.py:28
        2: 2

           Debug info of line 7 in <module>:                                                                                                                                                                              debugprint.py:28
        (1, dp(2)): (1, 2)

           Debug info of line 6 in <module>:                                                                                                                                                                              debugprint.py:28
        (1, dp(2)): (1, 2, 2) # uh-oh

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

debugp-0.1.6.tar.gz (9.2 kB view details)

Uploaded Source

Built Distribution

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

debugp-0.1.6-py3-none-any.whl (9.6 kB view details)

Uploaded Python 3

File details

Details for the file debugp-0.1.6.tar.gz.

File metadata

  • Download URL: debugp-0.1.6.tar.gz
  • Upload date:
  • Size: 9.2 kB
  • Tags: Source
  • Uploaded using Trusted Publishing? No
  • Uploaded via: twine/4.0.1 CPython/3.10.5

File hashes

Hashes for debugp-0.1.6.tar.gz
Algorithm Hash digest
SHA256 0e6fa4cb3559de9ec5a72167734866faec40d81bc0c8eede19596d5b6f3fc1e6
MD5 91b202668a2598b79d2c8a1a9feb50a2
BLAKE2b-256 703afad4322117b66542cd8708100cc5ab753276727ec33e0a5cddc6cbd41fe0

See more details on using hashes here.

File details

Details for the file debugp-0.1.6-py3-none-any.whl.

File metadata

  • Download URL: debugp-0.1.6-py3-none-any.whl
  • Upload date:
  • Size: 9.6 kB
  • Tags: Python 3
  • Uploaded using Trusted Publishing? No
  • Uploaded via: twine/4.0.1 CPython/3.10.5

File hashes

Hashes for debugp-0.1.6-py3-none-any.whl
Algorithm Hash digest
SHA256 20cf974ad830b450ff49bacaa7b0c03d1207aab489d17941ab7db8fc8f6dab37
MD5 51d2a63c5a5173081aa3ef2b247b9db9
BLAKE2b-256 8a3dda3cf816d38063ca4bf647610b09f32e40b2f7237569f933da98a59dcac5

See more details on using hashes here.

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