forked from krest1nka/llm-gradle-converter
-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathrun.py
executable file
·124 lines (107 loc) · 5.64 KB
/
run.py
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
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
import os
import shutil
import subprocess
import traceback
import pandas as pd
import configparser
import inspect
from colorama import Fore, init as colorama_init
from benchmark_scripts.download_benchmarks import download_benchmarks, check_if_builds
from benchmark_scripts.switch_build_scripts import replace_with_kotlin_build_files
def run_grazie_conversion(llm_converter_path: str, java_path: str, android_path: str):
subprocess_args = ["./gradlew", "run"]
try:
result = subprocess.run(subprocess_args,
cwd=llm_converter_path,
stdout=subprocess.PIPE,
stderr=subprocess.PIPE,
env={"JAVA_HOME": java_path,
"ANDROID_HOME": android_path},
timeout=3600)
print(Fore.WHITE + str(result.stdout))
print(Fore.RED + str(result.stderr))
except subprocess.TimeoutExpired as e:
print(Fore.RED + str(e))
def clear_dir(dir_to_clear: str):
for file in os.listdir(dir_to_clear):
file_path = os.path.join(dir_to_clear, file)
try:
os.chmod(os.path.join(dir_to_clear, file), 0o700)
if not os.path.exists(file_path):
continue
if os.path.isfile(file_path):
os.remove(file_path)
elif os.path.islink(file_path):
os.unlink(file_path)
elif os.path.isdir(file_path):
shutil.rmtree(file_path, ignore_errors=True)
except Exception as e:
print(Fore.RED + str(e))
# def clear_docker_containers():
# subprocess_args = ["docker", "container", "prune", "-f"]
# subprocess_args = "docker rm $(docker ps -a --filter \"ancestor=jetbrains/qodana-jvm\" -q)"
# subprocess.run(subprocess_args)
def save_original_build_files(benchmark_dir: str, groovy_build_files: str):
for root, dirs, files in os.walk(benchmark_dir):
for file in files:
if file == 'build.gradle':
relative_path = os.path.relpath(root, benchmark_dir)
destination_path = os.path.join(groovy_build_files, relative_path, file)
source_path = os.path.join(root, file)
os.makedirs(os.path.dirname(destination_path), exist_ok=True)
shutil.copy2(source_path, destination_path)
def run_qodana(benchmark_dir: str, qodana_token: str, qodana_plugin_jar: str, java_path: str, android_path: str):
my_env = os.environ
my_env["JAVA_HOME"] = java_path
my_env["ANDROID_HOME"] = android_path
for subdir in os.listdir(benchmark_dir):
print(subdir)
if os.path.isdir(os.path.join(benchmark_dir, subdir)):
subprocess_args = ["./run_qodana.sh", os.path.join(benchmark_dir, subdir), qodana_token, qodana_plugin_jar]
try:
result = subprocess.run(subprocess_args,
stdout=subprocess.PIPE,
stderr=subprocess.PIPE,
env=my_env,
timeout=3600)
print(Fore.WHITE + str(result.stdout))
print(Fore.RED + str(result.stderr))
except subprocess.TimeoutExpired as e:
print(Fore.RED + str(e))
def run_llm_gradle_converter_eval(batch_size: int, benchmark_dir: str, groovy_build_files: str, benchmarks_csv: str,
java_path: str, android_path: str, llm_converter_path: str, logs_dir: str):
csv_file = pd.read_csv(benchmarks_csv)
csv_size = len(csv_file)
env = {"JAVA_HOME": java_path,
"ANDROID_HOME": android_path}
for batch_ind in range(0, csv_size, batch_size):
print(Fore.MAGENTA + str(batch_ind))
try:
download_benchmarks(csv_file.iloc[batch_ind:min(batch_ind + batch_size, csv_size)], benchmark_dir, env, logs_dir)
# # save_original_build_files(benchmark_dir, groovy_build_files)
# replace_with_kotlin_build_files(benchmark_dir, logs_dir)
run_grazie_conversion(llm_converter_path, java_path, android_path)
except Exception as e:
print(Fore.MAGENTA + "exception in rum llm")
print(Fore.RED + str(e))
finally:
print(Fore.MAGENTA + "finally")
clear_dir(benchmark_dir)
# NIT: make the path to config passable as an argument
if __name__ == '__main__':
colorama_init()
current_script_path = os.path.dirname(os.path.abspath(__file__))
config = configparser.ConfigParser()
config.read('config.properties')
run_llm_gradle_converter_eval(batch_size=int(config.get('config', 'batch_size')),
benchmark_dir=os.path.join(current_script_path,
config.get('config', 'benchmarks_dir')),
groovy_build_files=os.path.join(current_script_path,
config.get('config', 'groovy_build_files')),
benchmarks_csv=os.path.join(current_script_path,
config.get('config', 'benchmarks_csv')),
java_path=config.get('config', 'java_path'),
android_path=config.get('config', 'android_path'),
llm_converter_path=current_script_path,
logs_dir=os.path.join(current_script_path,
config.get('config', 'logs_dir')))