A powerful debug mode
Project description
Debug Mode
Superpowers when you need them the most
Debug mode is a tiny library that puts at your fingertips powerful tools to debug your code.
What you get
If debug_mode
is activated (see below) you will have the following functions accessible
from everywhere:
ic
from the icecream library. A much better print statement for debugging purposes.iex
a function decorator from ipdb that will start a debugger session if the decorated function raises an exception. Great for those times when you don't know exactly where things are going wrong.wat
from wat to allow you to more deeply inspect all your variables.
On top of that, when you go start the debugger with breakpoint()
or
set_trace()
you will drop into ipdb, a much
better pdb with wat available there too.
Lastly, debug_mode
will create a folder in the current directory named
_debug
and will store it's path under the name debug_folder
and make it
globally accessible. This is great place to throw in plots, temporary files,
etc.
Usage
To use it simply import it and export the DBG
environment variable.
On your code you would normally have the following line sitting there and doing nothing.
import debug_mode
This has zero overhead and truly does nothing. However, 🐛 BUG ALERT 🐛, now
you need all the help that you can get to sort things out. To activate
debug_mode
all you need to do is export DBG
, it can hold any value, it just
needs to be there. You could accomplish this in many ways.
On your current terminal you could do:
export DBG=1
and all subsequent runs of your code would activate debug mode. Otherwise you could use it only for the next invocation of your script:
DBG=1 python myscript.py
or if you want it always on you could export from your bashrc
, zshrc
...
Making Ruff happy
I personally use Ruff for all my linting. Understandably he is not to happy
about all those global objects that he knows nothing about and will shout out
you, e.g for using "undefined" ic
.
You can add the following Ruff configuration to your pyproject.toml
[tool.ruff]
builtins = ["ic", "iex", "wat"]
If you already have a [tool.ruff]
section on your pyproject just add the
builtins part.
Installation
Debug mode is available on pypi:
pip install debug-mode
but you may also just want to copy the debug_mode
folder into your project
and add it's requirements to your project.
pip install icecream ipdb wat-inspector
Credits
Please leave a ⭐ if you find this useful in your projects.
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
Hashes for debug_mode-0.1.1-py3-none-any.whl
Algorithm | Hash digest | |
---|---|---|
SHA256 | 83ba2e01853bc7b214258d72544233561aed6b46eb885a5ac8ffd12789e7697c |
|
MD5 | 0704bacd58224cb9eb2d6b2fa15a0740 |
|
BLAKE2b-256 | 4c77b5d2846d5acaf35b8c69484b57bad490cae6e5200ab273eea17d784fa09c |