Skip to content

Commit 8c802f8

Browse files
committed
Upgrade pip only if it is too old in dev.py
1 parent b505553 commit 8c802f8

File tree

1 file changed

+24
-2
lines changed

1 file changed

+24
-2
lines changed

dev.py

Lines changed: 24 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -28,6 +28,9 @@
2828
"-Csetup-args=-Dfont=disabled",
2929
]
3030

31+
# We assume this script works with any pip version above this.
32+
PIP_MIN_VERSION = "23.1"
33+
3134

3235
class Colors(Enum):
3336
RESET = "\033[0m"
@@ -162,6 +165,16 @@ def show_diff_and_suggest_fix(parent: str):
162165
raise
163166

164167

168+
def check_version_atleast(version: str, min_version: str):
169+
try:
170+
version_tup = tuple(int(i.strip()) for i in version.split("."))
171+
min_version_tup = tuple(int(i.strip()) for i in min_version.split("."))
172+
except (AttributeError, TypeError, ValueError):
173+
return False
174+
175+
return version_tup >= min_version_tup
176+
177+
165178
class Dev:
166179
def __init__(self) -> None:
167180
self.py: Path = Path(sys.executable)
@@ -358,8 +371,17 @@ def prep_env(self):
358371
else:
359372
pprint(f"Using python '{self.py}'")
360373

361-
pprint("Upgrading pip")
362-
pip_install(self.py, ["-U", "pip"])
374+
pprint("Checking pip version")
375+
pip_v = cmd_run([self.py, "-m", "pip", "-V"], capture_output=True)
376+
try:
377+
pip_version = pip_v.split()[1]
378+
except (AttributeError, IndexError):
379+
pip_version = "UNKNOWN"
380+
381+
pprint(f"Determined pip version: {pip_version}")
382+
if not check_version_atleast(pip_version, PIP_MIN_VERSION):
383+
pprint("pip version is too old or unknown, attempting pip upgrade")
384+
pip_install(self.py, ["-U", "pip"])
363385

364386
deps = self.deps.get(self.args["command"])
365387
if deps:

0 commit comments

Comments
 (0)