Bug 1547730 - Switch to six.string_types instead of types.StringTypes for py3 r=#build
☠☠ backed out by ee4b88439111 ☠ ☠
authorJustin Wood <Callek@gmail.com>
Sun, 14 Apr 2019 21:27:36 -0400
changeset 474139 1b766ee6bf2385df6cd79ad01edd47dcfa56b657
parent 474138 c846bf431b5c79ea08053f1fa9952ea6543d41d7
child 474140 35e2dc6ad3474355bdeb4d1639fba65d61c24cf6
push id36023
push userncsoregi@mozilla.com
push dateThu, 16 May 2019 21:56:43 +0000
treeherdermozilla-central@786f094a30ae [default view] [failures only]
perfherder[talos] [build metrics] [platform microbench] (compared to previous push)
bugs1547730
milestone68.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 1547730 - Switch to six.string_types instead of types.StringTypes for py3 r=#build Differential Revision: https://phabricator.services.mozilla.com/D28098
python/mozbuild/mozbuild/backend/configenvironment.py
python/mozbuild/mozbuild/base.py
python/mozbuild/mozbuild/configure/__init__.py
python/mozbuild/mozbuild/configure/options.py
python/mozbuild/mozbuild/makeutil.py
python/mozbuild/mozbuild/util.py
--- a/python/mozbuild/mozbuild/backend/configenvironment.py
+++ b/python/mozbuild/mozbuild/backend/configenvironment.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/.
 
 from __future__ import absolute_import, print_function
 
 import os
+import six
 import sys
 import json
 
 from collections import Iterable, OrderedDict
-from types import StringTypes, ModuleType
+from types import ModuleType
 
 import mozpack.path as mozpath
 
 from mozbuild.util import (
     FileAvoidWrite,
     memoized_property,
     ReadOnlyDict,
 )
@@ -152,17 +153,17 @@ class ConfigEnvironment(object):
         self.substs["ACDEFINES"] = ' '.join(
             [
                 '-D%s=%s' % (name, shell_quote(self.defines[name]).replace('$', '$$'))
                 for name in sorted(global_defines)
             ]
         )
 
         def serialize(name, obj):
-            if isinstance(obj, StringTypes):
+            if isinstance(obj, six.string_types):
                 return obj
             if isinstance(obj, Iterable):
                 return ' '.join(obj)
             raise Exception('Unhandled type %s for %s', type(obj), str(name))
         self.substs['ALLSUBSTS'] = '\n'.join(
             sorted([
                 '%s = %s' % (
                     name,
@@ -198,17 +199,17 @@ class ConfigEnvironment(object):
         def decode(v):
             if not isinstance(v, text_type):
                 try:
                     return v.decode('utf-8')
                 except UnicodeDecodeError:
                     return v.decode('utf-8', 'replace')
 
         for k, v in self.substs.items():
-            if not isinstance(v, StringTypes):
+            if not isinstance(v, six.string_types):
                 if isinstance(v, Iterable):
                     type(v)(decode(i) for i in v)
             elif not isinstance(v, text_type):
                 v = decode(v)
 
             self.substs_unicode[k] = v
 
         self.substs_unicode = ReadOnlyDict(self.substs_unicode)
--- a/python/mozbuild/mozbuild/base.py
+++ b/python/mozbuild/mozbuild/base.py
@@ -4,19 +4,19 @@
 
 from __future__ import absolute_import, print_function, unicode_literals
 
 import json
 import logging
 import mozpack.path as mozpath
 import multiprocessing
 import os
+import six
 import subprocess
 import sys
-import types
 import errno
 try:
     from shutil import which
 except ImportError:
     # shutil.which is not available in Python 2.7
     import which
 
 from StringIO import StringIO
@@ -284,17 +284,17 @@ class MozbuildObject(ProcessExecutionMix
 
         # Modified configure sandbox that replaces '--help' dependencies with
         # `always`, such that depends functions with a '--help' dependency are
         # not automatically executed when including files. We don't want all of
         # those from init.configure to execute, only a subset.
         class ReducedConfigureSandbox(ConfigureSandbox):
             def depends_impl(self, *args, **kwargs):
                 args = tuple(
-                    a if not isinstance(a, types.StringTypes) or a != '--help'
+                    a if not isinstance(a, six.string_types) or a != '--help'
                     else self._always.sandboxed
                     for a in args
                 )
                 return super(ReducedConfigureSandbox, self).depends_impl(*args, **kwargs)
 
         sandbox = ReducedConfigureSandbox({}, environ=env, argv=['mach', '--help'],
                                           stdout=out, stderr=out)
         base_dir = os.path.join(topsrcdir, 'build', 'moz.configure')
--- a/python/mozbuild/mozbuild/configure/__init__.py
+++ b/python/mozbuild/mozbuild/configure/__init__.py
@@ -596,17 +596,17 @@ class ConfigureSandbox(dict):
                     % option_string.split('=', 1)[0])
             self._logger.log(TRACE, '%r = None', option)
             return None
 
         self._logger.log(TRACE, '%r = %r', option, value)
         return value
 
     def _dependency(self, arg, callee_name, arg_name=None):
-        if isinstance(arg, types.StringTypes):
+        if isinstance(arg, six.string_types):
             prefix, name, values = Option.split_option(arg)
             if values != ():
                 raise ConfigureError("Option must not contain an '='")
             if name not in self._options:
                 raise ConfigureError("'%s' is not a known option. "
                                      "Maybe it's declared too late?"
                                      % arg)
             arg = self._options[name]
@@ -740,17 +740,17 @@ class ConfigureSandbox(dict):
         Allows to include external files for execution in the sandbox.
         It is possible to use a @depends function as argument, in which case
         the result of the function is the file name to include. This latter
         feature is only really meant for --enable-application/--enable-project.
         '''
         with self.only_when_impl(when):
             what = self._resolve(what)
             if what:
-                if not isinstance(what, types.StringTypes):
+                if not isinstance(what, six.string_types):
                     raise TypeError("Unexpected type: '%s'" % type(what).__name__)
                 self.include_file(what)
 
     def template_impl(self, func):
         '''Implementation of @template.
         This function is a decorator. Template functions are called
         immediately. They are altered so that their global namespace exposes
         a limited set of functions from os.path, as well as `depends` and
@@ -818,17 +818,17 @@ class ConfigureSandbox(dict):
         optionally under a different _as name.
         The options correspond to the various forms for the import builtin.
             @imports('sys')
             @imports(_from='mozpack', _import='path', _as='mozpath')
         '''
         for value, required in (
                 (_import, True), (_from, False), (_as, False)):
 
-            if not isinstance(value, types.StringTypes) and (
+            if not isinstance(value, six.string_types) and (
                     required or value is not None):
                 raise TypeError("Unexpected type: '%s'" % type(value).__name__)
             if value is not None and not self.RE_MODULE.match(value):
                 raise ValueError("Invalid argument to @imports: '%s'" % value)
         if _as and '.' in _as:
             raise ValueError("Invalid argument to @imports: '%s'" % _as)
 
         def decorator(func):
@@ -917,17 +917,17 @@ class ConfigureSandbox(dict):
         # Don't set anything when --help was on the command line
         if self._help:
             return
         if when and not self._value_for(when):
             return
         name = self._resolve(name)
         if name is None:
             return
-        if not isinstance(name, types.StringTypes):
+        if not isinstance(name, six.string_types):
             raise TypeError("Unexpected type: '%s'" % type(name).__name__)
         if name in data:
             raise ConfigureError(
                 "Cannot add '%s' to configuration: Key already "
                 "exists" % name)
         value = self._resolve(value)
         if value is not None:
             if self._logger.isEnabledFor(TRACE):
@@ -1015,17 +1015,17 @@ class ConfigureSandbox(dict):
             return
         if not reason and isinstance(value, SandboxDependsFunction):
             deps = self._depends[value].dependencies
             possible_reasons = [d for d in deps if d != self._help_option]
             if len(possible_reasons) == 1:
                 if isinstance(possible_reasons[0], Option):
                     reason = possible_reasons[0]
         if not reason and (isinstance(value, (bool, tuple)) or
-                           isinstance(value, types.StringTypes)):
+                           isinstance(value, six.string_types)):
             # A reason can be provided automatically when imply_option
             # is called with an immediate value.
             _, filename, line, _, _, _ = inspect.stack()[1]
             reason = "imply_option at %s:%s" % (filename, line)
 
         if not reason:
             raise ConfigureError(
                 "Cannot infer what implies '%s'. Please add a `reason` to "
--- a/python/mozbuild/mozbuild/configure/options.py
+++ b/python/mozbuild/mozbuild/configure/options.py
@@ -8,17 +8,17 @@ import os
 import six
 import sys
 import types
 from collections import OrderedDict
 
 
 def istupleofstrings(obj):
     return isinstance(obj, tuple) and len(obj) and all(
-        isinstance(o, types.StringTypes) for o in obj)
+        isinstance(o, six.string_types) for o in obj)
 
 
 class OptionValue(tuple):
     '''Represents the value of a configure option.
 
     This class is not meant to be used directly. Use its subclasses instead.
 
     The `origin` attribute holds where the option comes from (e.g. environment,
@@ -88,17 +88,17 @@ class OptionValue(tuple):
     @staticmethod
     def from_(value):
         if isinstance(value, OptionValue):
             return value
         elif value is True:
             return PositiveOptionValue()
         elif value is False or value == ():
             return NegativeOptionValue()
-        elif isinstance(value, types.StringTypes):
+        elif isinstance(value, six.string_types):
             return PositiveOptionValue((value,))
         elif isinstance(value, tuple):
             return PositiveOptionValue(value)
         else:
             raise TypeError("Unexpected type: '%s'"
                             % type(value).__name__)
 
 
@@ -164,36 +164,36 @@ class Option(object):
 
     def __init__(self, name=None, env=None, nargs=None, default=None,
                  possible_origins=None, choices=None, help=None):
         if not name and not env:
             raise InvalidOptionError(
                 'At least an option name or an environment variable name must '
                 'be given')
         if name:
-            if not isinstance(name, types.StringTypes):
+            if not isinstance(name, six.string_types):
                 raise InvalidOptionError('Option must be a string')
             if not name.startswith('--'):
                 raise InvalidOptionError('Option must start with `--`')
             if '=' in name:
                 raise InvalidOptionError('Option must not contain an `=`')
             if not name.islower():
                 raise InvalidOptionError('Option must be all lowercase')
         if env:
-            if not isinstance(env, types.StringTypes):
+            if not isinstance(env, six.string_types):
                 raise InvalidOptionError(
                     'Environment variable name must be a string')
             if not env.isupper():
                 raise InvalidOptionError(
                     'Environment variable name must be all uppercase')
         if nargs not in (None, '?', '*', '+') and not (
                 isinstance(nargs, int) and nargs >= 0):
             raise InvalidOptionError(
                 "nargs must be a positive integer, '?', '*' or '+'")
-        if (not isinstance(default, types.StringTypes) and
+        if (not isinstance(default, six.string_types) and
                 not isinstance(default, (bool, types.NoneType)) and
                 not istupleofstrings(default)):
             raise InvalidOptionError(
                 'default must be a bool, a string or a tuple of strings')
         if choices and not istupleofstrings(choices):
             raise InvalidOptionError(
                 'choices must be a tuple of strings')
         if not help:
@@ -270,17 +270,17 @@ class Option(object):
     def split_option(option):
         '''Split a flag or variable into a prefix, a name and values
 
         Variables come in the form NAME=values (no prefix).
         Flags come in the form --name=values or --prefix-name=values
         where prefix is one of 'with', 'without', 'enable' or 'disable'.
         The '=values' part is optional. Values are separated with commas.
         '''
-        if not isinstance(option, types.StringTypes):
+        if not isinstance(option, six.string_types):
             raise InvalidOptionError('Option must be a string')
 
         elements = option.split('=', 1)
         name = elements[0]
         values = tuple(elements[1].split(',')) if len(elements) == 2 else ()
         if name.startswith('--'):
             name = name[2:]
             if not name.islower():
--- a/python/mozbuild/mozbuild/makeutil.py
+++ b/python/mozbuild/mozbuild/makeutil.py
@@ -1,17 +1,17 @@
 # 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
 
 import os
 import re
-from types import StringTypes
+import six
 from collections import Iterable
 
 
 class Makefile(object):
     '''Provides an interface for writing simple makefiles
 
     Instances of this class are created, populated with rules, then
     written.
@@ -100,29 +100,29 @@ class Rule(object):
     def __init__(self, targets=[]):
         self._targets = _SimpleOrderedSet()
         self._dependencies = _SimpleOrderedSet()
         self._commands = []
         self.add_targets(targets)
 
     def add_targets(self, targets):
         '''Add additional targets to the rule.'''
-        assert isinstance(targets, Iterable) and not isinstance(targets, StringTypes)
+        assert isinstance(targets, Iterable) and not isinstance(targets, six.string_types)
         self._targets.update(targets)
         return self
 
     def add_dependencies(self, deps):
         '''Add dependencies to the rule.'''
-        assert isinstance(deps, Iterable) and not isinstance(deps, StringTypes)
+        assert isinstance(deps, Iterable) and not isinstance(deps, six.string_types)
         self._dependencies.update(deps)
         return self
 
     def add_commands(self, commands):
         '''Add commands to the rule.'''
-        assert isinstance(commands, Iterable) and not isinstance(commands, StringTypes)
+        assert isinstance(commands, Iterable) and not isinstance(commands, six.string_types)
         self._commands.extend(commands)
         return self
 
     def targets(self):
         '''Return an iterator on the rule targets.'''
         # Ensure the returned iterator is actually just that, an iterator.
         # Avoids caller fiddling with the set itself.
         return iter(self._targets)
--- a/python/mozbuild/mozbuild/util.py
+++ b/python/mozbuild/mozbuild/util.py
@@ -1159,17 +1159,17 @@ def expand_variables(s, variables):
     If a variable value is not a string, it is iterated and its items are
     joined with a whitespace.'''
     result = ''
     for s, name in pair(VARIABLES_RE.split(s)):
         result += s
         value = variables.get(name)
         if not value:
             continue
-        if not isinstance(value, types.StringTypes):
+        if not isinstance(value, six.string_types):
             value = ' '.join(value)
         result += value
     return result
 
 
 class DefinesAction(argparse.Action):
     '''An ArgumentParser action to handle -Dvar[=value] type of arguments.'''