scripts/install.py

branch
maintenance
changeset 7503
b17672e6812d
parent 7362
028bf21bb5a2
parent 7453
54431a52b7f2
child 7560
343db73c4842
diff -r 7ece94219310 -r b17672e6812d scripts/install.py
--- a/scripts/install.py	Sat Mar 07 11:12:38 2020 +0100
+++ b/scripts/install.py	Sun Apr 05 12:06:15 2020 +0200
@@ -22,6 +22,7 @@
 import subprocess
 import time
 import io
+import json
 
 # Define the globals.
 progName = None
@@ -1307,12 +1308,62 @@
     return ok
 
 
+def isPipOutdated():
+    """
+    Check, if pip is outdated.
+    
+    @return flag indicating an outdated pip
+    @rtype bool
+    """
+    try:
+        pipOut = subprocess.check_output([
+            sys.executable, "-m", "pip", "list", "--outdated",
+            "--format=json"
+        ])
+        pipOut = pipOut.decode()
+    except (OSError, subprocess.CalledProcessError):
+        pipOut = "[]"       # default empty list
+    try:
+        jsonList = json.loads(pipOut)
+    except Exception:
+        jsonList = []
+    for package in jsonList:
+        if isinstance(package, dict) and package["name"] == "pip":
+            print("'pip' is outdated (installed {0}, available {1})".format(
+                package["version"], package["latest_version"]
+            ))
+            return True
+    
+    return False
+
+
+def updatePip():
+    """
+    Update the installed pip package.
+    """
+    global yes2All
+    
+    if yes2All:
+        answer = "y"
+    else:
+        print("Shall 'pip' be updated (recommended)? (Y/n)", end=" ")
+        answer = input()
+    if answer in ("", "Y", "y"):
+        subprocess.call(
+            [sys.executable, "-m", "pip", "install", "--upgrade", "pip"])
+
+
 def doDependancyChecks():
     """
     Perform some dependency checks.
     """
     print('Checking dependencies')
     
+    # update pip first even if we don't need to install anything
+    if isPipOutdated():
+        updatePip()
+        print("\n")
+    
     # perform dependency checks
     print("Python Version: {0:d}.{1:d}.{2:d}".format(*sys.version_info[:3]))
     if sys.version_info < (3, 5, 0):

eric ide

mercurial