setup: add extra logic to try and recommend a new pip on bad Python stable
authorAugie Fackler <augie@google.com>
Fri, 21 Jul 2017 10:46:31 -0400
branchstable
changeset 33588 025017423e53
parent 33587 e0bbe32d8b55
child 33589 a0bfcd08f5fe
setup: add extra logic to try and recommend a new pip on bad Python Modern pip can detect supported Python versions (which we now declare), and pull down a reasonable release. This trick was suggested in http://bit.ly/pycon2017-build-bridges, and seems like a good defensive maneuver so that when we want to move to Python 3 it's less risky for existing users. This moves the version-check logic after defining our printf function so we can print more informative messages.
setup.py
--- a/setup.py	Fri Jul 21 10:39:52 2017 -0400
+++ b/setup.py	Fri Jul 21 10:46:31 2017 -0400
@@ -24,9 +24,6 @@
     ])
 
 import sys, platform
-if sys.version_info < (2, 7, 0, 'final'):
-    raise SystemExit('Mercurial requires Python 2.7 or later.')
-
 if sys.version_info[0] >= 3:
     printf = eval('print')
     libdir_escape = 'unicode_escape'
@@ -37,6 +34,33 @@
         end = kwargs.get('end', '\n')
         f.write(b' '.join(args) + end)
 
+# Attempt to guide users to a modern pip - this means that 2.6 users
+# should have a chance of getting a 4.2 release, and when we ratchet
+# the version requirement forward again hopefully everyone will get
+# something that works for them.
+if sys.version_info < (2, 7, 0, 'final'):
+    pip_message = ('This may be due to an out of date pip. '
+                   'Make sure you have pip >= 9.0.1.')
+    try:
+        import pip
+        pip_version = tuple([int(x) for x in pip.__version__.split('.')[:3]])
+        if pip_version < (9, 0, 1) :
+            pip_message = (
+                'Your pip version is out of date, please install '
+                'pip >= 9.0.1. pip {} detected.'.format(pip.__version__))
+        else:
+            # pip is new enough - it must be something else
+            pip_message = ''
+    except Exception:
+        pass
+    error = """
+Mercurial does not support Python older than 2.7.
+Python {py} detected.
+{pip}
+""".format(py=sys.version_info, pip=pip_message)
+    printf(error, file=sys.stderr)
+    sys.exit(1)
+
 # Solaris Python packaging brain damage
 try:
     import hashlib