Skip to content

Commit

Permalink
Upgrade pip only if it is too old in dev.py
Browse files Browse the repository at this point in the history
  • Loading branch information
ankith26 committed Oct 19, 2024
1 parent b505553 commit 8c802f8
Showing 1 changed file with 24 additions and 2 deletions.
26 changes: 24 additions & 2 deletions dev.py
Original file line number Diff line number Diff line change
Expand Up @@ -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"
Expand Down Expand Up @@ -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)
Expand Down Expand Up @@ -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:
Expand Down

0 comments on commit 8c802f8

Please sign in to comment.