Skip to main content

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

ppe_debug-0.1.0.tar.gz (6.2 kB view details)

Uploaded Source

Built Distribution

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

ppe_debug-0.1.0-py3-none-any.whl (6.6 kB view details)

Uploaded Python 3

File details

Details for the file ppe_debug-0.1.0.tar.gz.

File metadata

  • Download URL: ppe_debug-0.1.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

Hashes for ppe_debug-0.1.0.tar.gz
Algorithm Hash digest
SHA256 c17d2a1e416d86936c7a67f3582d593b0a54acd3c71893872142733df0a1db91
MD5 23cb77ef6606bee81d15dd1e369d19b9
BLAKE2b-256 0cbf1290cb45a953a274ee5e244b4da3bada70c0365b0ccf70775c4b74e565aa

See more details on using hashes here.

File details

Details for the file ppe_debug-0.1.0-py3-none-any.whl.

File metadata

  • Download URL: ppe_debug-0.1.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

Hashes for ppe_debug-0.1.0-py3-none-any.whl
Algorithm Hash digest
SHA256 fb3c4299b5e1b200c69c0acdc175b4106cdcbd09c2e1e2892970e5522dcc7615
MD5 c1642e7dd6fec795cb070d9e1e9a3be0
BLAKE2b-256 0c129a6cc6ccc149e16888377272754b16c85a743ee95928d7abee69e2406252

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