summaryrefslogtreecommitdiffstats
path: root/main.py
diff options
context:
space:
mode:
authorMike Frysinger <vapier@google.com>2020-02-16 15:15:53 -0500
committerDavid Pursehouse <dpursehouse@collab.net>2020-02-18 14:38:33 +0000
commit37f28f1b4e6783c4a06e21977f2e30d592e13819 (patch)
treef6921d26c030505a585a37af495315ba258be885 /main.py
parentaf1e5dea3511c7e01f9a0a31f6e254d63848bed5 (diff)
downloadgit-repo-37f28f1b4e6783c4a06e21977f2e30d592e13819.tar.gz
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 <vapier@google.com> Reviewed-by: David Pursehouse <dpursehouse@collab.net>
Diffstat (limited to 'main.py')
-rwxr-xr-xmain.py28
1 files changed, 28 insertions, 0 deletions
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
71if not is_python3(): 71if not is_python3():
72 input = raw_input # noqa: F821 72 input = raw_input # noqa: F821
73 73
74# NB: These do not need to be kept in sync with the repo launcher script.
75# These may be much newer as it allows the repo launcher to roll between
76# different repo releases while source versions might require a newer python.
77#
78# The soft version is when we start warning users that the version is old and
79# we'll be dropping support for it. We'll refuse to work with versions older
80# than the hard version.
81#
82# python-3.6 is in Ubuntu Bionic.
83MIN_PYTHON_VERSION_SOFT = (3, 6)
84MIN_PYTHON_VERSION_HARD = (3, 4)
85
86if sys.version_info.major < 3:
87 print('repo: warning: Python 2 is no longer supported; '
88 'Please upgrade to Python {}.{}+.'.format(*MIN_PYTHON_VERSION_SOFT),
89 file=sys.stderr)
90else:
91 if sys.version_info < MIN_PYTHON_VERSION_HARD:
92 print('repo: error: Python 3 version is too old; '
93 'Please upgrade to Python {}.{}+.'.format(*MIN_PYTHON_VERSION_SOFT),
94 file=sys.stderr)
95 sys.exit(1)
96 elif sys.version_info < MIN_PYTHON_VERSION_SOFT:
97 print('repo: warning: your Python 3 version is no longer supported; '
98 'Please upgrade to Python {}.{}+.'.format(*MIN_PYTHON_VERSION_SOFT),
99 file=sys.stderr)
100
101
74global_options = optparse.OptionParser( 102global_options = optparse.OptionParser(
75 usage='repo [-p|--paginate|--no-pager] COMMAND [ARGS]', 103 usage='repo [-p|--paginate|--no-pager] COMMAND [ARGS]',
76 add_help_option=False) 104 add_help_option=False)