From 527e838b0037426d87f94718193787d81dc8c98a Mon Sep 17 00:00:00 2001 From: Augie Fackler Date: Fri, 21 Jul 2017 10:46:31 -0400 Subject: [PATCH] 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 | 30 +++++++++++++++++++++++++++--- 1 file changed, 27 insertions(+), 3 deletions(-) diff --git a/setup.py b/setup.py index c0d64479be..6f09b46f6d 100644 --- a/setup.py +++ b/setup.py @@ -24,9 +24,6 @@ if 'HGALLOWPYTHON3': ]) 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 @@ else: 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