From 8c802f8cfd43f53af2e231b4a797d6b2f6729bd4 Mon Sep 17 00:00:00 2001 From: Ankith Date: Sat, 19 Oct 2024 10:59:01 +0530 Subject: [PATCH] Upgrade pip only if it is too old in dev.py --- dev.py | 26 ++++++++++++++++++++++++-- 1 file changed, 24 insertions(+), 2 deletions(-) diff --git a/dev.py b/dev.py index db34ed1bef..547eee5712 100644 --- a/dev.py +++ b/dev.py @@ -28,6 +28,9 @@ "-Csetup-args=-Dfont=disabled", ] +# We assume this script works with any pip version above this. +PIP_MIN_VERSION = "23.1" + class Colors(Enum): RESET = "\033[0m" @@ -162,6 +165,16 @@ def show_diff_and_suggest_fix(parent: str): raise +def check_version_atleast(version: str, min_version: str): + try: + version_tup = tuple(int(i.strip()) for i in version.split(".")) + min_version_tup = tuple(int(i.strip()) for i in min_version.split(".")) + except (AttributeError, TypeError, ValueError): + return False + + return version_tup >= min_version_tup + + class Dev: def __init__(self) -> None: self.py: Path = Path(sys.executable) @@ -358,8 +371,17 @@ def prep_env(self): else: pprint(f"Using python '{self.py}'") - pprint("Upgrading pip") - pip_install(self.py, ["-U", "pip"]) + pprint("Checking pip version") + pip_v = cmd_run([self.py, "-m", "pip", "-V"], capture_output=True) + try: + pip_version = pip_v.split()[1] + except (AttributeError, IndexError): + pip_version = "UNKNOWN" + + pprint(f"Determined pip version: {pip_version}") + if not check_version_atleast(pip_version, PIP_MIN_VERSION): + pprint("pip version is too old or unknown, attempting pip upgrade") + pip_install(self.py, ["-U", "pip"]) deps = self.deps.get(self.args["command"]) if deps: