获取激活环境的shell命令, venv和conda执行对应的脚本即可,
(self)
| 279 | return self._site_pkg_name2bin("gunicorn") |
| 280 | |
| 281 | def activate_shell(self) -> Optional[str]: |
| 282 | """获取激活环境的shell命令, venv和conda执行对应的脚本即可,""" |
| 283 | if self.env_type == "venv": |
| 284 | res_sh = self.activate_sh |
| 285 | elif self.env_type == "conda": |
| 286 | init_sh = "{}/etc/profile.d/conda.sh".format(os.path.dirname(os.path.dirname(self.conda_path))) |
| 287 | remove_panel_py = ( |
| 288 | "bt_env_deactivate > /dev/null 2>&1 \n" |
| 289 | "export PATH=$(echo $PATH | tr ':' '\\n' | grep -v '{}' | tr '\\n' ':') \n" |
| 290 | "export PATH=$(echo $PATH | tr ':' '\\n' | grep -v '{}' | tr '\\n' ':') \n".format( |
| 291 | python_manager_path(), |
| 292 | pyenv_path() |
| 293 | ) |
| 294 | ) |
| 295 | return "{}{} init >/dev/null 2>&1\nsource {}\n{}".format( |
| 296 | remove_panel_py, self.conda_path, init_sh, self.activate_sh |
| 297 | ) |
| 298 | elif self.env_type == "system": |
| 299 | if any((self.bin_path.startswith(i) for i in _SYS_BIN_PATH)): |
| 300 | res_sh = 'export PATH="{}":"$PATH"'.format(os.path.dirname(self.bin_path)) |
| 301 | else: |
| 302 | res_sh = "export _BT_PROJECT_ENV={} && source {} NULL \n".format( |
| 303 | os.path.dirname(os.path.dirname(self.bin_path)), |
| 304 | self._BT_PROJECT_ENV_SHELL |
| 305 | ) |
| 306 | else: |
| 307 | return "" |
| 308 | |
| 309 | if self.env_type != "conda" and len(CondaDetector().find_conda_executable()) > 0: |
| 310 | res_sh = """# 彻底停用 Conda 环境并清除所有 Conda 相关路径 |
| 311 | conda deactivate |
| 312 | unset CONDA_PREFIX |
| 313 | unset CONDA_EXE |
| 314 | unset _CE_CONDA |
| 315 | unset _CE_M |
| 316 | export PATH=$(echo $PATH | tr ':' '\\n' | grep -v 'conda' | tr '\\n' ':') |
| 317 | export LD_LIBRARY_PATH=$(echo $LD_LIBRARY_PATH | tr ':' '\\n' | grep -v 'conda' | tr '\\n' ':') |
| 318 | """ + res_sh |
| 319 | |
| 320 | return res_sh + "\n" |
| 321 | |
| 322 | def _install_pip(self, call_log:Optional[Callable[[str], None]] = None) -> Optional[str]: |
| 323 | if not callable(call_log): |
no test coverage detected