通过call_log函数实时返回创建日志, 应用于websocket场景
(self, env_path: str, ps: str = "", call_log:Optional[Callable[[str], None]] = None)
| 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场景""" |
| 216 | if call_log is None: |
| 217 | call_log = lambda x: print(x) |
| 218 | |
| 219 | # 执行命令 |
| 220 | res = _run_command_with_call_log([self.bin_path, "-u", "-m", "venv", env_path], call_log) |
| 221 | if res is not None: |
| 222 | return res |
| 223 | |
| 224 | try: |
| 225 | site_packages = _EnvironmentDetector.get_site_packages(env_path + "/bin/python") |
| 226 | _ep = EnvironmentReporter() |
| 227 | _ep.update_report({ |
| 228 | "bin_path": env_path + "/bin/python", |
| 229 | "version": self.version, |
| 230 | "type": "venv", |
| 231 | "conda_path": self.conda_path, |
| 232 | "venv_name": os.path.basename(env_path), |
| 233 | "activate_sh": "source {}/bin/activate".format(env_path), |
| 234 | "system_path": self.bin_path, |
| 235 | "site_packages": site_packages, |
| 236 | "ps": ps or os.path.basename(env_path), |
| 237 | }) |
| 238 | call_log("虚拟环境创建成功") |
| 239 | return None |
| 240 | except Exception as e: |
| 241 | error_msg = f"更新环境配置失败:{str(e)}" |
| 242 | call_log(error_msg) |
| 243 | return error_msg |
| 244 | |
| 245 | def _site_pkg_name2bin(self, pkg_name: str) -> Optional[str]: |
| 246 | """通过包名查询在site-packages的*-info/RECORD可执行文件的位置 (可用于 pip, gunicorn, uwsgi)""" |
no test coverage detected