Skip to main content

Ensure the invariance of the Abstract Syntax Tree across commits.

Project description

ASTdiff

Compare two commits in a git repository to guarantee that there are no semantic changes.

Use this tool to corroborate that formatting tools don't change the code. If astdiff returns 0, the Abstract Syntax Tree of the files changed in the commits is the same.

Installation

Using pip:

pip install astdiff

Development Installation

To audit the code, or to modify it, install astdiff in development mode. The tool uses poetry to manage dependencies and to build pip installable packages.

$ git clone https://github.com/auntbertha/astdiff.git
$ cd astdiff
$ poetry develop
$ poetry run pytest

To build new packages:

$ poetry build

and distribute the wheel or tarball from the directory dist/.

Usage

The most basic use of astdiff is to check that a reformatting tool didn't change the meaning of the code. When it's called with no arguments astdiff compares the working tree against the HEAD of the current branch:

$ astdiff
Running: git diff --name-only 9d3219ba027d5a56040d23eb9ee3d23f7a410ad5
Checking astdiff/astdiff.py ... ok
✨ All files are equivalent! ✨
$ echo $?
0

astdiff returns 0 if the ASTs are the same, and returns 1 otherwise. The messages are printed to standard error.

astdiff can also check a given commit, a given commit and the working tree, or any pair of commits. It accepts the names of the commits in the same way that git does.

Use -h or --help to get help:

$ astdiff -h
Usage: astdiff.py [OPTIONS] [COMMITS]...

  Compare the AST of all changed files between commits.

  With no arguments, compare between HEAD and the working tree.
  With one argument COMMIT, compare between COMMIT~1 and COMMIT.
  With two arguments, COMMIT1 and COMMIT2, compare between those two.

  (COMMIT2 can be a dot '.' to compare between COMMIT1 and the working tree)

Options:
  -h, --help  Show this message and exit.

Algorithm

The comparison of the ASTs is a very simple recursive function that traverses the trees in a pre-order depth-first search. It can be audited to verify its correctness: astdiff.compare_ast.

LICENSE

The MIT License (MIT)

Copyright © 2018 Aunt Bertha

Permission is hereby granted, free of charge, to any person obtaining a copy of this software and associated documentation files (the "Software"), to deal in the Software without restriction, including without limitation the rights to use, copy, modify, merge, publish, distribute, sublicense, and/or sell copies of the Software, and to permit persons to whom the Software is furnished to do so, subject to the following conditions:

The above copyright notice and this permission notice shall be included in all copies or substantial portions of the Software.

THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.

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

astdiff-0.2.5.tar.gz (5.6 kB view details)

Uploaded Source

Built Distribution

astdiff-0.2.5-py2.py3-none-any.whl (12.8 kB view details)

Uploaded Python 2 Python 3

File details

Details for the file astdiff-0.2.5.tar.gz.

File metadata

  • Download URL: astdiff-0.2.5.tar.gz
  • Upload date:
  • Size: 5.6 kB
  • Tags: Source
  • Uploaded using Trusted Publishing? No
  • Uploaded via: poetry/0.12.10 CPython/2.7.15 Darwin/16.7.0

File hashes

Hashes for astdiff-0.2.5.tar.gz
Algorithm Hash digest
SHA256 e836602625b4cf24f85adee5109659e372cf6113ffd7432f42827c34e6d994c0
MD5 e4c6d48d47b543c571869a3bb2729c1b
BLAKE2b-256 9a45b078cadd5cdd9fd2c4f2ee30724c50cf076e4d10f0c9ecf8eb1a1ba1bdcb

See more details on using hashes here.

File details

Details for the file astdiff-0.2.5-py2.py3-none-any.whl.

File metadata

  • Download URL: astdiff-0.2.5-py2.py3-none-any.whl
  • Upload date:
  • Size: 12.8 kB
  • Tags: Python 2, Python 3
  • Uploaded using Trusted Publishing? No
  • Uploaded via: poetry/0.12.10 CPython/2.7.15 Darwin/16.7.0

File hashes

Hashes for astdiff-0.2.5-py2.py3-none-any.whl
Algorithm Hash digest
SHA256 e72622d782e87fb83a724d0428c9293d1c8f2acda390b6852f677b2c58be04eb
MD5 e4f93b2f06abb21f05caff1e4944ec96
BLAKE2b-256 b9cb8c99dea62dae707aaba8b80ed6c47d20cf1762f68e2fdaef8a3bb0b93428

See more details on using hashes here.

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