From patchwork Mon Jul 24 21:08:13 2017 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit Subject: [5, of, 5, stable] setup: add extra logic to try and recommend a new pip on bad Python From: Augie Fackler X-Patchwork-Id: 22547 Message-Id: <8d381b895e19ad447069.1500930493@augie-macbookpro2.roam.corp.google.com> To: mercurial-devel@mercurial-scm.org Date: Mon, 24 Jul 2017 17:08:13 -0400 # HG changeset patch # User Augie Fackler # Date 1500648391 14400 # Fri Jul 21 10:46:31 2017 -0400 # Branch stable # Node ID 8d381b895e19ad447069529aa5c5e7358c4b0b48 # Parent 6d82dcfad5dfb1b1a83c47055dc8a2377c59701b 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. diff --git a/setup.py b/setup.py --- 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