Skip to main content

vscode-debug-visualizer extension for python

Project description

This package adds python support to the Debug Visualizer.

Installation Instructions

The Debug Visualizer is required. To install the extension for python, your're required to install the package within your debug enviroment:

pip install vscodedebugvisualizerpy

supported Types

Numpy Array / PyTorch Tensors / Tensorflow Tensors

All Tensors are converted to numpy arrays and treated alike.

If there multiple dimensions only the last 2 dimensons are visualized, the longer dimension ist treated as x axis. The X axe is downsampled to 1000 points and the y axe only shows the first 10 rows.

Dataframes

Dataframes are transformed to data tables.

Add your own representation/data extractor

Asuming you have a specific Type in your project you want to visualize. You can create a file debugvisualizer.py in your project root directory, that will be injected into the debug process.

Asuming we want to visualize the class Person:

class Person:
    def __init__(self, name, parents=None) -> None:
        self.name = name
        self.parents = [] if parents is None else parents

    def addParent(self, parent: "Person"):
        self.parents.append(parent)

In debugvisualizer.py you can access all available visualizer with the from vscodedebugvisualizer import globalVisualizationFactory. To support your Type you need to create an class that has checkType(anytype) -> Boolean and visualize(self, data) -> None defined. checkType should return True if the given object is supported by the Visualizer. visualize returns a json string that is supported by the visualizer client (see playground).

Finally you need to add the visualizer to the globalVisualizationFactory with globalVisualizationFactory.addVisualizer(YourVisualizer()).

For the Person-Example:

from Person import Person
from pandas.io import json
from vscodedebugvisualizer import globalVisualizationFactory


class PersonVisualizer:
    def checkType(self, t):
        """ checks if the given object `t` is an instance of Person """
        return isinstance(t, Person)

    def visualizePerson(self, person: Person, nodes=[], edges=[]):
        if person.name in [n["id"] for n in nodes]:
            return nodes, edges

        nodes.append(
            {
                "id": person.name,
                "label": person.name,
            }
        )

        for p in person.parents:
            nodes, edges = self.visualizePerson(p, nodes, edges)
            edges.append(
                {
                    "from": p.name,
                    "to": person.name,
                }
            )

        return nodes, edges

    def visualize(self, person: Person):
        jsonDict = {
            "kind": {"graph": True},
            "nodes": [],
            "edges": [],
        }

        self.visualizePerson(person, jsonDict["nodes"], jsonDict["edges"])

        return json.dumps(jsonDict)


globalVisualizationFactory.addVisualizer(PersonVisualizer())

For more visualization examples check out the visualizer playground

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

vscodedebugvisualizer-0.1.0.tar.gz (5.0 kB view hashes)

Uploaded Source

Built Distribution

vscodedebugvisualizer-0.1.0-py3-none-any.whl (8.3 kB view hashes)

Uploaded Python 3

Supported by

AWS AWS Cloud computing and Security Sponsor Datadog Datadog Monitoring Fastly Fastly CDN Google Google Download Analytics Microsoft Microsoft PSF Sponsor Pingdom Pingdom Monitoring Sentry Sentry Error logging StatusPage StatusPage Status page