Bug 1388013 - Add support for Python 3 to mozbuild
MozReview-Commit-ID: CgwT42JAb9g
--- a/python/mozbuild/mozbuild/virtualenv.py
+++ b/python/mozbuild/mozbuild/virtualenv.py
@@ -16,18 +16,19 @@ import warnings
from distutils.version import LooseVersion
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
+MINIMUM_PYTHON_VERSION = {
+ 2: LooseVersion('2.7.3'),
+ 3: LooseVersion('3.6.0')}
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 = '''
@@ -202,17 +203,17 @@ class VirtualenvManager(object):
raise Exception(
'Failed to create virtualenv: %s' % self.virtualenv_root)
self.write_exe_info(python)
return self.virtualenv_root
def packages(self):
- with file(self.manifest_path, 'rU') as fh:
+ with open(self.manifest_path, 'rU') as fh:
packages = [line.rstrip().split(':')
for line in fh]
return packages
def populate(self):
"""Populate the virtualenv.
The manifest file consists of colon-delimited fields. The first field
@@ -526,19 +527,21 @@ class VirtualenvManager(object):
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)
+ if major not in MINIMUM_PYTHON_VERSION or \
+ our < MINIMUM_PYTHON_VERSION[major]:
+ log_handle.write('Python %s or greater is required to build. ' %
+ MINIMUM_PYTHON_VERSION.get(
+ major, MINIMUM_PYTHON_VERSION[2]))
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)
@@ -561,9 +564,8 @@ if __name__ == '__main__':
manager = VirtualenvManager(topsrcdir, topobjdir, virtualenv_path,
sys.stdout, manifest_path)
if populate:
manager.populate()
else:
manager.ensure()
-