(cls, pyenv: Optional["PythonEnvironment"])
| 470 | |
| 471 | @classmethod |
| 472 | def set_profile_env(cls, pyenv: Optional["PythonEnvironment"]) -> Optional[str]: |
| 473 | if pyenv and pyenv.env_type == "conda": |
| 474 | return "Conda环境不支持直接设置,请在命令行中执行conda activate {}".format(pyenv.venv_name) |
| 475 | if not cls.profile_check_use(): |
| 476 | return "疑似开启了系统加固,无法操作环境变量相关设置" |
| 477 | _profile = cls.return_profile() |
| 478 | if not os.path.isfile("/etc/profile"): |
| 479 | return "文件不存在" |
| 480 | cls._remove_old_python_env() |
| 481 | data = public.readFile(_profile) |
| 482 | data = re.sub(r'# +Start-Python-Env[^\n]*\nif\s+\[ +-f[^\n]*\n# +End-Python-Env', "", data) |
| 483 | data += cls._PYENV_FORMAT_DATA |
| 484 | public.writeFile(_profile, data) |
| 485 | if not pyenv and os.path.isfile(cls._bt_etc_pyenv): |
| 486 | os.remove(cls._bt_etc_pyenv) |
| 487 | return None |
| 488 | if pyenv: |
| 489 | cmd = "#{}\n{}".format(pyenv.bin_path, pyenv.activate_shell()) |
| 490 | public.writeFile(cls._bt_etc_pyenv, cmd) |
| 491 | return None |
| 492 | |
| 493 | def remove(self) -> Optional[str]: |
| 494 | if self.env_type == "conda": |
no test coverage detected