Elegant debuging module
Project description
Nezu
Elegant debug module
-
Python Code Example
# file.py from nezu import dbg x = 13 dbg('x') # Prints debug info.
-
Bash Commands to Debug
export NEZU_SEEK=1 python file.py @4 L.. x:int => 13
-
Powershell Commands to Debug
$env:NEZU_SEEK = 1 python file.py @4 L.. x:int => 13
Table of Contents
Installation
-
Pip
python -m pip install nezu
-
Poetry
python -m poetry add nezu
Usage
- Inspect variables with function
dbg. - Display literals with function
say. - Configure Nezu to show output.
- Interpret output.
- Fix bugs.
Debug Interpretation
Using debbuging function dbg will display something like:
-
Example output
@7 ..B print:function => Prints the values to a stream, or to sys... -
Interpretation
@7 ..B print:function => Prints the values to a stream, or to sys... │ │ │ │ │ │ │ │ │ └─ Value of inspected variable │ │ │ │ │ │ │ └─────────────── Type of inspected variable. │ │ │ │ │ └───────────────────── Name of inspected variable. │ │ │ └───────────────────────── Scope of inspected variable (see bollow). | └─────────────────────────── Line number of inspection. -
Scope codes
L..- local scope, no shadowingLg.- local scope, shadowing globalL.b- local scope, shadowing built-inLgb- local scope, shadowing global and built-in.G.- Global scope, no shadowing.Gb- Global scope, shadowing built-in..B- Built-in scope, no shadowing...- Undefined
Function dbg
To debug, use funtion dbg, it will inspect scopes and values of given keys (variable names etc.).
-
Args
-
*keys:strNames of variables to inspect
-
hide:int = 1This argument is compared with
Nezu.seek. IfNezu.seek >= hidethis debug inspection will be displayed. -
bp:int = 0This argument is compared with
Nezu.flow. IfNezu.flow < bpthis debug inspection will be considered breakpoint.
-
-
Python Code Example
# file.py from nezu import dbg nortius = 3 maximus = int() biggus = {'dickus':'sillius'} dbg('nortius') # Works on simple variables. dbg('maximus.real') # Works on attributes. dbg('print') # Works on functions and built-ins. dbg('biggus["dickus"]') # DOES NOT work on keys and indexes yet.
-
Note
Output of
dbgfunction is hidden by default. If you want to see dbg you need to configure env varNEZU_SEEKwith value of1or more.
Function say
Simple literal output.
-
Args
-
*valValue to display.
-
hide:int = 1This argument is compared with
nezu.seek. Ifnezu.seek >= hidethis call will be displayed. -
bp:int = 0This argument is compared with
Nezu.flow. IfNezu.flow < bpthis call will be considered breakpoint.
-
-
Python Code Example
# file.py from nezu import say biggus = 'dickus' say('biggus') # displays something like ` @5 biggus` say(biggus) # displays something like ` @6 dickus`
-
Note
Output of
dbgfunction is hidden by default. If you want to see dbg you need to configure env varNEZU_SEEKwith value of1or more.
Config
Module nezu creates nezu object that has config attributes used by function dbg.
- Attributes
-
nezu.seek:int = 0Compared to
dbgargumenthide, ifnezu.seek >= hidethendbgwill be printed. -
nezu.color:bool = FalseDetermines if output of
dbgfunction should be colored. -
nezu.lock:bool = FalseIf
nezu.lock = True, this config cannot be changed later, during runtime.
-
Env Vars Config
If you want to use default config method, change your env vars in terminal and run Python script.
-
Bash
export NEZU_SEEK=1 export NEZU_FLOW=5 export NEZU_COLOR=1 export NEZU_LOCK=0 python file.py
-
PowerShell
$env:NEZU_SEEK = 1 $env:NEZU_FLOW = 5 $env:NEZU_COLOR = $True $env:NEZU_LOCK = $False python file.py
JSON Config
If you don't want to use env vars as config, you can call nezu.json() to read config data from json file.
It will search for key nezu inside chosen file.
-
Args
path:str = 'nezu.json'- path of config file
-
Example Python Code
from nezu import nezu, dbg nezu.json('my/json/file.json')
-
Example Config File
"nezu": { "seek": 1, "flow": 5, "color": true, "locked": false }
Hardcoded Config
If you don't want to use env vars as config you can also call object nezu like function to make hardcoded config.
-
Args
-
seek:int = 0Debug level
-
flow:int = 5Skipping breakpoits
-
color:bool = FalseOutput coloring
-
lock:bool = FalseLock this config
-
-
Example
# file.py from nezu import nezu, dbg nezu(1, 7, True, False) ...
-
Tip
There is no built-in support for yaml, toml or .env in nezu This is so nezu can stay free of dependencies. However you can use hardcoded config to pass data from any config file.
Coloring output
By default nezu output is monochrome. If your terminal of choise support coloring you can change that.
-
Example Bash Command
export NEZU_COLOR=1 python file.py
-
Example PowerShell Command
$env:NEZU_COLOR = $True python file.py
-
Example JSON Config File
"nezu": { "color": true, }
-
Example Hardcoded Config
from nezu import nezu, dbg nezu(color = True) ...
Hiding Output
Functions dbg() and say() can be hidden more by hide parameter. By default only calls with hide <= nezu.seek will be printed. In examples bellow only dbg hidden up to level 3 are displayed.
-
Python Code Example
#file.py from nezu import say say('biggus', hide=1) say('dickus', hide=2) say('nortius', hide=3) say('maximus', hide=4) say('sillius', hide=5) say('soddus', hide=6)
-
Bash Example
export NEZU_SEEK=3 python file.py @4 biggus @5 dickus @6 nortius
-
PowerShell Example
$ENV:NEZU_SEEK = 3 python file.py @4 biggus @5 dickus @6 nortius
-
JSON File Example
"nezu": { "seek": 3, }
-
Example Hardcoded Config
from nezu import nezu, dbg nezu(3) ...
Breakpoints
Functions dbg() and say() can be used as breakpoints by bp parameter. Calls with bp > nezu.flow will stop program execution. Hidden calls are never considered brerakpoints. In examples bellow only second call will behave as breakpoint.
-
Python Code Example
#file.py from nezu import dbg say('biggus' bp=6) say('dickus', bp=7) say('nortius', hide=2, bp=8)
-
Bash Example
export NEZU_SEEK=1 export NEZU_FLOW=6 python file.py @4 biggus @5 dickus # Program stop execution until user press Enter @6 nortius
-
PowerShell Example
$ENV:NEZU_SEEK = 1 $ENV:NEZU_FLOW = 6 python file.py @4 biggus @5 dickus # Program stop execution until user press Enter @6 nortius
-
JSON File Example
"nezu": { "flow": 6, }
-
Example Hardcoded Config
from nezu import nezu, dbg nezu(flow = 6) ...
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 nezu-0.5.1a2.tar.gz.
File metadata
- Download URL: nezu-0.5.1a2.tar.gz
- Upload date:
- Size: 14.3 kB
- Tags: Source
- Uploaded using Trusted Publishing? No
- Uploaded via: poetry/1.5.1 CPython/3.11.7 Windows/10
File hashes
| Algorithm | Hash digest | |
|---|---|---|
| SHA256 |
3379b2925abae002d6d5d0e208e14539df0d904c36d8ecd013a98812a09fb510
|
|
| MD5 |
edae2954b5311846417307ba6c17e4b7
|
|
| BLAKE2b-256 |
b69ae5d81ef39e634e17e35b0a6dae653f25a0607287c2b3c2704431e01b5e98
|
File details
Details for the file nezu-0.5.1a2-py3-none-any.whl.
File metadata
- Download URL: nezu-0.5.1a2-py3-none-any.whl
- Upload date:
- Size: 18.5 kB
- Tags: Python 3
- Uploaded using Trusted Publishing? No
- Uploaded via: poetry/1.5.1 CPython/3.11.7 Windows/10
File hashes
| Algorithm | Hash digest | |
|---|---|---|
| SHA256 |
d9e9d4380f08ef42a7df66c564de1867b2e2aa4eced34f2aeb5a97f8ac212f23
|
|
| MD5 |
c2fbe82ed79d193e60425fb767126ca1
|
|
| BLAKE2b-256 |
892ed342a16fe1d593a04f7030e865df83c817a0de10271fc7d54e2863a5ffc1
|