Created
July 3, 2021 23:00
-
-
Save thepalbi/794c90e52d6a50f9b908d66c436181fd to your computer and use it in GitHub Desktop.
Python wrapper to compare with jsinspect
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| import subprocess | |
| import tempfile | |
| # npm install -g jsinspect | |
| additional_arguments = [ | |
| "-I", # Ignore identifers | |
| "-L", # Ignore literals | |
| "-t", "20", # Compare nodes count | |
| "-m", "2", # Minimum number of equal nodes to get a match | |
| ] | |
| def compare(a, b): | |
| with tempfile.NamedTemporaryFile() as file_a, tempfile.NamedTemporaryFile() as file_b: | |
| file_a.write(bytes(a, "utf-8")) | |
| file_a.flush() | |
| file_b.write(bytes(b, "utf-8")) | |
| file_b.flush() | |
| args = ["jsinspect"] + additional_arguments + \ | |
| [file_a.name, file_b.name] | |
| p_result = subprocess.run( | |
| args, capture_output=False, check=False, stdout=subprocess.DEVNULL) | |
| return p_result.returncode == 0 |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment