From 37f28f1b4e6783c4a06e21977f2e30d592e13819 Mon Sep 17 00:00:00 2001 From: Mike Frysinger Date: Sun, 16 Feb 2020 15:15:53 -0500 Subject: [PATCH] main: add python version checking If an older launcher script is used with newer repo source tree, we might be issuing python version warnings. Plus, we want to be able to roll Python version requirements independently of the launcher. Add some version checking here too. Change-Id: Ia35fc821f93c429296bdf5fd578276fef796b649 Reviewed-on: https://gerrit-review.googlesource.com/c/git-repo/+/255592 Tested-by: Mike Frysinger Reviewed-by: David Pursehouse --- main.py | 28 ++++++++++++++++++++++++++++ 1 file changed, 28 insertions(+) diff --git a/main.py b/main.py index 3efb1c35..ec031a4c 100755 --- a/main.py +++ b/main.py @@ -71,6 +71,34 @@ from subcmds import all_commands if not is_python3(): input = raw_input # noqa: F821 +# NB: These do not need to be kept in sync with the repo launcher script. +# These may be much newer as it allows the repo launcher to roll between +# different repo releases while source versions might require a newer python. +# +# The soft version is when we start warning users that the version is old and +# we'll be dropping support for it. We'll refuse to work with versions older +# than the hard version. +# +# python-3.6 is in Ubuntu Bionic. +MIN_PYTHON_VERSION_SOFT = (3, 6) +MIN_PYTHON_VERSION_HARD = (3, 4) + +if sys.version_info.major < 3: + print('repo: warning: Python 2 is no longer supported; ' + 'Please upgrade to Python {}.{}+.'.format(*MIN_PYTHON_VERSION_SOFT), + file=sys.stderr) +else: + if sys.version_info < MIN_PYTHON_VERSION_HARD: + print('repo: error: Python 3 version is too old; ' + 'Please upgrade to Python {}.{}+.'.format(*MIN_PYTHON_VERSION_SOFT), + file=sys.stderr) + sys.exit(1) + elif sys.version_info < MIN_PYTHON_VERSION_SOFT: + print('repo: warning: your Python 3 version is no longer supported; ' + 'Please upgrade to Python {}.{}+.'.format(*MIN_PYTHON_VERSION_SOFT), + file=sys.stderr) + + global_options = optparse.OptionParser( usage='repo [-p|--paginate|--no-pager] COMMAND [ARGS]', add_help_option=False)