朱东升 commited on
Commit
f41205f
·
1 Parent(s): 517b50c

requirements update19

Browse files
Files changed (1) hide show
  1. app.py +11 -20
app.py CHANGED
@@ -6,6 +6,7 @@ import sys
6
  from pathlib import Path
7
  import concurrent.futures
8
  import multiprocessing
 
9
 
10
  # 添加当前目录和src目录到模块搜索路径
11
  current_dir = os.path.dirname(os.path.abspath(__file__))
@@ -91,28 +92,18 @@ def evaluate_code(code, language):
91
  dict: 包含评估结果的字典
92
  """
93
  try:
94
- language = language.split('.')[-1] if '.' in language else language # just for go
95
- module_name = f"src.eval_{language.lower()}"
96
- module = importlib.import_module(module_name)
97
-
98
- import tempfile
99
-
100
- # 对于Go语言,确保文件以_test.go结尾
101
- suffix = "_test.go" if language.lower() == "go" else f".{language}"
102
- with tempfile.NamedTemporaryFile(suffix=suffix, delete=False) as temp_file:
103
- temp_file_path = temp_file.name
104
- print(f'temp_file_path: {temp_file_path}')
105
- temp_file.write(code.encode('utf-8'))
106
 
107
- result = module.eval_script(temp_file_path)
108
-
109
- if os.path.exists(temp_file_path):
110
- os.unlink(temp_file_path)
111
-
112
- return result
 
 
113
 
114
- except ImportError as e:
115
- return {"status": "Exception", "error": f"Language {language} not supported: {str(e)}"}
116
  except Exception as e:
117
  return {"status": "Exception", "error": str(e)}
118
 
 
6
  from pathlib import Path
7
  import concurrent.futures
8
  import multiprocessing
9
+ from src.containerized_eval import eval_string_script
10
 
11
  # 添加当前目录和src目录到模块搜索路径
12
  current_dir = os.path.dirname(os.path.abspath(__file__))
 
92
  dict: 包含评估结果的字典
93
  """
94
  try:
95
+ # 使用containerized_eval中的eval_string_script函数
96
+ result = eval_string_script(language, code)
 
 
 
 
 
 
 
 
 
 
97
 
98
+ if result["exit_code"] == 0:
99
+ return {"status": "OK", "output": result["stdout"]}
100
+ else:
101
+ return {
102
+ "status": "Error",
103
+ "error": result["stderr"] if result["stderr"] else "Unknown error",
104
+ "output": result["stdout"]
105
+ }
106
 
 
 
107
  except Exception as e:
108
  return {"status": "Exception", "error": str(e)}
109