|
@@ -32,6 +32,13 @@ import subprocess
|
|
|
import sys
|
|
import sys
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
+# These should never be newer than the main.py version since this needs to be a
|
|
|
|
|
+# bit more flexible with older systems. See that file for more details on the
|
|
|
|
|
+# versions we select.
|
|
|
|
|
+MIN_PYTHON_VERSION_SOFT = (3, 6)
|
|
|
|
|
+MIN_PYTHON_VERSION_HARD = (3, 5)
|
|
|
|
|
+
|
|
|
|
|
+
|
|
|
# Keep basic logic in sync with repo_trace.py.
|
|
# Keep basic logic in sync with repo_trace.py.
|
|
|
class Trace(object):
|
|
class Trace(object):
|
|
|
"""Trace helper logic."""
|
|
"""Trace helper logic."""
|
|
@@ -70,8 +77,6 @@ def check_python_version():
|
|
|
def reexec(prog):
|
|
def reexec(prog):
|
|
|
exec_command([prog] + sys.argv)
|
|
exec_command([prog] + sys.argv)
|
|
|
|
|
|
|
|
- MIN_PYTHON_VERSION = (3, 6)
|
|
|
|
|
-
|
|
|
|
|
ver = sys.version_info
|
|
ver = sys.version_info
|
|
|
major = ver.major
|
|
major = ver.major
|
|
|
minor = ver.minor
|
|
minor = ver.minor
|
|
@@ -80,17 +85,24 @@ def check_python_version():
|
|
|
if (major, minor) < (2, 7):
|
|
if (major, minor) < (2, 7):
|
|
|
print('repo: error: Your Python version is too old. '
|
|
print('repo: error: Your Python version is too old. '
|
|
|
'Please use Python {}.{} or newer instead.'.format(
|
|
'Please use Python {}.{} or newer instead.'.format(
|
|
|
- *MIN_PYTHON_VERSION), file=sys.stderr)
|
|
|
|
|
|
|
+ *MIN_PYTHON_VERSION_SOFT), file=sys.stderr)
|
|
|
sys.exit(1)
|
|
sys.exit(1)
|
|
|
|
|
|
|
|
# Try to re-exec the version specific Python 3 if needed.
|
|
# Try to re-exec the version specific Python 3 if needed.
|
|
|
- if (major, minor) < MIN_PYTHON_VERSION:
|
|
|
|
|
|
|
+ if (major, minor) < MIN_PYTHON_VERSION_SOFT:
|
|
|
# Python makes releases ~once a year, so try our min version +10 to help
|
|
# Python makes releases ~once a year, so try our min version +10 to help
|
|
|
# bridge the gap. This is the fallback anyways so perf isn't critical.
|
|
# bridge the gap. This is the fallback anyways so perf isn't critical.
|
|
|
- min_major, min_minor = MIN_PYTHON_VERSION
|
|
|
|
|
|
|
+ min_major, min_minor = MIN_PYTHON_VERSION_SOFT
|
|
|
for inc in range(0, 10):
|
|
for inc in range(0, 10):
|
|
|
reexec('python{}.{}'.format(min_major, min_minor + inc))
|
|
reexec('python{}.{}'.format(min_major, min_minor + inc))
|
|
|
|
|
|
|
|
|
|
+ # Fallback to older versions if possible.
|
|
|
|
|
+ for inc in range(MIN_PYTHON_VERSION_SOFT[1] - MIN_PYTHON_VERSION_HARD[1], 0, -1):
|
|
|
|
|
+ # Don't downgrade, and don't reexec ourselves (which would infinite loop).
|
|
|
|
|
+ if (min_major, min_minor - inc) <= (major, minor):
|
|
|
|
|
+ break
|
|
|
|
|
+ reexec('python{}.{}'.format(min_major, min_minor - inc))
|
|
|
|
|
+
|
|
|
# Try the generic Python 3 wrapper, but only if it's new enough. We don't
|
|
# Try the generic Python 3 wrapper, but only if it's new enough. We don't
|
|
|
# want to go from (still supported) Python 2.7 to (unsupported) Python 3.5.
|
|
# want to go from (still supported) Python 2.7 to (unsupported) Python 3.5.
|
|
|
try:
|
|
try:
|
|
@@ -103,18 +115,19 @@ def check_python_version():
|
|
|
except (OSError, subprocess.CalledProcessError):
|
|
except (OSError, subprocess.CalledProcessError):
|
|
|
python3_ver = None
|
|
python3_ver = None
|
|
|
|
|
|
|
|
- # The python3 version looks like it's new enough, so give it a try.
|
|
|
|
|
- if python3_ver and python3_ver >= MIN_PYTHON_VERSION:
|
|
|
|
|
|
|
+ # If the python3 version looks like it's new enough, give it a try.
|
|
|
|
|
+ if (python3_ver and python3_ver >= MIN_PYTHON_VERSION_HARD
|
|
|
|
|
+ and python3_ver != (major, minor)):
|
|
|
reexec('python3')
|
|
reexec('python3')
|
|
|
|
|
|
|
|
# We're still here, so diagnose things for the user.
|
|
# We're still here, so diagnose things for the user.
|
|
|
if major < 3:
|
|
if major < 3:
|
|
|
print('repo: warning: Python 2 is no longer supported; '
|
|
print('repo: warning: Python 2 is no longer supported; '
|
|
|
- 'Please upgrade to Python {}.{}+.'.format(*MIN_PYTHON_VERSION),
|
|
|
|
|
|
|
+ 'Please upgrade to Python {}.{}+.'.format(*MIN_PYTHON_VERSION_HARD),
|
|
|
file=sys.stderr)
|
|
file=sys.stderr)
|
|
|
- else:
|
|
|
|
|
|
|
+ elif (major, minor) < MIN_PYTHON_VERSION_HARD:
|
|
|
print('repo: error: Python 3 version is too old; '
|
|
print('repo: error: Python 3 version is too old; '
|
|
|
- 'Please use Python {}.{} or newer.'.format(*MIN_PYTHON_VERSION),
|
|
|
|
|
|
|
+ 'Please use Python {}.{} or newer.'.format(*MIN_PYTHON_VERSION_HARD),
|
|
|
file=sys.stderr)
|
|
file=sys.stderr)
|
|
|
sys.exit(1)
|
|
sys.exit(1)
|
|
|
|
|
|