(self, env_path: str, ps: str = "")
| 176 | return None |
| 177 | |
| 178 | def create_venv(self, env_path: str, ps: str = "") -> Optional[str]: |
| 179 | if self.env_type != "system": |
| 180 | return "请选择一个系统环境进行虚拟环境的创建" |
| 181 | |
| 182 | # 创建目录 |
| 183 | parent_dir = os.path.dirname(env_path) |
| 184 | if not os.path.exists(parent_dir): |
| 185 | try: |
| 186 | os.makedirs(parent_dir) |
| 187 | except Exception as e: |
| 188 | return "创建目录失败:{}".format(str(e)) |
| 189 | |
| 190 | try: |
| 191 | subprocess.run( |
| 192 | [self.bin_path, "-m", "venv", env_path], |
| 193 | capture_output=True, text=True, check=True |
| 194 | ) |
| 195 | except Exception as e: |
| 196 | print("创建虚拟环境失败: {}".format(str(e))) |
| 197 | return str(e) |
| 198 | |
| 199 | site_packages = _EnvironmentDetector.get_site_packages(env_path + "/bin/python") |
| 200 | _ep = EnvironmentReporter() |
| 201 | _ep.update_report({ |
| 202 | "bin_path": env_path + "/bin/python", |
| 203 | "version": self.version, |
| 204 | "type": "venv", |
| 205 | "conda_path": self.conda_path, |
| 206 | "venv_name": os.path.basename(env_path), |
| 207 | "activate_sh": "source {}/bin/activate".format(env_path), |
| 208 | "system_path": self.bin_path, |
| 209 | "site_packages": site_packages, |
| 210 | "ps": ps or os.path.basename(env_path), |
| 211 | }) |
| 212 | return None |
| 213 | |
| 214 | def create_venv_sync(self, env_path: str, ps: str = "", call_log:Optional[Callable[[str], None]] = None): |
| 215 | """通过call_log函数实时返回创建日志, 应用于websocket场景""" |
no test coverage detected