Line-level debug hook decorator driven by ### comments.
Project description
magichash
magichash is a tiny debugging decorator that injects print statements at runtime based on ### markers in your function body — no manual print calls needed.
Install
pip install magichash
For local development:
pip install -e .
Quick Start
from magichash import register
@register
def foo(x, y):
z = x + y ###
w = z * 2 ### z,w
return w
foo(2, 3)
# foo.py:3: z: 5
# foo.py:4:
# z: 5,
# w: 10,
Marker rules
| Marker | Behaviour |
|---|---|
z = x + y ### |
Auto-print assignment targets (z) |
z = x + y ### z,w |
Print the listed expressions (z, w) |
x, y ### |
On non-assignment lines, print the comma-separated names before ### |
Custom mark and callback
Use register(mark=..., callback=...) to override the marker string or the print handler:
from magichash import register
def my_print(loc, var_dict):
print(f"[DEBUG] {loc}: {var_dict}")
@register(mark="#//", callback=my_print)
def bar(x, y):
z = x * y #// x,y
z = x + y #//
return z
bar(2, 3)
# [DEBUG] bar.py:3: {'x': 2, 'y': 3}
# [DEBUG] bar.py:4: {'z': 5}
API
register(func=None, *, mark="###", callback=do_print)
Decorator that instruments a function. Can be used in two ways:
@register # default mark=### and built-in printer
@register(mark="#==", callback=fn) # custom mark / callback
do_print(loc, var_dict)
The default callback. Prints coloured file:line: name: value output to stdout.
Build and Publish
python -m build
python -m twine upload dist/*
Project details
Release history Release notifications | RSS feed
Download files
Download the file for your platform. If you're not sure which to choose, learn more about installing packages.
Source Distribution
Built Distribution
Filter files by name, interpreter, ABI, and platform.
If you're not sure about the file name format, learn more about wheel file names.
Copy a direct link to the current filters
File details
Details for the file magichash-0.1.0.tar.gz.
File metadata
- Download URL: magichash-0.1.0.tar.gz
- Upload date:
- Size: 4.2 kB
- Tags: Source
- Uploaded using Trusted Publishing? No
- Uploaded via: twine/6.2.0 CPython/3.10.12
File hashes
| Algorithm | Hash digest | |
|---|---|---|
| SHA256 |
0281678634e36df6691c1b4006aa9b8a15c1502e787a092ccaf3a4ae1fdf1b31
|
|
| MD5 |
0bbaf8e7b2267146c8e6f605c27c212a
|
|
| BLAKE2b-256 |
7a918bdfc0ee1364b0a88382be4390ef48a357bcf7831a9139708d7be59adfe0
|
File details
Details for the file magichash-0.1.0-py3-none-any.whl.
File metadata
- Download URL: magichash-0.1.0-py3-none-any.whl
- Upload date:
- Size: 4.8 kB
- Tags: Python 3
- Uploaded using Trusted Publishing? No
- Uploaded via: twine/6.2.0 CPython/3.10.12
File hashes
| Algorithm | Hash digest | |
|---|---|---|
| SHA256 |
81113cf0002355cc07167a01b0929da30857994a3c7271ffcad17c5c227ff092
|
|
| MD5 |
94afacbcca1bc61b853956d1c15e82f9
|
|
| BLAKE2b-256 |
939c3f9a04210f803fbd73f50b71f8f9db35e296c9854b40cbf907de821ef338
|