jwiaduck / pyastest

a command line tool to parse, modify, and compare Python Abstract Syntax Trees

Geek Repo:Geek Repo

Github PK Tool:Github PK Tool

pyastest

a command line tool to parse, modify, and compare Python ASTs

sort of providing an interface to ast.py. initially to provide some better scripting capabilities, but it might evolve into a suite of tools.

Quick Start

Note: Developed with Python 3.9.10!

Note: Rudimentally tested. Proceed with caution!

Currently, only Abstract Syntax Tree equality check between two files is supported.

$ git clone <this repo>
$ cd pyastest
$ python3 pyastest.py diff <path/to/file1> <path/to/file2>
Starting...
...
True: ASTs are equal!
Finished!

Documentation

Options

Only one option must be specified.

Diff

diff command, followed by the files to be diffed, path/to/ORIGINAL.py and path/to/CHANGED.py

diff will read in and generate an AST for each file, then do an equality check on the two ASTs.

Ex: $ python3 pyastest.py diff ~/dev/source.py ~/dev/source_changed.py

Info

info command, followed by one file to be analyzed, path/to/SOURCE.py

info will read in and generate an AST for the given file, then visit the AST to gather info on the nodes. prints a summary of node type information.

Ex: $ python3 pyastest.py info ~/dev/source.py

The output is currently long (flags to come). Pipe to a txt file: $ python3 pyastest.py info ~/dev/source.py > output

About

a command line tool to parse, modify, and compare Python Abstract Syntax Trees

License:MIT License


Languages

Language:Python 100.0%