Bug 1606336 - mozbuild/mozinfo.py supports Python 3 r=firefox-build-system-reviewers,mshal
authorRicky Stewart <rstewart@mozilla.com>
Mon, 30 Dec 2019 22:50:19 +0000
changeset 508517 557d32efe22c449de7be5f073d71e6f5f7394e90
parent 508516 6e02a9956f57b0c32e8bad6b023a39d56343f7cb
child 508518 1ecc516179e57a19b9686d4e0121b45cf982bef5
push id36968
push userrmaries@mozilla.com
push dateTue, 31 Dec 2019 21:39:20 +0000
treeherdermozilla-central@49ca7598efc0 [default view] [failures only]
perfherder[talos] [build metrics] [platform microbench] (compared to previous push)
reviewersfirefox-build-system-reviewers, mshal
bugs1606336
milestone73.0a1
first release with
nightly linux32
nightly linux64
nightly mac
nightly win32
nightly win64
last release without
nightly linux32
nightly linux64
nightly mac
nightly win32
nightly win64
Bug 1606336 - mozbuild/mozinfo.py supports Python 3 r=firefox-build-system-reviewers,mshal Differential Revision: https://phabricator.services.mozilla.com/D58381
python/mozbuild/mozbuild/mozinfo.py
python/mozbuild/mozbuild/test/python.ini
python/mozbuild/mozbuild/test/python2.ini
python/mozbuild/mozbuild/test/test_mozinfo.py
--- a/python/mozbuild/mozbuild/mozinfo.py
+++ b/python/mozbuild/mozbuild/mozinfo.py
@@ -1,20 +1,21 @@
 # This Source Code Form is subject to the terms of the Mozilla Public
 # License, v. 2.0. If a copy of the MPL was not distributed with this
 # file, You can obtain one at http://mozilla.org/MPL/2.0/.
 
 # This module produces a JSON file that provides basic build info and
 # configuration metadata.
 
-from __future__ import absolute_import, print_function
+from __future__ import absolute_import, print_function, unicode_literals
 
+import json
 import os
 import re
-import json
+import six
 
 
 def build_dict(config, env=os.environ):
     """
     Build a dict containing data about the build configuration from
     the environment.
     """
     substs = config.substs
@@ -145,12 +146,12 @@ def build_dict(config, env=os.environ):
 def write_mozinfo(file, config, env=os.environ):
     """Write JSON data about the configuration specified in config and an
     environment variable dict to ``|file|``, which may be a filename or file-like
     object.
     See build_dict for information about what  environment variables are used,
     and what keys are produced.
     """
     build_conf = build_dict(config, env)
-    if isinstance(file, basestring):
-        file = open(file, 'wb')
+    if isinstance(file, six.text_type):
+        file = open(file, 'wt')
 
     json.dump(build_conf, file, sort_keys=True, indent=4)
--- a/python/mozbuild/mozbuild/test/python.ini
+++ b/python/mozbuild/mozbuild/test/python.ini
@@ -1,11 +1,12 @@
 [DEFAULT]
 subsuite = mozbuild
 
 [test_base.py]
 [test_expression.py]
 [test_licenses.py]
 [test_makeutil.py]
 [test_mozconfig.py]
+[test_mozinfo.py]
 [test_preprocessor.py]
 [test_pythonutil.py]
 [test_util_fileavoidwrite.py]
--- a/python/mozbuild/mozbuild/test/python2.ini
+++ b/python/mozbuild/mozbuild/test/python2.ini
@@ -36,10 +36,9 @@ skip-if = (os == "win")
 [frontend/test_namespaces.py]
 [frontend/test_reader.py]
 [frontend/test_sandbox.py]
 [test_artifact_cache.py]
 [test_containers.py]
 [test_dotproperties.py]
 [test_jarmaker.py]
 [test_line_endings.py]
-[test_mozinfo.py]
 [test_util.py]
--- a/python/mozbuild/mozbuild/test/test_mozinfo.py
+++ b/python/mozbuild/mozbuild/test/test_mozinfo.py
@@ -1,21 +1,22 @@
 #!/usr/bin/env python
 # This Source Code Form is subject to the terms of the Mozilla Public
 # License, v. 2.0. If a copy of the MPL was not distributed with this file,
 # You can obtain one at http://mozilla.org/MPL/2.0/.
 
-from __future__ import absolute_import, print_function
+from __future__ import absolute_import, print_function, unicode_literals
 
 import json
 import os
+import six
 import tempfile
 import unittest
 
-from StringIO import StringIO
+from six import StringIO
 
 import mozunit
 
 from mozbuild.backend.configenvironment import ConfigEnvironment
 
 from mozbuild.mozinfo import (
     build_dict,
     write_mozinfo,
@@ -200,34 +201,36 @@ class TestBuildDict(unittest.TestCase, B
 
 
 class TestWriteMozinfo(unittest.TestCase, Base):
     """
     Test the write_mozinfo function.
     """
 
     def setUp(self):
-        fd, self.f = tempfile.mkstemp()
+        fd, f = tempfile.mkstemp()
+        self.f = six.ensure_text(f)
         os.close(fd)
 
     def tearDown(self):
         os.unlink(self.f)
 
     def test_basic(self):
         """
         Test that writing to a file produces correct output.
         """
         c = self._config(dict(
             OS_TARGET='WINNT',
             TARGET_CPU='i386',
             MOZ_WIDGET_TOOLKIT='windows',
         ))
         tempdir = tempfile.tempdir
         c.topsrcdir = tempdir
-        with NamedTemporaryFile(dir=os.path.normpath(c.topsrcdir)) as mozconfig:
+        with NamedTemporaryFile(dir=os.path.normpath(c.topsrcdir),
+                                mode='wt') as mozconfig:
             mozconfig.write('unused contents')
             mozconfig.flush()
             c.mozconfig = mozconfig.name
             write_mozinfo(self.f, c)
             with open(self.f) as f:
                 d = json.load(f)
                 self.assertEqual('win', d['os'])
                 self.assertEqual('x86', d['processor'])