MCPcopy Create free account
hub / github.com/aaPanel/BaoTa / set_profile_env

Method set_profile_env

mod/project/python/pyenv_tool.py:472–491  ·  view source on GitHub ↗
(cls, pyenv: Optional["PythonEnvironment"])

Source from the content-addressed store, hash-verified

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":

Callers 1

set_python2envMethod · 0.80

Calls 9

profile_check_useMethod · 0.80
readFileMethod · 0.80
writeFileMethod · 0.80
activate_shellMethod · 0.80
formatMethod · 0.45
return_profileMethod · 0.45
subMethod · 0.45
removeMethod · 0.45

Tested by

no test coverage detected