Skip to content

Commit 69d1c6d

Browse files
authored
Merge pull request #355 from AYUSHJAIN951/pip_version_patch
Fix pip based installation in helper
2 parents 4464a64 + bd4f6ec commit 69d1c6d

File tree

1 file changed

+12
-3
lines changed

1 file changed

+12
-3
lines changed

lib/helper.py

Lines changed: 12 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -21,6 +21,7 @@
2121
import shutil
2222
import stat
2323
import platform
24+
import importlib.metadata
2425

2526
from .logger import logger_init
2627

@@ -218,6 +219,11 @@ def __init__(self, base_fw=[], opt_fw=[], kvm_fw=[], enable_kvm=False):
218219
# Check for pip if not attempt install and proceed
219220
cmd = "%s --help >/dev/null 2>&1||(curl https://bootstrap.pypa.io/get-pip.py -o get-pip.py && python%s ./get-pip.py)" % (self.pip_cmd, sys.version_info[0])
220221
runcmd(cmd, err_str='Unable to install pip3')
222+
223+
# Get pip version
224+
pip_version_split = importlib.metadata.version(f"pip").split(".")
225+
self.pip_vmajor, self.pip_vminor = int(pip_version_split[0]), int(pip_version_split[1])
226+
221227
self.uninstallitems = base_fw + opt_fw + kvm_fw
222228
if enable_kvm:
223229
self.installitems = self.uninstallitems
@@ -243,15 +249,18 @@ def install(self):
243249
else:
244250
pip_installcmd = '%s install -U' % self.pip_cmd
245251
for package in self.install_packages:
246-
cmd = '%s %s --break-system-packages' % (pip_installcmd, package)
252+
cmd = '%s %s' % (pip_installcmd, package)
253+
if (self.pip_vmajor > 23) or (self.pip_vmajor == 23 and self.pip_vminor >= 1):
254+
cmd = cmd + ' --break-system-packages' # --break-system-packages introduced in pip 23.1
247255
runcmd(cmd,
248256
err_str='Package installation via pip failed: package %s' % package,
249257
debug_str='Installing python package %s using pip' % package)
250258

251259
def uninstall(self):
252260
for package in self.uninstall_packages:
253-
cmd = "%s uninstall %s --break-system-packages -y \
254-
--disable-pip-version-check" % (self.pip_cmd, package)
261+
cmd = '%s uninstall %s -y --disable-pip-version-check' % (self.pip_cmd, package)
262+
if (self.pip_vmajor > 23) or (self.pip_vmajor == 23 and self.pip_vminor >= 1):
263+
cmd = cmd + ' --break-system-packages' # --break-system-packages introduced in pip 23.1
255264
runcmd(cmd, ignore_status=True,
256265
err_str="Error in removing package: %s" % package,
257266
debug_str="Uninstalling %s" % package)

0 commit comments

Comments
 (0)