Bug 1388013 - Add support for Python 3 to mozbuild draft
authorDave Hunt <dhunt@mozilla.com>
Wed, 16 Aug 2017 11:24:26 +0100
changeset 647555 3955a05c610d26cce72aa7860cafcf72c07999d1
parent 647554 a00e6675e442edf83aa9c57d07073106d3f2fd32
child 647556 a8a17d13701f61948162be62ace1e2012b13e599
push id74442
push userbmo:dave.hunt@gmail.com
push dateWed, 16 Aug 2017 14:37:14 +0000
bugs1388013
milestone57.0a1
Bug 1388013 - Add support for Python 3 to mozbuild MozReview-Commit-ID: CgwT42JAb9g
python/mozbuild/mozbuild/virtualenv.py
--- 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()
-