File tree Expand file tree Collapse file tree 1 file changed +10
-5
lines changed
Expand file tree Collapse file tree 1 file changed +10
-5
lines changed Original file line number Diff line number Diff line change 11import argparse
22import json
3+ import os
34import re
45import subprocess
56import sys
@@ -16,6 +17,7 @@ def create_venv(venv_path):
1617 venv .create (venv_path , with_pip = True )
1718 print (f"Virtual environment will be created at: { venv_path } " , flush = True )
1819
20+
1921def install_requirements (venv_path ):
2022 pip_path = venv_path / ("Scripts" if sys .platform == "win32" else "bin" ) / "pip"
2123 requirements_path = Path (__file__ ).parent / "requirements.txt"
@@ -34,20 +36,20 @@ def install_requirements(venv_path):
3436
3537
3638def ensure_venv ():
37- import importlib .util
38- import os
39-
4039 # 检查必需的包是否已安装
4140 try :
4241 import rich
4342 import tomli
43+
4444 return True
4545 except ImportError :
4646 pass
4747
4848 # 检查是否已经在递归调用中
4949 if os .environ .get ("GRADER_VENV_SETUP" ) == "1" :
50- print ("Error: Failed to set up virtual environment after retry" , file = sys .stderr )
50+ print (
51+ "Error: Failed to set up virtual environment after retry" , file = sys .stderr
52+ )
5153 sys .exit (1 )
5254
5355 # 如果缺少包,创建虚拟环境并安装
@@ -64,13 +66,16 @@ def ensure_venv():
6466 # 设置环境变量标记并重新运行
6567 env = os .environ .copy ()
6668 env ["GRADER_VENV_SETUP" ] = "1"
67- subprocess .run ([str (python_path ), __file__ ] + sys .argv [1 :], env = env , check = False )
69+ subprocess .run (
70+ [str (python_path ), __file__ ] + sys .argv [1 :], env = env , check = False
71+ )
6872 return False
6973 except Exception as e :
7074 print (f"Error setting up virtual environment: { str (e )} " , file = sys .stderr )
7175 # 如果虚拟环境创建失败,清理现有的虚拟环境
7276 if venv_dir .exists ():
7377 import shutil
78+
7479 shutil .rmtree (venv_dir )
7580 sys .exit (1 )
7681
You can’t perform that action at this time.
0 commit comments