Update tests.py
Browse files
tests.py
CHANGED
|
@@ -115,7 +115,7 @@ def run(cmd, timeout_sec,forever_cmd):
|
|
| 115 |
|
| 116 |
child.sendline(command)
|
| 117 |
|
| 118 |
-
while (not child.eof() ) and (time.time()-t<
|
| 119 |
x=child.readline().decode()
|
| 120 |
output=output+x
|
| 121 |
print(x)
|
|
@@ -222,7 +222,7 @@ def run_code(language:str,packages:str,filename: str, code: str,start_cmd:str,fo
|
|
| 222 |
Execute code in a controlled environment with package installation and file handling.
|
| 223 |
Args:
|
| 224 |
language:Programming language of the code (eg:"python", "nodejs", "bash","html",etc).
|
| 225 |
-
packages: Space-separated list of packages to install
|
| 226 |
Preinstalled python packages: gradio, XlsxWriter, openpyxl , mpxj , jpype1.
|
| 227 |
Preinstalled npm packages: express, ejs, chart.js.
|
| 228 |
filename:Name of the file to create (stored in /app/code_interpreter/).
|
|
@@ -248,9 +248,11 @@ def run_code(language:str,packages:str,filename: str, code: str,start_cmd:str,fo
|
|
| 248 |
else:
|
| 249 |
command="ls"
|
| 250 |
if packages != "" or packages != " ":
|
| 251 |
-
|
| 252 |
f"{command} {package_names}", timeout_sec=300,forever_cmd= 'false'
|
| 253 |
)
|
|
|
|
|
|
|
| 254 |
transfer_files2()
|
| 255 |
transfer_files()
|
| 256 |
f = open(os.path.join(destination_dir, filename), "w")
|
|
@@ -258,7 +260,7 @@ def run_code(language:str,packages:str,filename: str, code: str,start_cmd:str,fo
|
|
| 258 |
f.close()
|
| 259 |
global files_list
|
| 260 |
if start_cmd != "" or start_cmd != " ":
|
| 261 |
-
stdot=run(start_cmd,
|
| 262 |
else:
|
| 263 |
stdot="File created successfully."
|
| 264 |
onlyfiles = glob.glob("/app/code_interpreter/*")
|
|
|
|
| 115 |
|
| 116 |
child.sendline(command)
|
| 117 |
|
| 118 |
+
while (not child.eof() ) and (time.time()-t<timeout_sec):
|
| 119 |
x=child.readline().decode()
|
| 120 |
output=output+x
|
| 121 |
print(x)
|
|
|
|
| 222 |
Execute code in a controlled environment with package installation and file handling.
|
| 223 |
Args:
|
| 224 |
language:Programming language of the code (eg:"python", "nodejs", "bash","html",etc).
|
| 225 |
+
packages: Space-separated list of packages to install.(python packages are installed if language set to python and npm packages are installed if language set to nodejs).
|
| 226 |
Preinstalled python packages: gradio, XlsxWriter, openpyxl , mpxj , jpype1.
|
| 227 |
Preinstalled npm packages: express, ejs, chart.js.
|
| 228 |
filename:Name of the file to create (stored in /app/code_interpreter/).
|
|
|
|
| 248 |
else:
|
| 249 |
command="ls"
|
| 250 |
if packages != "" or packages != " ":
|
| 251 |
+
package_logs=run(
|
| 252 |
f"{command} {package_names}", timeout_sec=300,forever_cmd= 'false'
|
| 253 |
)
|
| 254 |
+
if "ERROR" in package_logs:
|
| 255 |
+
return {"package_installation_log":package_logs,"info":"Package installation failed. Please check the package names. Tip:Try using another package/method to accomplish the task."}
|
| 256 |
transfer_files2()
|
| 257 |
transfer_files()
|
| 258 |
f = open(os.path.join(destination_dir, filename), "w")
|
|
|
|
| 260 |
f.close()
|
| 261 |
global files_list
|
| 262 |
if start_cmd != "" or start_cmd != " ":
|
| 263 |
+
stdot=run(start_cmd, 120,forever_cmd)
|
| 264 |
else:
|
| 265 |
stdot="File created successfully."
|
| 266 |
onlyfiles = glob.glob("/app/code_interpreter/*")
|