alexmojaki / birdseye
- понедельник, 5 февраля 2018 г. в 03:15:42
Quick, convenient, expression-centric, graphical Python debugger using the AST
This is a Python debugger which records the value of expressions in a function call and lets you easily view them after the function exits. For example:
Rather than stepping through lines, move back and forth through loop iterations and see how the values of selected expressions change:
See which expressions raise exceptions, even if they're suppressed:
Expand concrete data structures and objects to see their contents. Lengths and depths are limited to avoid an overload of data.
Calls are organised into functions (which are organised into files) and organised by time, letting you see what happens at a glance:
Simply pip install birdseye
.
For a quick demonstration, copy this example and run it. Then continue from step 2 below.
To debug your own function, decorate it with birdseye.eye
, e.g.
from birdseye import eye
@eye
def foo():
The eye
decorator must be applied before any other decorators, i.e. at the bottom of the list.
birdseye
or python -m birdseye
in a terminal to run the UI server. The command has a single optional argument which is the port number, default 7777.When viewing a function call, you can:
Data is kept in a SQL database. You can configure this by setting the environment variable BIRDSEYE_DB
to a database URL used by SQLAlchemy. The default is sqlite:///$HOME/.birdseye.db
.
Every function call is recorded, and every nontrivial expression is traced. This means that:
repr()
of values is used, provided by the cheap_repr package.There is no API at the moment to collect more or less data. Suggestions are welcome as it's not obvious how to deal with the problem. But the idea of this tool is to be as quick and convenient as possible and to work for most cases. If in a particular situation you have to think carefully about how to use it, it may be better to use more conventional debugging methods.
Asynchronous code is not supported.
I'd love your help! Check out the wiki to get started.
The source file of a decorated function is parsed into the standard Python Abstract Syntax Tree. The tree is then modified so that every statement is wrapped in its own with
statement and every expression is wrapped in a function call. The modified tree is compiled and the resulting code object is used to directly construct a brand new function. This is why the eye
decorator must be applied first: it's not a wrapper like most decorators, so other decorators applied first would almost certainly either have no effect or bypass the tracing. The AST modifications notify the tracer both before and after every expression and statement. This functionality is generic, and in the future it will be extracted into its own package.