A comprehensive Python function debugger with colors, variable tracking, and file output
Project description
Debugger Decorator
A simple Python decorator for debugging functions.
Installation
pip install debugger-decorator
Usage
from debugger_decorator import show_information
@show_information()
def my_function(a, b):
return a + b
my_function(1, 2)
This will print information about the function call, its arguments, return value, and execution time.
Parameters
debug(bool, default=True): Enable or disable debugging output.color_scheme(dict, optional): Custom color scheme for terminal output.track_vars(list or str, optional): Variables to track for changes during execution.log_file(str, optional): File path to write output instead of stdout (plain text, no colors).deep_track(bool, default=False): Use deep copying for variable tracking to detect in-place changes.
Variable Tracking
Track changes to specific variables during function execution:
@show_information(track_vars=['result'])
def calculate(x, y):
result = x + y
result *= 2
return result
calculate(3, 4)
For deep tracking of in-place modifications:
@show_information(track_vars=['data'], deep_track=True)
def modify_list(data):
data.append(5) # Detected with deep_track
return data
Output Redirection
Redirect debug output to a file:
@show_information(log_file='debug.log')
def my_function(a, b):
return a + b
my_function(1, 2) # Output to debug.log
Customizing Colors
You can customize the color scheme for better accessibility or personal preference:
from debugger_decorator import show_information
from colorama import Fore, Style, Back
# High contrast color scheme
high_contrast_colors = {
'header': Style.BRIGHT + Fore.WHITE,
'params': Fore.CYAN,
'running': Style.BRIGHT + Fore.YELLOW,
'return': Back.GREEN + Style.BRIGHT + Fore.BLACK,
'time': Style.BRIGHT + Fore.GREEN,
'error': Style.BRIGHT + Fore.RED,
'dashes': Style.BRIGHT + Fore.WHITE,
'error_dashes': Style.BRIGHT + Fore.RED,
'tracking': Style.BRIGHT + Fore.MAGENTA,
}
@show_information(color_scheme=high_contrast_colors)
def my_function(a, b):
return a + b
my_function(1, 2)
Available color keys:
header: Function name and caller infoparams: Parameter names and valuesrunning: "Running . . ." messagereturn: Return value displaytime: Execution timeerror: Error messagesdashes: Separator lineserror_dashes: Error separator linestracking: Variable change messages
Uses Colorama styles (DIM, NORMAL, BRIGHT) and colors (Fore., Back., Style.*).
Error Handling
The decorator catches and displays exceptions with colors:
@show_information()
def failing_function():
raise ValueError("Something went wrong")
failing_function() # Shows error message and re-raises
Testing
Run the test suite:
python -m pytest tests/ -v
Performance Notes
- Variable tracking uses
sys.settrace, which may slow down execution for large functions. - A warning is printed if execution takes more than 1 second.
- For production, set
debug=Falseto disable output.
Development
- Variable tracking uses
sys.settrace, which may slow down execution for large functions. - A warning is printed if execution takes more than 1 second.
- For production, set
debug=Falseto disable output.
Building the Package
To build the package for distribution:
pip install build
python -m build
This creates dist/debugger_decorator-<version>.tar.gz and dist/debugger_decorator-<version>-py3-none-any.whl.
Publishing to PyPI
-
Install Twine:
pip install twine
-
Upload to Test PyPI (recommended first):
twine upload --repository testpypi dist/*
-
Upload to Production PyPI:
twine upload dist/*
You'll need a PyPI account and API token. Set it up at pypi.org and use __token__ as username with your token as password.
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 debugger_decorator-0.1.4.tar.gz.
File metadata
- Download URL: debugger_decorator-0.1.4.tar.gz
- Upload date:
- Size: 7.5 kB
- Tags: Source
- Uploaded using Trusted Publishing? No
- Uploaded via: twine/6.2.0 CPython/3.14.0
File hashes
| Algorithm | Hash digest | |
|---|---|---|
| SHA256 |
b92fd4ace86f3d8517ca5a57d032d224a81eedcb1b9369878a0f2c707e1dc455
|
|
| MD5 |
97e219898dfee89048a73e7bdcb929df
|
|
| BLAKE2b-256 |
7f3fc5a3c0225ccb72cd4d230570582343d1ba216b6ef992afedcbbb06bf793c
|
File details
Details for the file debugger_decorator-0.1.4-py3-none-any.whl.
File metadata
- Download URL: debugger_decorator-0.1.4-py3-none-any.whl
- Upload date:
- Size: 7.9 kB
- Tags: Python 3
- Uploaded using Trusted Publishing? No
- Uploaded via: twine/6.2.0 CPython/3.14.0
File hashes
| Algorithm | Hash digest | |
|---|---|---|
| SHA256 |
b3c5ffc14083f431482ed181de9392ee0406728105a4c735c9ab2fee7c2c4474
|
|
| MD5 |
46dcd000f63aca238e84d5b461b00d61
|
|
| BLAKE2b-256 |
7d216b07db6d0722f3259c94a26322fce284840eead4118740406dde89e2cc35
|