Repository navigation
Expand file tree
/
Copy pathsyntax_check.py
More file actions
91 lines (79 loc) · 2.95 KB
/
Copy pathsyntax_check.py
File metadata and controls
91 lines (79 loc) · 2.95 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
"""
This script is used to check the syntax error brought by merge the pr created by envagent.
"""
import os
data_path = ""
common_dir = "/home/aoyanli.722/MSB_for_envagent_test/multi_swe_bench/harness/repos"
languages = [
"python",
"cpp",
"php",
"kotlin",
"csharp",
"scala",
"swift",
"typescript",
"ruby",
"html",
"golang",
"javascript",
"rust",
"c",
"java",
]
def remove_unkonwn_file():
remove_file_names = []
for lang in languages:
for root, dirs, files in os.walk(os.path.join(common_dir, lang)):
for file in files:
if file.endswith(".py") and "_to_unknown" in file:
remove_file_names.append(os.path.join(root, file))
for file in remove_file_names:
print(file)
# os.remove(file)
def process_init_file():
init_content = ""
for lang in languages:
with open(f"{common_dir}/{lang}/__init__.py", "r") as f:
init_content += f.read()
# ensure the newly added repo in init_content
for file in os.listdir(data_path):
org = file.split("__")[0]
if org.startswith("."):
continue
if org.replace("-", "_").replace(".", "_") not in init_content:
print(f"{org} not in init_content")
# del the incomplete(rebundant) repo
# 在提交pr的时候,同一个机器的其他repo没有配置完,unknow删掉,init也得删掉
for lang in languages:
done_org = os.listdir(os.path.join(common_dir, lang))
remain_importlines = ""
with open(os.path.join(common_dir, lang, "__init__.py"), "r") as f:
importlines = [i.strip() for i in f.readlines()]
for line in importlines:
orgname = line.split(" import *")[0].split(".")[-1]
if orgname not in done_org:
print(f"{orgname} not in done_org")
else:
remain_importlines += line + "\n"
# replace the repo in lang init file
# with open(os.path.join(common_dir, lang,'__init__replace.py'), 'w') as f:
# f.write(remain_importlines)
# del unkonw对应的repo目录下init
for lang in languages:
for root, dirs, files in os.walk(os.path.join(common_dir, lang)):
for file in files:
if file == "__init__.py":
with open(os.path.join(root, file), "r") as f:
init_repos = [i.strip() for i in f.readlines()]
del_init_repos = []
for init_repo in init_repos:
if "_to_unknown" in init_repo:
print(f"need del some repo in {root}/{file}")
else:
del_init_repos.append(init_repo)
# with open(os.path.join(root, file), 'w') as f:
# f.write('\n'.join(del_init_repos))
if __name__ == "__main__":
process_init_file()
# remove_unkonwn_file()