Skip to content

Commit

Permalink
FIX clean up extra whitespaces
Browse files Browse the repository at this point in the history
  • Loading branch information
AlpacaMax committed Apr 10, 2024
1 parent ee82b4e commit e08832e
Show file tree
Hide file tree
Showing 8 changed files with 24 additions and 23 deletions.
5 changes: 3 additions & 2 deletions pyproject.toml
Original file line number Diff line number Diff line change
Expand Up @@ -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="[email protected]" },
]
Expand All @@ -22,7 +22,8 @@ dependencies = [
"clang",
"tree-sitter",
"tqdm",
"GitPython"
"GitPython",
"flask",
]

[project.urls]
Expand Down
2 changes: 1 addition & 1 deletion src/mayat/AST.py
Original file line number Diff line number Diff line change
Expand Up @@ -33,7 +33,7 @@ def hash(self):
).hexdigest()

return self.fingerprint

def hash_non_recursive(self):
"""
Equivalent to hash() but non-recursive
Expand Down
10 changes: 5 additions & 5 deletions src/mayat/Checker.py
Original file line number Diff line number Diff line change
Expand Up @@ -6,18 +6,18 @@ 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()

for node in self.flattened:
if node in self.removed:
continue
yield node

def remove(self, node):
self.removed.update(node.preorder())

def __len__(self):
return len(self.flattened)

Expand All @@ -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 = []
Expand Down Expand Up @@ -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])

Expand Down
10 changes: 5 additions & 5 deletions src/mayat/Result.py
Original file line number Diff line number Diff line change
Expand Up @@ -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"
Expand All @@ -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:
Expand Down
8 changes: 4 additions & 4 deletions src/mayat/frontends/Python.py
Original file line number Diff line number Diff line change
Expand Up @@ -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):
Expand All @@ -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)
Expand All @@ -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:
Expand Down Expand Up @@ -84,4 +84,4 @@ def main(
result,
format=args.output_format,
list_all=args.list_all
))
))
4 changes: 2 additions & 2 deletions src/mayat/result_viewer/app.py
Original file line number Diff line number Diff line change
Expand Up @@ -43,7 +43,7 @@ def code_to_highlighted_html(code, ranges):
html += "<span style='background-color: red; color: white'>"
in_range = True
# print((ln, col), range_i, in_range)

html += c
if c == '\n':
ln += 1
Expand Down Expand Up @@ -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)
app.run(debug=True)
2 changes: 1 addition & 1 deletion src/mayat/result_viewer/templates/result.html
Original file line number Diff line number Diff line change
Expand Up @@ -38,4 +38,4 @@ <h2><code>{{ "{:.2%}".format(entry["similarity"]) }}</code></h2>
</div>
</div>
</body>
</html>
</html>
6 changes: 3 additions & 3 deletions tests/test.py
Original file line number Diff line number Diff line change
Expand Up @@ -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()
unittest.main()

0 comments on commit e08832e

Please sign in to comment.