GithubHelp home page GithubHelp logo

hchasestevens / show_ast Goto Github PK

View Code? Open in Web Editor NEW
98.0 5.0 15.0 230 KB

An IPython notebook plugin for visualizing ASTs.

License: MIT License

Jupyter Notebook 93.52% Python 6.48%
ast ipython ipython-notebook ipynb visualization

show_ast's Introduction

showast

PyPI version Liberapay receiving

An IPython/Jupyter notebook plugin for visualizing abstract syntax trees.

Example usage

Examples can be found in this IPython notebook.

import showast
%%showast
print 1 + 2

print 1 + 2 AST

from showast import show_source
import antigravity
show_source(antigravity)

antigravity module AST

Installation

pip install showast

showast has the following Python dependencies:

ipython
graphviz

You will also need to have Graphviz installed.

Use of the alternative nltk-based rendering engine requires the following packages:

nltk
pillow

When using this option, you will additionally need to have Ghostscript installed.

Contacts

show_ast's People

Contributors

hchasestevens avatar leandro-benedet-garcia avatar

Stargazers

 avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar

Watchers

 avatar  avatar  avatar  avatar  avatar

show_ast's Issues

Using SVG output in ipywidget.HTML?

Hi I'd like to use the SVG output generated by the graphviz renderer inside ipywidgets. I don't see yet, if there is a way to get direct access to the SVG, so I could use it like in the attached screenshot.

Screenshot 2019-03-15 at 15 36 41

Requires DISPLAY

This would be a very useful utility (I'm teaching Programming Languages). But, when trying to use showast on a server (no DISPLAY is set) running JupyterHub you get this error:

---------------------------------------------------------------------------
TclError                                  Traceback (most recent call last)
<ipython-input-8-389e57529b45> in <module>()
----> 1 get_ipython().run_cell_magic('showast', '', '\n1 + 1')

/opt/anaconda3/lib/python3.5/site-packages/IPython/core/interactiveshell.py in run_cell_magic(self, magic_name, line, cell)
   2113             magic_arg_s = self.var_expand(line, stack_depth)
   2114             with self.builtin_trap:
-> 2115                 result = fn(magic_arg_s, cell)
   2116             return result
   2117 

/opt/anaconda3/lib/python3.5/site-packages/showast/__init__.py in showast(__, cell)
    154 def showast(__, cell):
    155     m = ast.parse(cell)
--> 156     show_ast(m)
    157 
    158 

/opt/anaconda3/lib/python3.5/site-packages/showast/__init__.py in show_ast(module)
    148     else:
    149         treestring = nltk_treestring(module)
--> 150     tree_image(treestring)
    151 
    152 

/opt/anaconda3/lib/python3.5/site-packages/showast/__init__.py in tree_image(tree)
    122 def tree_image(tree):
    123     t = Tree.fromstring(tree)
--> 124     tv = SizableTreeView(t)
    125     tv._cframe.print_to_file('.temp.ps')
    126     im = Image.open('.temp.ps')

/opt/anaconda3/lib/python3.5/site-packages/showast/__init__.py in __init__(self, *trees)
     86         self._trees = trees
     87 
---> 88         self._top = Tk()
     89 
     90         cf = self._cframe = CanvasFrame(self._top)

/opt/anaconda3/lib/python3.5/tkinter/__init__.py in __init__(self, screenName, baseName, className, useTk, sync, use)
   1866                 baseName = baseName + ext
   1867         interactive = 0
-> 1868         self.tk = _tkinter.create(screenName, baseName, className, interactive, wantobjects, useTk, sync, use)
   1869         if useTk:
   1870             self._loadtk()

TclError: no display name and no $DISPLAY environment variable

This seems like a roundabout way to get a graphical representation. Any ideas for a workaround?

BTW, an SVG would be preferable as an image format.

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    ๐Ÿ–– Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. ๐Ÿ“Š๐Ÿ“ˆ๐ŸŽ‰

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google โค๏ธ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.