зеркало из https://github.com/mozilla/gecko-dev.git
Bug 1847196 - Remove python 2 compatibility code from mozbuild.frontend.reader. r=firefox-build-system-reviewers,ahochheiden
The starting point was a Deprecation warning about visit_Str. It turns out the function used to have an enlightening comment before bug 1616920, which read: # String nodes we got from the AST parser are str, but we want # unicode literals everywhere, so transform them. In other words, the sole purpose of that function was to make the transformed code closer to python 3 even when running in python 2. It's a no-op on python 3, and, well we don't support python 2 anymore. So the method can just go away. While here, it turned out that some of the code that was added in bug 1616920 can also be undone because we don't need python 2 compatibility anymore. And while we're doing that, let's just remove the uses of six as well. Differential Revision: https://phabricator.services.mozilla.com/D185421
This commit is contained in:
Родитель
a640c1e16d
Коммит
c67fb78742
|
@ -17,6 +17,7 @@ It does this by examining specific variables populated during execution.
|
|||
"""
|
||||
|
||||
import ast
|
||||
import functools
|
||||
import inspect
|
||||
import logging
|
||||
import os
|
||||
|
@ -32,9 +33,7 @@ from itertools import chain
|
|||
from multiprocessing import cpu_count
|
||||
|
||||
import mozpack.path as mozpath
|
||||
import six
|
||||
from mozpack.files import FileFinder
|
||||
from six import string_types
|
||||
|
||||
from mozbuild.backend.configenvironment import ConfigEnvironment
|
||||
from mozbuild.base import ExecutionSummary
|
||||
|
@ -66,11 +65,6 @@ from .sandbox import (
|
|||
default_finder,
|
||||
)
|
||||
|
||||
if six.PY2:
|
||||
type_type = types.TypeType
|
||||
else:
|
||||
type_type = type
|
||||
|
||||
|
||||
def log(logger, level, action, params, formatter):
|
||||
logger.log(level, formatter, extra={"action": action, "params": params})
|
||||
|
@ -410,15 +404,14 @@ class TemplateFunction(object):
|
|||
# When using a custom dictionary for function globals/locals, Cpython
|
||||
# actually never calls __getitem__ and __setitem__, so we need to
|
||||
# modify the AST so that accesses to globals are properly directed
|
||||
# to a dict. AST wants binary_type for this in Py2 and text_type for
|
||||
# this in Py3, so cast to str.
|
||||
self._global_name = str("_data")
|
||||
# to a dict.
|
||||
self._global_name = "_data"
|
||||
# In case '_data' is a name used for a variable in the function code,
|
||||
# prepend more underscores until we find an unused name.
|
||||
while (
|
||||
self._global_name in code.co_names or self._global_name in code.co_varnames
|
||||
):
|
||||
self._global_name += str("_")
|
||||
self._global_name += "_"
|
||||
func_ast = self.RewriteName(sandbox, self._global_name).visit(func_ast)
|
||||
|
||||
# Execute the rewritten code. That code now looks like:
|
||||
|
@ -461,10 +454,6 @@ class TemplateFunction(object):
|
|||
self._sandbox = sandbox
|
||||
self._global_name = global_name
|
||||
|
||||
def visit_Str(self, node):
|
||||
node.s = six.ensure_text(node.s)
|
||||
return node
|
||||
|
||||
def visit_Name(self, node):
|
||||
# Modify uppercase variable references and names known to the
|
||||
# sandbox as if they were retrieved from a dict instead.
|
||||
|
@ -598,10 +587,7 @@ class BuildReaderError(Exception):
|
|||
s.write("the execution. The reported error is:\n")
|
||||
s.write("\n")
|
||||
s.write(
|
||||
"".join(
|
||||
" %s\n" % l
|
||||
for l in six.text_type(self.validation_error).splitlines()
|
||||
)
|
||||
"".join(" %s\n" % l for l in str(self.validation_error).splitlines())
|
||||
)
|
||||
s.write("\n")
|
||||
else:
|
||||
|
@ -613,7 +599,7 @@ class BuildReaderError(Exception):
|
|||
for l in traceback.format_exception(
|
||||
type(self.other), self.other, self.trace
|
||||
):
|
||||
s.write(six.ensure_text(l))
|
||||
s.write(str(l))
|
||||
|
||||
return s.getvalue()
|
||||
|
||||
|
@ -810,7 +796,7 @@ class BuildReaderError(Exception):
|
|||
s.write("\n")
|
||||
s.write("This variable expects the following type(s):\n")
|
||||
s.write("\n")
|
||||
if type(inner.args[4]) == type_type:
|
||||
if type(inner.args[4]) == type:
|
||||
s.write(" %s\n" % inner.args[4].__name__)
|
||||
else:
|
||||
for t in inner.args[4]:
|
||||
|
@ -974,7 +960,7 @@ class BuildReader(object):
|
|||
defined if the variable is an object, otherwise it is `None`.
|
||||
"""
|
||||
|
||||
if isinstance(variables, string_types):
|
||||
if isinstance(variables, str):
|
||||
variables = [variables]
|
||||
|
||||
def assigned_variable(node):
|
||||
|
@ -1192,7 +1178,7 @@ class BuildReader(object):
|
|||
raise SandboxValidationError("Cannot find %s." % source, context)
|
||||
non_unified_sources.add(source)
|
||||
action_overrides = {}
|
||||
for action, script in six.iteritems(gyp_dir.action_overrides):
|
||||
for action, script in gyp_dir.action_overrides.items():
|
||||
action_overrides[action] = SourcePath(context, script)
|
||||
|
||||
gyp_processor = GypProcessor(
|
||||
|
@ -1365,7 +1351,7 @@ class BuildReader(object):
|
|||
|
||||
result = {}
|
||||
for path, paths in path_mozbuilds.items():
|
||||
result[path] = six.moves.reduce(
|
||||
result[path] = functools.reduce(
|
||||
lambda x, y: x + y, (contexts[p] for p in paths), []
|
||||
)
|
||||
|
||||
|
|
Загрузка…
Ссылка в новой задаче