Skip to main content

Simple, small, interactive, console-based debugger.

Project description

Simple, small, interactive, console-based Python debugger.

  • Cross-platform

  • Django compatibile

KRT inherits from basic python debugger (called bdb). The main reason behind development of package was need of user interface during python script debugging in console (or when graphical interface is not available). Although pdb have the same (and propbably much more) functionality, I found it not so “user friendly”.

Installation

Install using pip.

pip install krt

Basic script debugging

python krt.py script.py
# or
python -m krt script.py

Initializing debugger during program execution

This method of initialization allows initialization at specific line.

import krt

def func(_something, _nothing):
  local_var = [1, 2, 3, 4]
  # now, initialize krt
  krt.trace()
  anything = _somethins + _nothing
  return anything

Initializing krt via decorator. This method will initialize krt at 1st line of decorated method or function.

import krt

# initialize krt
@krt.debug()
def func(_something, _nothing):
  local_var = [1, 2, 3, 4]
  anything = _somethins + _nothing
  return anything

Django usage

One can use methods mentioned above, but method below allows krt triggering only if run with pre-defined django command.

Setting up django command

  1. Inside django applicaiton directory, create directory called management, inside which create directory commands. Following path, must exists django_project/application/management/commands/.

  2. Create __init__.py inside management and commands directories.

  3. Inside directory commands, create file <command>.py, where <command> will be used with manage.py. Let’s say that we’ve used krt_runserver.py.

  4. Insert into created file: ```python from django.core.management.base import BaseCommand from django.core.management.commands import runserver

class Command(runserver.Command):
   help = “Sets trigger for krt decorators”

   def __init__(self, *args, **kwargs):
       from django.conf import settings
       setattr(settings, 'krt_django_decorator_trigger_flag', True)
       super(Command, self).__init__(*args, **kwargs)

Use decorator inside view

Decorator, when used in django project, requires setting of keyword argument django to True. If the django argument is omitted, the debugger will be always initialized!

from django.http import HttpResponse
from  krttest.krt import debug

@debug(django=True)
def index(request):
    return HttpResponse("I'm ok.")

Now, when the django server is run with created command, KRT debugger is being initialized on 1st line of view, otherwise the decorators are being ignored.

python ./manage.py krt_runserver

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

krt-0.2.3.tar.gz (6.1 kB view details)

Uploaded Source

File details

Details for the file krt-0.2.3.tar.gz.

File metadata

  • Download URL: krt-0.2.3.tar.gz
  • Upload date:
  • Size: 6.1 kB
  • Tags: Source
  • Uploaded using Trusted Publishing? No

File hashes

Hashes for krt-0.2.3.tar.gz
Algorithm Hash digest
SHA256 999e379d5d56e65c08e7b787782080815c5d5a9e1c662727e86d9275932aedcc
MD5 5d526e654812da23f63055fa7cd5680c
BLAKE2b-256 97ced9dfa76801ff28f07e9f933d646a834db70432afb449523e38d977e263c1

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