PrePrintExec - AST-based debugging tool that prints before execution
Project description
PPE - PrePrintExec
A lightweight, non-intrusive debugging tool that uses AST transformation to print debug information before executing your Python code.
Why PPE?
Traditional comments help users understand code, but they are ignored at runtime. With PPE, your comments become actionable debug messages, making your code both readable and insightful during execution. This is especially valuable in complex functions -- PPE shows exactly which step is running and where errors occur, saving time during debugging.
from ppe import ppe_debug
def risky_division(x, y):
return x / y
@ppe_debug
def process_data(data):
total = sum(data) ## Summing data
avg = total / len(data) ## Calculating average
# Many other complex operations...
result = risky_division(avg, 0) ## -
return result
process_data([1, 2, 3])
# Output:
# PPE: Summing data
# PPE: Calculating average
# PPE: result = risky_division(avg, 0)
# Traceback (most recent call last):
# ...
# ZeroDivisionError: float division by zero
With PPE, you see exactly which step triggers the error, making debugging faster and clearer.
Installation
pip install ppe-debug
Quick Start
from ppe import ppe_debug
@ppe_debug
def my_function():
x = 10 ## Setting x value
y = x * 2 ## -
return y
result = my_function()
# Output:
# PPE: Setting x value
# PPE: y = x * 2
Features
- 🎯 Non-intrusive: Just add a decorator
- 🔧 Multiple debug modes: Custom messages, statement echoing, or variable inspection
- 🚀 Zero dependencies: Uses only Python standard library
- 🧹 Clean: Remove decorator to disable debugging
- 🔍 Comprehensive: Works with all Python statements
Usage
Custom Debug Messages
Use ## comments to print your custom debug messages.
@ppe_debug
def calculate():
result = 10 + 5 ## Adding two numbers
return result
# Output:
# PPE: Adding two numbers
Statement Echoing
Use ## - to echo the actual statement being executed.
@ppe_debug
def calculate():
result = 10 + 5 ## -
return result
# Output:
# PPE: result = 10 + 5
Variable Inspection
Use ## @var1,var2 to inspect variable values (prints after execution)
Use ## @before:var1,var2 to inspect variables before execution
Use ## @after:var1,var2 to explicitly inspect variables after execution
Note that if some variables are not defined at the time of inspection, they will trigger an error.
@ppe_debug
def calculate():
a = 1 ## @a
b = 2 ## @after:b
c = a + b ## @before:a,b
d = 10 ## @before:d
return c
# Output:
# PPE: [After] a=1
# PPE: [After] b=2
# PPE: [Before] a=1, b=2
# PPE: Variable inspection failed
License
MIT License - see LICENSE file for details.
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
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 ppe_debug-1.0.0.tar.gz.
File metadata
- Download URL: ppe_debug-1.0.0.tar.gz
- Upload date:
- Size: 6.2 kB
- Tags: Source
- Uploaded using Trusted Publishing? No
- Uploaded via: twine/6.1.0 CPython/3.11.4
File hashes
| Algorithm | Hash digest | |
|---|---|---|
| SHA256 |
b43c4bad3ef90bac48ef414d22dd70253964eceba51e9ca7f82e5e792fca4844
|
|
| MD5 |
a64eca4d936b294b91285bf20d06786c
|
|
| BLAKE2b-256 |
f9b0cb084953749a35494c2175ead531a1ac981bcafc9b669ecec649f843446f
|
File details
Details for the file ppe_debug-1.0.0-py3-none-any.whl.
File metadata
- Download URL: ppe_debug-1.0.0-py3-none-any.whl
- Upload date:
- Size: 6.6 kB
- Tags: Python 3
- Uploaded using Trusted Publishing? No
- Uploaded via: twine/6.1.0 CPython/3.11.4
File hashes
| Algorithm | Hash digest | |
|---|---|---|
| SHA256 |
8a043f56ceb87cf219e793c8d18dd2eb20164e10f3b1438c7ebe606722871c8d
|
|
| MD5 |
360d1776c8ca3acf8791c3350c766b67
|
|
| BLAKE2b-256 |
ac46f2d95d084fe3c44d8a8ae6eb2cfda097e0ff01c24a9392654e84473ba6ae
|