| 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() |