Bug 1396582 - Move Python version checking to moz.configure; r=nalexander

The Python version validation in virtualenv.py is only called in 2
locations: `python -m mozbuild.virtualenv` and in moz.configure.

I believe that nobody calls `python -m mozbuild.virtualenv` any more.
That means that moz.configure is the only caller of
verify_python_version(). That means we can inline the logic into
moz.configure.

It makes sense for version checking to live in moz.configure because
the role of moz.configure is to evaluate the sanity of the environment.
So this commit does just that.

MozReview-Commit-ID: 7FLL0cGblFS

--HG--
extra : rebase_source : 4c2ecbe06399aad917f58ffb25a571993b736965
This commit is contained in:
Gregory Szorc 2018-01-08 15:46:35 -08:00
Родитель 8fedfc41e7
Коммит b1d1ac0183
2 изменённых файлов: 22 добавлений и 42 удалений

Просмотреть файл

@ -203,7 +203,6 @@ option(env='PYTHON', nargs=1, help='Python interpreter')
@imports('subprocess')
@imports(_from='mozbuild.configure.util', _import='LineIO')
@imports(_from='mozbuild.virtualenv', _import='VirtualenvManager')
@imports(_from='mozbuild.virtualenv', _import='verify_python_version')
@imports('distutils.sysconfig')
def virtualenv_python(env_python, build_env, mozconfig, help):
if help:
@ -224,8 +223,28 @@ def virtualenv_python(env_python, build_env, mozconfig, help):
elif 'PYTHON' in mozconfig['vars']['modified']:
python = mozconfig['vars']['modified']['PYTHON'][1]
with LineIO(lambda l: log.error(l)) as out:
verify_python_version(out)
minimum_version = Version('2.7.3')
major, minor, micro = sys.version_info[:3]
our_version = Version('%d.%d.%d' % (major, minor, micro))
if major != 2 or our_version < minimum_version:
msg = ('Python %s or greater (but not Python 3) is required to build. '
'You are running Python %s. ' % (minimum_version, our_version))
if os.name == 'nt':
msg += ('Please upgrade to the latest MozillaBuild development '
'environment. See https://developer.mozilla.org/en-US/docs/Developer_Guide/Build_Instructions/Windows_Prerequisites')
else:
msg += ('Run `mach bootstrap` to ensure your system is up to date. '
'If you still receive this error afterwards, your shell '
'environment is likely detecting another Python version. '
'Ensure a modern Python can be found in the paths defined '
'by the $PATH environment variable. Or set the PYTHON '
'environment or mozconfig variable to specify which Python '
'interpreter to use.')
die(msg)
topsrcdir, topobjdir = build_env.topsrcdir, build_env.topobjdir
if topobjdir.endswith('/js/src'):
topobjdir = topobjdir[:-7]

Просмотреть файл

@ -20,24 +20,6 @@ IS_NATIVE_WIN = (sys.platform == 'win32' and os.sep == '\\')
IS_MSYS2 = (sys.platform == 'win32' and os.sep == '/')
IS_CYGWIN = (sys.platform == 'cygwin')
# Minimum version of Python required to build.
MINIMUM_PYTHON_VERSION = LooseVersion('2.7.3')
MINIMUM_PYTHON_MAJOR = 2
UPGRADE_WINDOWS = '''
Please upgrade to the latest MozillaBuild development environment. See
https://developer.mozilla.org/en-US/docs/Developer_Guide/Build_Instructions/Windows_Prerequisites
'''.lstrip()
UPGRADE_OTHER = '''
Run |mach bootstrap| to ensure your system is up to date.
If you still receive this error, your shell environment is likely detecting
another Python version. Ensure a modern Python can be found in the paths
defined by the $PATH environment variable and try again.
'''.lstrip()
class VirtualenvManager(object):
"""Contains logic for managing virtualenvs for building the tree."""
@ -525,32 +507,11 @@ class VirtualenvManager(object):
stderr=subprocess.STDOUT)
def verify_python_version(log_handle):
"""Ensure the current version of Python is sufficient."""
major, minor, micro = sys.version_info[:3]
our = LooseVersion('%d.%d.%d' % (major, minor, micro))
if major != MINIMUM_PYTHON_MAJOR or our < MINIMUM_PYTHON_VERSION:
log_handle.write('Python %s or greater (but not Python 3) is '
'required to build. ' % MINIMUM_PYTHON_VERSION)
log_handle.write('You are running Python %s.\n' % our)
if os.name in ('nt', 'ce'):
log_handle.write(UPGRADE_WINDOWS)
else:
log_handle.write(UPGRADE_OTHER)
sys.exit(1)
if __name__ == '__main__':
if len(sys.argv) < 5:
print('Usage: populate_virtualenv.py /path/to/topsrcdir /path/to/topobjdir /path/to/virtualenv /path/to/virtualenv_manifest')
sys.exit(1)
verify_python_version(sys.stdout)
topsrcdir, topobjdir, virtualenv_path, manifest_path = sys.argv[1:5]
populate = False