Skip to content

Commit 71939ae

Browse files
committed
Add working tue-install-pip-now
1 parent 21283c4 commit 71939ae

File tree

1 file changed

+39
-0
lines changed

1 file changed

+39
-0
lines changed

src/tue_get/installer_impl.py

Lines changed: 39 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -7,6 +7,8 @@
77
import glob
88
import os
99
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
1012
import re
1113
import shlex
1214
import shutil
@@ -824,6 +826,43 @@ def tue_install_pip(self, pkgs: List[str]) -> bool:
824826
return True
825827

826828
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+
827866
return True
828867

829868
def tue_install_snap(self, pkgs: List[str]) -> bool:

0 commit comments

Comments
 (0)