|
7 | 7 | import glob
|
8 | 8 | import os
|
9 | 9 | from pathlib import Path
|
| 10 | +from pip import main as pip_main |
| 11 | +from pip._internal.req.constructors import install_req_from_line as pip_install_req_from_line |
10 | 12 | import re
|
11 | 13 | import shlex
|
12 | 14 | import shutil
|
@@ -824,6 +826,43 @@ def tue_install_pip(self, pkgs: List[str]) -> bool:
|
824 | 826 | return True
|
825 | 827 |
|
826 | 828 | def tue_install_pip_now(self, pkgs: List[str]) -> bool:
|
| 829 | + self.tue_install_debug(f"tue-install-pip-now {pkgs=}") |
| 830 | + |
| 831 | + if not pkgs: |
| 832 | + self.tue_install_error("Invalid tue-install-pip-now call: needs packages as argument") |
| 833 | + # ToDo: This depends on behaviour of tue-install-error |
| 834 | + return False |
| 835 | + |
| 836 | + pips_to_install = [] |
| 837 | + git_pips_to_install = [] |
| 838 | + for pkg in pkgs: |
| 839 | + if pkg.startswith("git+"): |
| 840 | + git_pips_to_install.append(pkg) |
| 841 | + continue |
| 842 | + |
| 843 | + req = pip_install_req_from_line(pkg) |
| 844 | + req.check_if_exists(use_user_site=True) |
| 845 | + |
| 846 | + if req.satisfied_by: |
| 847 | + self.tue_install_debug(f"{pkg} is already installed, {req.satisfied_by}") |
| 848 | + else: |
| 849 | + pips_to_install.append(pkg) |
| 850 | + |
| 851 | + if pips_to_install: |
| 852 | + returncode = pip_main(["install", "--user", *pips_to_install]) |
| 853 | + if returncode != 0: |
| 854 | + self.tue_install_error(f"An error occurred while installing pip packages: {pips_to_install}") |
| 855 | + # ToDo: This depends on behaviour of tue-install-error |
| 856 | + return False |
| 857 | + |
| 858 | + if git_pips_to_install: |
| 859 | + for pkg in git_pips_to_install: |
| 860 | + returncode = pip_main(["install", "--user", pkg]) |
| 861 | + if returncode != 0: |
| 862 | + self.tue_install_error(f"An error occurred while installing pip packages: {pkg}") |
| 863 | + # ToDo: This depends on behaviour of tue-install-error |
| 864 | + return False |
| 865 | + |
827 | 866 | return True
|
828 | 867 |
|
829 | 868 | def tue_install_snap(self, pkgs: List[str]) -> bool:
|
|
0 commit comments