install.py: refined the pip update process

Wed, 11 Mar 2020 19:25:20 +0100

author
Detlev Offenbach <detlev@die-offenbachs.de>
date
Wed, 11 Mar 2020 19:25:20 +0100
changeset 7453
54431a52b7f2
parent 7452
32b5c4a9fb17
child 7454
a4392387052c

install.py: refined the pip update process

scripts/install.py file | annotate | diff | comparison | revisions
--- a/scripts/install.py	Tue Mar 10 19:32:39 2020 +0100
+++ b/scripts/install.py	Wed Mar 11 19:25:20 2020 +0100
@@ -22,6 +22,7 @@
 import subprocess
 import time
 import io
+import json
 
 # Define the globals.
 progName = None
@@ -1307,6 +1308,35 @@
     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.
@@ -1330,8 +1360,9 @@
     print('Checking dependencies')
     
     # update pip first even if we don't need to install anything
-    updatePip()
-    print("\n\n")
+    if isPipOutdated():
+        updatePip()
+        print("\n")
     
     # perform dependency checks
     print("Python Version: {0:d}.{1:d}.{2:d}".format(*sys.version_info[:3]))

eric ide

mercurial