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

Method pip_list

mod/project/python/pyenv_tool.py:392–423  ·  view source on GitHub ↗
(self, force: bool = False)

Source from the content-addressed store, hash-verified

390 return _run_command_with_call_log(cmd, call_log)
391
392 def pip_list(self, force: bool = False) -> List[Tuple[str, str]]:
393 if not self.pip_bin():
394 return []
395 prefix_path = os.path.dirname(os.path.dirname(self.bin_path))
396 if not force and not any (self.bin_path.startswith(i) for i in _SYS_BIN_PATH):
397 try:
398 old_cache = json.loads(public.readFile(os.path.join(prefix_path, "pip_list.cache")))
399 mtime = int(os.path.getmtime(self.site_packages))
400 if old_cache and int(old_cache.get("mtime", 0)) == mtime:
401 return old_cache["data"]
402 except:
403 pass
404
405 cmd = self.activate_shell() + "\n" + " ".join([self.pip_bin(), "list"])
406 res_out = subprocess.check_output(cmd, text=True, stderr=subprocess.DEVNULL, shell=True)
407 pip_list = []
408 for line in res_out.split("\n"):
409 try:
410 tmp = line.strip().split()
411 if len(tmp) >= 2:
412 if tmp[0] == "Package":
413 continue
414 if tmp[0].startswith("-----"):
415 continue
416 if tmp[1].startswith("("):
417 tmp[1] = tmp[1].strip("()")
418 pip_list.append((tmp[0], tmp[1]))
419 except:
420 pass
421 mtime = int(os.path.getmtime(self.site_packages))
422 public.writeFile(os.path.join(prefix_path, "pip_list.cache"), json.dumps({"mtime": mtime, "data": pip_list}))
423 return pip_list
424
425 def pkg_file_exits(self, pkg_name: str) -> bool:
426 pkg_name_lower = pkg_name.lower()

Callers 2

init_site_server_pkgMethod · 0.95
get_env_infoMethod · 0.80

Calls 11

pip_binMethod · 0.95
activate_shellMethod · 0.95
dirnameMethod · 0.80
readFileMethod · 0.80
writeFileMethod · 0.80
loadsMethod · 0.45
joinMethod · 0.45
getMethod · 0.45
splitMethod · 0.45
appendMethod · 0.45
dumpsMethod · 0.45

Tested by

no test coverage detected