From e08832ebfe5809714ac881f376ae572ca2a34d09 Mon Sep 17 00:00:00 2001 From: "Tian(Maxwell) Yang" Date: Wed, 10 Apr 2024 00:51:51 -0500 Subject: [PATCH] FIX clean up extra whitespaces --- pyproject.toml | 5 +++-- src/mayat/AST.py | 2 +- src/mayat/Checker.py | 10 +++++----- src/mayat/Result.py | 10 +++++----- src/mayat/frontends/Python.py | 8 ++++---- src/mayat/result_viewer/app.py | 4 ++-- src/mayat/result_viewer/templates/result.html | 2 +- tests/test.py | 6 +++--- 8 files changed, 24 insertions(+), 23 deletions(-) diff --git a/pyproject.toml b/pyproject.toml index 21a4583..a702eb0 100644 --- a/pyproject.toml +++ b/pyproject.toml @@ -4,7 +4,7 @@ build-backend = "setuptools.build_meta" [project] name = "mayat" -version = "1.1.0" +version = "1.1.1" authors = [ { name="Tian(Maxwell) Yang", email="ty1146@nyu.edu" }, ] @@ -22,7 +22,8 @@ dependencies = [ "clang", "tree-sitter", "tqdm", - "GitPython" + "GitPython", + "flask", ] [project.urls] diff --git a/src/mayat/AST.py b/src/mayat/AST.py index 9207c00..c06bfbe 100644 --- a/src/mayat/AST.py +++ b/src/mayat/AST.py @@ -33,7 +33,7 @@ def hash(self): ).hexdigest() return self.fingerprint - + def hash_non_recursive(self): """ Equivalent to hash() but non-recursive diff --git a/src/mayat/Checker.py b/src/mayat/Checker.py index 1a47340..8a8c90e 100644 --- a/src/mayat/Checker.py +++ b/src/mayat/Checker.py @@ -6,7 +6,7 @@ def __init__(self, ast): self.flattened = ast.preorder() self.flattened.sort(key=lambda node: node.weight, reverse=True) self.removed = set() - + def nodes(self): self.removed = set() @@ -14,10 +14,10 @@ def nodes(self): if node in self.removed: continue yield node - + def remove(self, node): self.removed.update(node.preorder()) - + def __len__(self): return len(self.flattened) @@ -28,7 +28,7 @@ def __init__(self, path1, path2, ast1, ast2, threshold=5): self.path2 = path2 self.flattened1 = FlattenedTree(ast1) self.flattened2 = FlattenedTree(ast2) - + self.threshold = threshold self.similarity = 0 self.overlapping_ranges = [] @@ -90,7 +90,7 @@ def check(self): else: overlaps_in_arrLL2[key][0].append(node) overlaps_in_arrLL2[key][1] += 1 - + for key in overlaps_in_arrLL2: overlaps_in_arrLL2[key][0] = iter(overlaps_in_arrLL2[key][0]) diff --git a/src/mayat/Result.py b/src/mayat/Result.py index 53d834a..9b9a7c0 100644 --- a/src/mayat/Result.py +++ b/src/mayat/Result.py @@ -5,11 +5,11 @@ def to_json(result_dict: dict) -> str: def to_text(result_dict: dict) -> str: result = "" - + result += str(result_dict["current_datetime"]) + "\n\n" - + result += f"Checking function: {result_dict['function']}" + "\n\n" - + result += "Warnings:" + "\n" for warning in result_dict["warnings"]: result += warning + "\n" @@ -35,12 +35,12 @@ def to_text(result_dict: dict) -> str: # for warning in result_dict["warnings"]: # print(warning) # print() - + # print(f"Checker result:") # for entry in sorted(result_dict["result"], key=lambda x: x["similarity"], reverse=True): # print(f"{entry['submission_A']} - {entry['submission_B']}:\t{entry['similarity']:%}") # print() - + # print(f"{result_dict['execution_time']}s") def serialize_result(result_dict: dict, format: str, list_all: bool) -> str: diff --git a/src/mayat/frontends/Python.py b/src/mayat/frontends/Python.py index 76800de..5328950 100644 --- a/src/mayat/frontends/Python.py +++ b/src/mayat/frontends/Python.py @@ -13,7 +13,7 @@ class Python_AST(AST): def __init__(self, parent=None, name=None, text=None, start_pos=None, end_pos=None, kind=None): AST.__init__(self, parent, name, text, start_pos, end_pos, kind) - + @classmethod def create(cls, path): def helper(node, parent=None): @@ -22,7 +22,7 @@ def helper(node, parent=None): name = node.name.encode() elif isinstance(node, ast.Name): name = node.id.encode() - + pos = None if hasattr(node, 'lineno') and hasattr(node, 'col_offset'): pos = (node.lineno, node.col_offset) @@ -42,7 +42,7 @@ def helper(node, parent=None): child_node = helper(child, python_ast_node) python_ast_node.children.append(child_node) python_ast_node.weight += child_node.weight - + return python_ast_node with open(path, 'r') as f: @@ -84,4 +84,4 @@ def main( result, format=args.output_format, list_all=args.list_all - )) \ No newline at end of file + )) diff --git a/src/mayat/result_viewer/app.py b/src/mayat/result_viewer/app.py index f859f4e..f1d9d26 100644 --- a/src/mayat/result_viewer/app.py +++ b/src/mayat/result_viewer/app.py @@ -43,7 +43,7 @@ def code_to_highlighted_html(code, ranges): html += "" in_range = True # print((ln, col), range_i, in_range) - + html += c if c == '\n': ln += 1 @@ -86,4 +86,4 @@ def result(index): if __name__ == "__main__": data = json.loads(open(sys.argv[1]).read()) data["result"].sort(key=lambda x: -x["similarity"]) - app.run(debug=True) \ No newline at end of file + app.run(debug=True) diff --git a/src/mayat/result_viewer/templates/result.html b/src/mayat/result_viewer/templates/result.html index f05076d..28f1f1e 100644 --- a/src/mayat/result_viewer/templates/result.html +++ b/src/mayat/result_viewer/templates/result.html @@ -38,4 +38,4 @@

{{ "{:.2%}".format(entry["similarity"]) }}

- \ No newline at end of file + diff --git a/tests/test.py b/tests/test.py index c0c4ec4..4cd2a41 100644 --- a/tests/test.py +++ b/tests/test.py @@ -17,16 +17,16 @@ def test_TS_C_frontend(self): c_files = [os.path.join(C_SAMPLE_DIR, f) for f in os.listdir(C_SAMPLE_DIR)] result = TS_C.main(c_files, "*", 5) check_similarity(result) - + def test_TS_Java_frontend(self): java_files = [os.path.join(JAVA_SAMPLE_DIR, f) for f in os.listdir(JAVA_SAMPLE_DIR)] result = TS_Java.main(java_files, "*", 20) check_similarity(result) - + def test_TS_Python_frontend(self): python_files = [os.path.join(PYTHON_SAMPLE_DIR, f) for f in os.listdir(PYTHON_SAMPLE_DIR)] result = TS_Java.main(python_files, "*", 5) check_similarity(result) if __name__ == '__main__': - unittest.main() \ No newline at end of file + unittest.main()