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 say
    x = 13
    say('x')  # print debug info
    
  • Bash commands to run

    export NEZU_SEEK = 1
    $ py file.py
        @4 l x:int  =>  13
    

Table of content

NEZU

Installation

  • pip

    $ python -m pip install nezu
    
  • poetry

    $ python -m poetry add nezu
    

Usage

Function say

  • Args

    • *keys:str

      Names of varables to inspect

    • note:str = None

      Optional comment. Ignored if equal to None.

    • hide:int = 1

      How deep do you want to hide this message. If hide <= 0, this message will be displayed by default.

  • Python code example

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

    Output of say function is hidden by default. If you wannna see what nezu has to say you need to configure env var NEZU_SEEK with value of 1 or more.

Config

By default nezu is configured by env vars. This can be changed in code.

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
    python3 file.py
    
  • PowerShell

    $env:NEZU_SEEK = 1
    $env:NEZU_COLOR = $True
    $env:NEZU_LOCK = $True
    py 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

  • 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, say
    
    nezu(1, True, False)
    ...
    
  • Tip

    There is no build 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.

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.
 │                          l:local, g:global, b:build-in, u:undefined
 |
 └───────────────────────── Line number of inspection.

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
    python3 file.py
    
  • Example PowerShell command

    $env:NEZU_COLOR = $True
    py file.py
    
  • Example JSON config file

    "nezu" {
      "color": true,
    }
    
  • Example harcoded config

    from nezu import nezu, say
    
    nezu(color = True)
    ...
    

Hiding output

Function say() can be can be hidden into deeper levels of debug via hide parameter. By default only say calls with hide <= 0 will be printed. When you want to display more, change NEZU_SEEK env var. In examples bellow only says hidden up to level 3 are displayed.

  • Python code example

    #file.py
    from nezu import say
    
    say('egg', hide=1)
    say('ham', hide=2)
    say('spam', hide=3)
    say('bacon', hide=4)
    say('lobster', hide=5)
    
  • Bash example

    export NEZU_SEEK = 3 
    python file.py
          @4 u egg
          @5 u ham
          @6 u spam
    

    PowerShell example

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

    "nezu" = {
        "seek": 3
    }
    

TO DO

  • add class method support?
  • add coloring
  • add classes parameter (so you can print only group of logs)
  • indicate shadowing
  • write docstring for say
    • write test for multiline output
  • write tests for name parser
  • write tests for say
  • automate testing with Github actions?
  • automate deployment to PyPI with Github actions?
  • publish to Conda
  • test on different CPython versions
  • test on Pypy
  • test on Anaconda
  • add badges
  • format files with blue
  • remove obsolete tests
  • gitignore .vscode, __pycache, dist
  • write proper documentation
    • How to interpret output
    • Configuration
    • Explain arguments
      • Hiding
      • Notes
      • args
    • Note args
    • brag in readme about being on pypy and and conda
  • make a helper function, that returns dictionary (so it's easier to assert and doesn't require --nezu)
    • write function
    • write docstring for it
    • write tests for it
    • document it in README
  • Write code of conduct
  • Write/generate TOC
  • Update README about configuration
  • Write docstrings to configuration functions

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.3.2.tar.gz (5.9 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.3.2-py3-none-any.whl (6.0 kB view details)

Uploaded Python 3

File details

Details for the file nezu-0.3.2.tar.gz.

File metadata

  • Download URL: nezu-0.3.2.tar.gz
  • Upload date:
  • Size: 5.9 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.3.2.tar.gz
Algorithm Hash digest
SHA256 cebf2f65df9e5445568bc811a0b18579057d6638753dec4d7d60409c09770740
MD5 33dff2fc186a4b503700556ec39ef57a
BLAKE2b-256 a201f92cd1f8127ac985090ad71bba0915bfacc66d5f9acab3385612170e36c5

See more details on using hashes here.

File details

Details for the file nezu-0.3.2-py3-none-any.whl.

File metadata

  • Download URL: nezu-0.3.2-py3-none-any.whl
  • Upload date:
  • Size: 6.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.3.2-py3-none-any.whl
Algorithm Hash digest
SHA256 71d14da8753fa7628f3bd0da3f85b9d8bd6d5ca2d490d2f9b79c1c9594812612
MD5 0ba38d35eb8ba66ac61104b0811a26ca
BLAKE2b-256 9cd6ba16c234229898bf85804c561d82cb95174c0c1efc40199abda4435dcbec

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