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

Method add_python_env

mod/project/python/pyenv_tool.py:1155–1191  ·  view source on GitHub ↗
(add_type: str, path: str)

Source from the content-addressed store, hash-verified

1153
1154 @staticmethod
1155 def add_python_env(add_type: str, path: str) -> Optional[str]:
1156 p = Path(path)
1157 if not p.exists():
1158 return "Python环境不存在"
1159 if path.find("conda") and add_type == "system":
1160 tmp_path = path.rsplit("/bin")[0]
1161 if os.path.isfile(tmp_path + "/condabin/conda"):
1162 add_type = "conda"
1163 path = tmp_path + "/condabin/conda"
1164 elif os.path.isfile(tmp_path + "/../../condabin/conda"):
1165 add_type = "conda"
1166 path = os.path.realpath(tmp_path + "/../../condabin/conda")
1167
1168 if add_type == "system":
1169 tmp_p = SystemPythonDetector.find_system_python(path)
1170 if not tmp_p:
1171 return "Python环境不存在"
1172 p_list = [tmp_p]
1173 elif add_type == "venv":
1174 tmp_p = VirtualEnvDetector.find_venv_python(path)
1175 if not tmp_p:
1176 return "Python环境不存在"
1177 else:
1178 p_list = [tmp_p]
1179 system_p = SystemPythonDetector.find_system_python(tmp_p.system_path)
1180 if system_p:
1181 p_list.append(system_p)
1182 elif add_type == "conda":
1183 p_list = CondaDetector.find_conda_python(path)
1184 if not p_list:
1185 return "Python环境不存在"
1186 else:
1187 return "指定类型错误"
1188
1189 _ep = EnvironmentReporter()
1190 _ep.update_report(*[p.to_dict() for p in p_list])
1191 return None
1192
1193 def multi_remove_env(self, *more_path: str) -> List[Dict]:
1194 """批量移除Python虚拟环境(从管理列表中移除)

Callers 2

add_environmentMethod · 0.80
installMethod · 0.80

Calls 9

update_reportMethod · 0.95
EnvironmentReporterClass · 0.85
find_system_pythonMethod · 0.80
find_venv_pythonMethod · 0.80
find_conda_pythonMethod · 0.80
existsMethod · 0.45
findMethod · 0.45
appendMethod · 0.45
to_dictMethod · 0.45

Tested by

no test coverage detected