From df3ad8c98b56a0565fb4dca454dc51bda0854381 Mon Sep 17 00:00:00 2001 From: Justin Wood Date: Tue, 28 May 2019 14:23:47 +0000 Subject: [PATCH] Bug 1547730 - Do dict.iteritems() via six to support py3. r=glandium shellutil.py needed special handling since it is invoked earlier than the vendor directory adding we do, so it does not have six available. Differential Revision: https://phabricator.services.mozilla.com/D28096 --HG-- extra : moz-landing-system : lando --- .../mozbuild/mozbuild/configure/__init__.py | 10 +++-- python/mozbuild/mozbuild/configure/options.py | 3 +- python/mozbuild/mozbuild/preprocessor.py | 45 ++++++++++--------- python/mozbuild/mozbuild/shellutil.py | 2 +- python/mozbuild/mozbuild/util.py | 7 +-- python/mozbuild/mozpack/chrome/flags.py | 3 +- python/mozbuild/mozpack/copier.py | 3 +- python/mozbuild/mozpack/files.py | 3 +- python/mozbuild/mozpack/mozjar.py | 14 +++--- python/mozbuild/mozpack/packager/__init__.py | 4 +- python/mozbuild/mozpack/packager/l10n.py | 5 ++- python/mozbuild/mozpack/test/test_copier.py | 3 +- .../mozpack/test/test_packager_formats.py | 17 +++---- .../mozpack/test/test_packager_l10n.py | 3 +- 14 files changed, 70 insertions(+), 52 deletions(-) diff --git a/python/mozbuild/mozbuild/configure/__init__.py b/python/mozbuild/mozbuild/configure/__init__.py index 8e95b04d94b8..37f30659b138 100644 --- a/python/mozbuild/mozbuild/configure/__init__.py +++ b/python/mozbuild/mozbuild/configure/__init__.py @@ -9,6 +9,7 @@ import inspect import logging import os import re +import six import sys import types from collections import OrderedDict @@ -664,7 +665,7 @@ class ConfigureSandbox(dict): ''' when = self._normalize_when(kwargs.get('when'), 'option') args = [self._resolve(arg) for arg in args] - kwargs = {k: self._resolve(v) for k, v in kwargs.iteritems() + kwargs = {k: self._resolve(v) for k, v in six.iteritems(kwargs) if k != 'when'} option = Option(*args, **kwargs) if when: @@ -762,7 +763,7 @@ class ConfigureSandbox(dict): (k[:-len('_impl')], getattr(self, k)) for k in dir(self) if k.endswith('_impl') and k != 'template_impl' ) - glob.update((k, v) for k, v in self.iteritems() if k not in glob) + glob.update((k, v) for k, v in six.iteritems(self) if k not in glob) template = self._prepare_function(func, update_globals) @@ -787,7 +788,7 @@ class ConfigureSandbox(dict): def wrapper(*args, **kwargs): args = [maybe_prepare_function(arg) for arg in args] kwargs = {k: maybe_prepare_function(v) - for k, v in kwargs.iteritems()} + for k, v in kwargs.items()} ret = template(*args, **kwargs) if isfunction(ret): # We can't expect the sandboxed code to think about all the @@ -1055,7 +1056,8 @@ class ConfigureSandbox(dict): return func glob = SandboxedGlobal( - (k, v) for k, v in func.func_globals.iteritems() + (k, v) + for k, v in six.iteritems(func.func_globals) if (inspect.isfunction(v) and v not in self._templates) or ( inspect.isclass(v) and issubclass(v, Exception)) ) diff --git a/python/mozbuild/mozbuild/configure/options.py b/python/mozbuild/mozbuild/configure/options.py index 8a403272c31c..59938653196c 100644 --- a/python/mozbuild/mozbuild/configure/options.py +++ b/python/mozbuild/mozbuild/configure/options.py @@ -5,6 +5,7 @@ from __future__ import absolute_import, print_function, unicode_literals import os +import six import sys import types from collections import OrderedDict @@ -132,7 +133,7 @@ class ConflictingOptionError(InvalidOptionError): if format_data: message = message.format(**format_data) super(ConflictingOptionError, self).__init__(message) - for k, v in format_data.iteritems(): + for k, v in six.iteritems(format_data): setattr(self, k, v) diff --git a/python/mozbuild/mozbuild/preprocessor.py b/python/mozbuild/mozbuild/preprocessor.py index 0b4f51a4e538..98167fe9ca9a 100644 --- a/python/mozbuild/mozbuild/preprocessor.py +++ b/python/mozbuild/mozbuild/preprocessor.py @@ -296,10 +296,11 @@ class Preprocessor: def __init__(self, defines=None, marker='#'): self.context = Context() - for k, v in {'FILE': '', - 'LINE': 0, - 'DIRECTORY': os.path.abspath('.')}.iteritems(): - self.context[k] = v + self.context.update({ + 'FILE': '', + 'LINE': 0, + 'DIRECTORY': os.path.abspath('.') + }) try: # Can import globally because of bootstrapping issues. from buildconfig import topsrcdir, topobjdir @@ -319,23 +320,25 @@ class Preprocessor: self.checkLineNumbers = False self.filters = [] self.cmds = {} - for cmd, level in {'define': 0, - 'undef': 0, - 'if': sys.maxint, - 'ifdef': sys.maxint, - 'ifndef': sys.maxint, - 'else': 1, - 'elif': 1, - 'elifdef': 1, - 'elifndef': 1, - 'endif': sys.maxint, - 'expand': 0, - 'literal': 0, - 'filter': 0, - 'unfilter': 0, - 'include': 0, - 'includesubst': 0, - 'error': 0}.iteritems(): + for cmd, level in ( + ('define', 0), + ('undef', 0), + ('if', sys.maxint), + ('ifdef', sys.maxint), + ('ifndef', sys.maxint), + ('else', 1), + ('elif', 1), + ('elifdef', 1), + ('elifndef', 1), + ('endif', sys.maxint), + ('expand', 0), + ('literal', 0), + ('filter', 0), + ('unfilter', 0), + ('include', 0), + ('includesubst', 0), + ('error', 0), + ): self.cmds[cmd] = (level, getattr(self, 'do_' + cmd)) self.out = sys.stdout self.setMarker(marker) diff --git a/python/mozbuild/mozbuild/shellutil.py b/python/mozbuild/mozbuild/shellutil.py index 140feecb2c31..677b1377c9a5 100644 --- a/python/mozbuild/mozbuild/shellutil.py +++ b/python/mozbuild/mozbuild/shellutil.py @@ -17,7 +17,7 @@ def _tokens2re(**tokens): # which matches the pattern and captures it in a named match group. # The group names and patterns are given as arguments. all_tokens = '|'.join('(?P<%s>%s)' % (name, value) - for name, value in tokens.iteritems()) + for name, value in tokens.items()) nonescaped = r'(?" % (self.__class__.__name__, diff --git a/python/mozbuild/mozpack/packager/__init__.py b/python/mozbuild/mozpack/packager/__init__.py index 9cfe8d99725c..c5ba30fd5c6e 100644 --- a/python/mozbuild/mozpack/packager/__init__.py +++ b/python/mozbuild/mozpack/packager/__init__.py @@ -7,6 +7,7 @@ from __future__ import absolute_import, print_function, unicode_literals from mozbuild.preprocessor import Preprocessor import re import os +import six from mozpack.errors import errors from mozpack.chrome.manifest import ( Manifest, @@ -366,7 +367,8 @@ class SimplePackager(object): bases = self.get_bases() broken_bases = sorted( - m for m, includer in self._included_manifests.iteritems() + m + for m, includer in six.iteritems(self._included_manifests) if mozpath.basedir(m, bases) != mozpath.basedir(includer, bases)) for m in broken_bases: errors.fatal('"%s" is included from "%s", which is outside "%s"' % diff --git a/python/mozbuild/mozpack/packager/l10n.py b/python/mozbuild/mozpack/packager/l10n.py index 1f6462734993..761ca4b107b9 100644 --- a/python/mozbuild/mozpack/packager/l10n.py +++ b/python/mozbuild/mozpack/packager/l10n.py @@ -11,6 +11,7 @@ directory. import json import os +import six import mozpack.path as mozpath from mozpack.packager.formats import ( FlatFormatter, @@ -258,7 +259,7 @@ def _repack(app_finder, l10n_finder, copier, formatter, non_chrome=set()): formatter.add(p, f) # Transplant jar preloading information. - for path, log in app_finder.jarlogs.iteritems(): + for path, log in six.iteritems(app_finder.jarlogs): assert isinstance(copier[path], Jarrer) copier[path].preload([l.replace(locale, l10n_locale) for l in log]) @@ -289,7 +290,7 @@ def repack(source, l10n, extra_l10n={}, non_resources=[], non_chrome=set()): finders = { '': l10n_finder, } - for base, path in extra_l10n.iteritems(): + for base, path in six.iteritems(extra_l10n): finders[base] = UnpackFinder(path) l10n_finder = ComposedFinder(finders) copier = FileCopier() diff --git a/python/mozbuild/mozpack/test/test_copier.py b/python/mozbuild/mozpack/test/test_copier.py index ae82f198f8e3..6c9d54f7827e 100644 --- a/python/mozbuild/mozpack/test/test_copier.py +++ b/python/mozbuild/mozpack/test/test_copier.py @@ -19,6 +19,7 @@ import mozpack.path as mozpath import unittest import mozunit import os +import six import stat from mozpack.errors import ErrorMessage from mozpack.test.test_files import ( @@ -130,7 +131,7 @@ class TestFileRegistry(BaseTestFileRegistry, unittest.TestCase): 'bar': [], } reg = FileRegistry() - for path, parts in cases.iteritems(): + for path, parts in six.iteritems(cases): self.assertEqual(reg._partial_paths(path), parts) def test_file_registry(self): diff --git a/python/mozbuild/mozpack/test/test_packager_formats.py b/python/mozbuild/mozpack/test/test_packager_formats.py index fb144bc0dcc5..a7b0afbf9c53 100644 --- a/python/mozbuild/mozpack/test/test_packager_formats.py +++ b/python/mozbuild/mozpack/test/test_packager_formats.py @@ -33,6 +33,7 @@ from mozpack.test.test_files import ( bar_xpt, ) import mozpack.path as mozpath +import six from itertools import chain from test_errors import TestErrors @@ -123,7 +124,7 @@ RESULT_FLAT = { for addon in ('addon0', 'addon1', 'app/chrome/addons/addon2'): RESULT_FLAT.update({ mozpath.join(addon, p): f - for p, f in { + for p, f in six.iteritems({ 'chrome.manifest': [ 'manifest chrome/chrome.manifest', 'manifest components/components.manifest', @@ -138,7 +139,7 @@ for addon in ('addon0', 'addon1', 'app/chrome/addons/addon2'): ], 'components/bar.xpt': bar_xpt, 'components/foo.xpt': foo2_xpt, - }.iteritems() + }) }) RESULT_JAR = { @@ -186,12 +187,12 @@ RESULT_JAR.update({ }, 'addon1.xpi': { mozpath.relpath(p, 'addon1'): f - for p, f in RESULT_FLAT.iteritems() + for p, f in six.iteritems(RESULT_FLAT) if p.startswith('addon1/') }, 'app/chrome/addons/addon2.xpi': { mozpath.relpath(p, 'app/chrome/addons/addon2'): f - for p, f in RESULT_FLAT.iteritems() + for p, f in six.iteritems(RESULT_FLAT) if p.startswith('app/chrome/addons/addon2/') }, }) @@ -262,7 +263,7 @@ RESULT_OMNIJAR_WITH_SUBPATH = { CONTENTS_WITH_BASE = { 'bases': { mozpath.join('base/root', b) if b else 'base/root': a - for b, a in CONTENTS['bases'].iteritems() + for b, a in six.iteritems(CONTENTS['bases']) }, 'manifests': [ m.move(mozpath.join('base/root', m.base)) @@ -270,7 +271,7 @@ CONTENTS_WITH_BASE = { ], 'files': { mozpath.join('base/root', p): f - for p, f in CONTENTS['files'].iteritems() + for p, f in six.iteritems(CONTENTS['files']) }, } @@ -284,7 +285,7 @@ CONTENTS_WITH_BASE['files'].update(EXTRA_CONTENTS) def result_with_base(results): result = { mozpath.join('base/root', p): v - for p, v in results.iteritems() + for p, v in six.iteritems(results) } result.update(EXTRA_CONTENTS) return result @@ -302,7 +303,7 @@ def fill_formatter(formatter, contents): for manifest in contents['manifests']: formatter.add_manifest(manifest) - for k, v in sorted(contents['files'].iteritems()): + for k, v in sorted(six.iteritems(contents['files'])): if k.endswith('.xpt'): formatter.add_interfaces(k, v) else: diff --git a/python/mozbuild/mozpack/test/test_packager_l10n.py b/python/mozbuild/mozpack/test/test_packager_l10n.py index 6eb12767c6fa..e5acaf576661 100644 --- a/python/mozbuild/mozpack/test/test_packager_l10n.py +++ b/python/mozbuild/mozpack/test/test_packager_l10n.py @@ -5,6 +5,7 @@ from __future__ import absolute_import, print_function, unicode_literals import unittest +import six import mozunit from test_packager import MockFinder from mozpack.packager import l10n @@ -120,7 +121,7 @@ class TestL10NRepack(unittest.TestCase): self.assertEqual( dict((p, f.open().read()) for p, f in copier), - dict((p, f.open().read()) for p, f in repacked.iteritems()) + dict((p, f.open().read()) for p, f in six.iteritems(repacked)), )