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

Method install_requirement

class/projectModel/pythonModel.py:494–544  ·  view source on GitHub ↗
(self, values: dict, pyenv: PythonEnvironment, call_log: Callable[[str], None])

Source from the content-addressed store, hash-verified

492 return True
493
494 def install_requirement(self, values: dict, pyenv: PythonEnvironment, call_log: Callable[[str], None]):
495 if "requirement_path" in values and values["requirement_path"] is not None:
496 call_log("\n|- 开始安装需求包....\n")
497 requirement_data = public.read_rare_charset_file(values['requirement_path'])
498 if not isinstance(requirement_data, str):
499 call_log("\n|- 未识别到安装包信息\n")
500 list_sh = []
501 list_normative_pkg = []
502 for i in requirement_data.split("\n"):
503 tmp_data = i.strip()
504 if not tmp_data or tmp_data.startswith("#"):
505 continue
506 if re.search(r"-e\s+\.{0,2}/", tmp_data): # 本地库依赖且为可编辑模式的不安装
507 continue
508 tmp_env = ""
509 if tmp_data.find("-e") != -1:
510 tmp_env += "cd {}\n".format(values["path"])
511 if tmp_data.find("git+") != -1:
512 tmp_sh = tmp_env + "{} install {}".format(pyenv.pip_bin(), tmp_data)
513 rep_name_list = [re.compile(r"#egg=(?P<name>\S+)"), re.compile(r"/(?P<name>\S+\.git)")]
514 name = tmp_data
515 for tmp_rep in rep_name_list:
516 tmp_name = tmp_rep.search(tmp_data)
517 if tmp_name:
518 name = tmp_name.group("name")
519 break
520 list_sh.append((name, tmp_sh))
521
522 elif tmp_data.find("file:") != -1:
523 tmp_sh = tmp_env + "{} install {}".format(pyenv.pip_bin(), tmp_data)
524
525 list_sh.append((tmp_data.split("file:", 1)[1], tmp_sh))
526 else:
527 if tmp_data.find("==") != -1:
528 pkg_name, pkg_version = tmp_data.split("==")
529 elif tmp_data.find(">=") != -1:
530 pkg_name, pkg_version = tmp_data.split(">=")
531 else:
532 pkg_name, pkg_version = tmp_data, ""
533 list_normative_pkg.append((pkg_name, pkg_version))
534
535
536 length = len(list_sh) + len(list_normative_pkg)
537 for idx, (name, tmp_sh) in enumerate(list_sh):
538 call_log("\n|- ({}/{})开始安装【{}】...\n".format(idx + 1, length, name))
539 pyenv.exec_shell(tmp_sh, call_log=call_log)
540
541 for idx, (name, pkg_version) in enumerate(list_normative_pkg):
542 call_log("\n|- ({}/{})开始安装【{}】...\n".format(idx + len(list_sh) + 1, length, name))
543 pyenv.pip_install(name, pkg_version, call_log=call_log)
544 call_log("\n|- 需求包安装执行完毕....\n")
545
546 def re_prep_env(self, get: public.dict_obj):
547 name = get.name.strip()

Callers 2

simple_prep_envMethod · 0.95
manage_packageMethod · 0.95

Calls 9

pip_binMethod · 0.80
pip_installMethod · 0.80
splitMethod · 0.45
searchMethod · 0.45
findMethod · 0.45
formatMethod · 0.45
groupMethod · 0.45
appendMethod · 0.45
exec_shellMethod · 0.45

Tested by

no test coverage detected