Skip to main content

Very simpler debugger providing context

Project description

context

Python debugging with context helper

Don't want complicated debugger but the print("here") isn't enough to help you catch mistakes ? Then you should try this module !

Installation

pip install ctxt

Usage

This example was generated using the notebook in the demo folder.

from context import here, ctxt
"""
here: minimalist debugging
ctxt: complete debugging

Want an intermediate debugging? Instantiate your own Context object :-)
"""

sep = "\n" + 70 * "=" + "\n"

here()
[<ipython-input-1-79eead714f34>:11] in <module>
x = here(5 + 10)
print("x =", x)

print(sep)

y = ctxt(5 + 10)
print("y =", y)

print(sep)

z = ctxt(5, 6, a=10)
print("z =", z)
[<ipython-input-2-db88b4f95185>:1] in <module>
x = 15

======================================================================

[<ipython-input-2-db88b4f95185>:6] in <module>:
> 15
y = 15

======================================================================

[<ipython-input-2-db88b4f95185>:11] in <module>:
> 5
> 6
> a = 10
z = ((5, 6), dict_items([('a', 10)]))
# Handle call inside a function
def my_square(x):
    y = x ** 2
    here()
    return y

s = my_square(5)
print("s =", s)

print(sep)


# Can also wrap a function call
s = here(my_square(10))
print("s =", s)
[<ipython-input-3-323904d716c7>:4] in my_square
s = 25

======================================================================

[<ipython-input-3-323904d716c7>:4] in my_square
[<ipython-input-3-323904d716c7>:14] in <module>
s = 100
# Can also be a function wrapper
@here  # binds to here.wrap
def my_sqrt(x):
    return pow(x, 0.5)

r = my_sqrt(4)
print("r =", r)

print(sep)

# Handles nested call, adding indent per-level
@here
def my_sqrt_bis(x):
    y =  here(pow(x, 0.5))
    return y

r = my_sqrt_bis(16)
print("r =", r)

print(sep)

# Same but with more context
@ctxt
def my_sqrt_ter(x):
    y =  ctxt(pow(x, 0.5))
    return y

r = my_sqrt_ter(25)
print("r =", r)
[CALL: my_sqrt, FROM: <ipython-input-4-10cc6d34de9d>:6 in <module>]
r = 2.0

======================================================================

[CALL: my_sqrt_bis, FROM: <ipython-input-4-10cc6d34de9d>:17 in [...]
  [<ipython-input-4-10cc6d34de9d>:14] in my_sqrt_bis
r = 4.0

======================================================================

[CALL: my_sqrt_ter, FROM: <ipython-input-4-10cc6d34de9d>:28 in [...]
<- in:
> 25
  [<ipython-input-4-10cc6d34de9d>:25] in my_sqrt_ter:
  > 5.0
-> out:
> 5.0
r = 5.0
# If you still want to use the print function to add more context,
# you can wrap the print function using our wrapper

import builtins

@here
def print(*args, **kwargs):
    return builtins.print(*args)

# or
# print = here(builtins.print)

print("hello")

print(sep)  # Yes it will also be affected ;-)

def some_function():
    print("in some_function")


some_function()

# Reset old print function

print = builtins.print
[CALL: print, FROM: <ipython-input-8-b7886cfc88db>:13 in <module>]
hello
[CALL: print, FROM: <ipython-input-8-b7886cfc88db>:15 in <module>]

======================================================================

[CALL: print, FROM: <ipython-input-8-b7886cfc88db>:18 in [...]
in some_function

TODO List:

  • allows more arguments to Context class
  • allows block context with with here as h:

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

ctxt-0.0.2.tar.gz (3.9 kB view details)

Uploaded Source

Built Distribution

ctxt-0.0.2-py3-none-any.whl (4.5 kB view details)

Uploaded Python 3

File details

Details for the file ctxt-0.0.2.tar.gz.

File metadata

  • Download URL: ctxt-0.0.2.tar.gz
  • Upload date:
  • Size: 3.9 kB
  • Tags: Source
  • Uploaded using Trusted Publishing? No
  • Uploaded via: twine/3.2.0 pkginfo/1.7.0 requests/2.22.0 setuptools/50.3.0 requests-toolbelt/0.9.1 tqdm/4.54.0 CPython/3.8.5

File hashes

Hashes for ctxt-0.0.2.tar.gz
Algorithm Hash digest
SHA256 aab54874ca96967c1c45f8c951881719d7d48d8f21a5ec96bd094d9883ea11da
MD5 43f3f7d8a746450c695057cc9d8ae2d2
BLAKE2b-256 5f70adf4db0b653cc214106805cc7a31ca861a3ab63a8263910a1546996159ae

See more details on using hashes here.

File details

Details for the file ctxt-0.0.2-py3-none-any.whl.

File metadata

  • Download URL: ctxt-0.0.2-py3-none-any.whl
  • Upload date:
  • Size: 4.5 kB
  • Tags: Python 3
  • Uploaded using Trusted Publishing? No
  • Uploaded via: twine/3.2.0 pkginfo/1.7.0 requests/2.22.0 setuptools/50.3.0 requests-toolbelt/0.9.1 tqdm/4.54.0 CPython/3.8.5

File hashes

Hashes for ctxt-0.0.2-py3-none-any.whl
Algorithm Hash digest
SHA256 e25d207eab4bc760ffd769e460d4562d8dff30e3c4211eb3ba99f2cddcc923dd
MD5 eb020db957f3814803eb0470527aa6ee
BLAKE2b-256 99458303e6e13e50e76e2931cec1bccb3f10f4862aea187d4ca420de7b3cd905

See more details on using hashes here.

Supported by

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