Skip to main content

Elegant debuging module

Project description

Nezu

PyPI version License Dependencies

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

NEZU

Installation

  • Pip

    python -m pip install nezu
    
  • Poetry

    python -m poetry add nezu
    

Usage

Output 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 shadowing
    • Lg. - local scope, shadowing global
    • L.b - local scope, shadowing built-in
    • Lgb - 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

Inspect scopes and values of given keys (variable names etc.).

  • Args

    • *keys:str

      Names of variables to inspect

    • note:str = None

      Optional comment. Ignored if equal to None.

    • hide:int = 1

      This argument is compared with nezu.seek. If nezu.seek >= hide this debug inspection will be displayed. If hide <= 0, this message will be displayed by default.

  • Python Code Example

    # file.py
    from nezu import dbg
    
    egg = 3
    ham = int()
    spam = {'spam':'bacon'}
    
    dbg('egg')          # Works on simple variables.
    dbg('ham.real')     # Works on attributes.
    dbg('print')        # Works on functions and built-ins.
    dbg('spam["spam"]') # DOES NOT work on keys and indexes yet.
    
  • Note

    Output of dbg function is hidden by default. If you want to see dbg you need to configure env var NEZU_SEEK with value of 1 or more.

Config

Module nezu creates nezu object that has config attributes used by function dbg.

  • Attributes
    • nezu.seek:int = 0 Compared to dbg argumenthide, if nezu.seek >= hide then dbg will be printed.
    • nezu.color:bool = False Determines if output of dbg function should be colored.
    • nezu.lock:bool = False If 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_COLOR=1
    export NEZU_LOCK=0
    python file.py
    
  • PowerShell

    $env:NEZU_SEEK = 1
    $env:NEZU_COLOR = $True
    $env:NEZU_LOCK = $True
    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,
      "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 = 0 - debug level
    • color:bool = False - output coloring
    • lock:bool = False - lock this config
  • Example

    # file.py
    from nezu import nezu, dbg
    
    nezu(1, 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

Function dbg() can be hidden more by hide parameter. By default only dbg 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 dbg
    
    dbg('egg', hide=1)
    dbg('ham', hide=2)
    dbg('spam', hide=3)
    dbg('bacon', hide=4)
    dbg('lobster', hide=5)
    
  • Bash Example

    export NEZU_SEEK=3
    python file.py
          @4 ... egg
          @5 ... ham
          @6 ... spam
    
  • PowerShell Example

    $ENV:NEZU_SEEK = 3
    python file.py
          @4 ... egg
          @5 ... ham
          @6 ... spam
    
  • JSON File Example

    "nezu": {
        "seek": 3
    }
    

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

nezu-0.5.1a1.tar.gz (13.1 kB view details)

Uploaded Source

Built Distribution

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

nezu-0.5.1a1-py3-none-any.whl (17.0 kB view details)

Uploaded Python 3

File details

Details for the file nezu-0.5.1a1.tar.gz.

File metadata

  • Download URL: nezu-0.5.1a1.tar.gz
  • Upload date:
  • Size: 13.1 kB
  • Tags: Source
  • Uploaded using Trusted Publishing? No
  • Uploaded via: poetry/1.5.1 CPython/3.11.7 Windows/10

File hashes

Hashes for nezu-0.5.1a1.tar.gz
Algorithm Hash digest
SHA256 3be41ea0271b4a27d559c80839274d7bee8eebf095d346ae7007c267dbbb7143
MD5 116dc975df326a314135186138560b78
BLAKE2b-256 531a724ed090d0f2fa03fb8a8732893c40f2f1361489cf3297347412d55635f1

See more details on using hashes here.

File details

Details for the file nezu-0.5.1a1-py3-none-any.whl.

File metadata

  • Download URL: nezu-0.5.1a1-py3-none-any.whl
  • Upload date:
  • Size: 17.0 kB
  • Tags: Python 3
  • Uploaded using Trusted Publishing? No
  • Uploaded via: poetry/1.5.1 CPython/3.11.7 Windows/10

File hashes

Hashes for nezu-0.5.1a1-py3-none-any.whl
Algorithm Hash digest
SHA256 cc9a9bafcefa29d3e2e6a50a64ab784b840ce76371544efd3641bbcac87f14ac
MD5 5fc816e4949bc5378a870d2a88fbdfaf
BLAKE2b-256 8f57aafed60e19a6d014b8c61401037ae6e8f7a72508a425d104918e54090b0c

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