[tools] Clean up py2 code
Bug: chromium:1292013 Change-Id: Ic2c3a197005a2136bb0eda4cbb36d8eb57f42a7c Reviewed-on: https://chromium-review.googlesource.com/c/v8/v8/+/3523047 Reviewed-by: Liviu Rau <liviurau@chromium.org> Commit-Queue: Michael Achenbach <machenbach@chromium.org> Cr-Commit-Position: refs/heads/main@{#79507}
This commit is contained in:
parent
33bf4c4bca
commit
1289704aae
@ -9,5 +9,6 @@ USE_PYTHON3 = True
|
||||
|
||||
def CheckChangeOnCommit(input_api, output_api):
|
||||
tests = input_api.canned_checks.GetUnitTestsInDirectory(
|
||||
input_api, output_api, 'unittests', files_to_check=[r'.+_test\.py$'])
|
||||
input_api, output_api, 'unittests', files_to_check=[r'.+_test\.py$'],
|
||||
run_on_python2=False)
|
||||
return input_api.RunTests(tests)
|
||||
|
@ -14,6 +14,7 @@ def _CommonChecks(input_api, output_api):
|
||||
input_api.os_path.join(input_api.PresubmitLocalPath()),
|
||||
files_to_check=[r'.+_unittest\.py$'],
|
||||
files_to_skip=[],
|
||||
run_on_python2=False,
|
||||
))
|
||||
|
||||
def CheckChangeOnUpload(input_api, output_api):
|
||||
|
@ -2,8 +2,6 @@
|
||||
# Use of this source code is governed by a BSD-style license that can be
|
||||
# found in the LICENSE file.
|
||||
|
||||
# for py2/py3 compatibility
|
||||
from __future__ import print_function
|
||||
from functools import reduce
|
||||
|
||||
from collections import OrderedDict, namedtuple
|
||||
|
@ -2,9 +2,6 @@
|
||||
# Use of this source code is governed by a BSD-style license that can be
|
||||
# found in the LICENSE file.
|
||||
|
||||
# for py2/py3 compatibility
|
||||
from __future__ import print_function
|
||||
|
||||
from contextlib import contextmanager
|
||||
import os
|
||||
import re
|
||||
@ -19,8 +16,6 @@ from ..local.android import (
|
||||
from ..local import utils
|
||||
from ..objects import output
|
||||
|
||||
PYTHON3 = sys.version_info >= (3, 0)
|
||||
|
||||
BASE_DIR = os.path.normpath(
|
||||
os.path.join(os.path.dirname(os.path.abspath(__file__)), '..' , '..', '..'))
|
||||
|
||||
@ -115,17 +110,11 @@ class BaseCommand(object):
|
||||
|
||||
timer.cancel()
|
||||
|
||||
def convert(stream):
|
||||
if PYTHON3:
|
||||
return stream.decode('utf-8', 'replace')
|
||||
else:
|
||||
return stream.decode('utf-8', 'replace').encode('utf-8')
|
||||
|
||||
return output.Output(
|
||||
process.returncode,
|
||||
timeout_occured[0],
|
||||
convert(stdout),
|
||||
convert(stderr),
|
||||
stdout.decode('utf-8', 'replace'),
|
||||
stderr.decode('utf-8', 'replace'),
|
||||
process.pid,
|
||||
duration
|
||||
)
|
||||
|
@ -1,11 +1,8 @@
|
||||
#!/usr/bin/env python
|
||||
#!/usr/bin/env python3
|
||||
# Copyright 2014 the V8 project authors. All rights reserved.
|
||||
# Use of this source code is governed by a BSD-style license that can be
|
||||
# found in the LICENSE file.
|
||||
|
||||
# for py2/py3 compatibility
|
||||
from __future__ import print_function
|
||||
|
||||
from contextlib import contextmanager
|
||||
from multiprocessing import Process, Queue
|
||||
import os
|
||||
|
@ -1,4 +1,4 @@
|
||||
#!/usr/bin/env python
|
||||
#!/usr/bin/env python3
|
||||
# Copyright 2014 the V8 project authors. All rights reserved.
|
||||
# Use of this source code is governed by a BSD-style license that can be
|
||||
# found in the LICENSE file.
|
||||
@ -28,7 +28,7 @@ class PoolTest(unittest.TestCase):
|
||||
# Any result can be a heartbeat due to timings.
|
||||
continue
|
||||
results.add(result.value)
|
||||
self.assertEquals(set(range(0, 10)), results)
|
||||
self.assertEqual(set(range(0, 10)), results)
|
||||
|
||||
def testException(self):
|
||||
results = set()
|
||||
@ -42,7 +42,7 @@ class PoolTest(unittest.TestCase):
|
||||
results.add(result.value)
|
||||
expect = set(range(0, 12))
|
||||
expect.remove(10)
|
||||
self.assertEquals(expect, results)
|
||||
self.assertEqual(expect, results)
|
||||
|
||||
def testAdd(self):
|
||||
results = set()
|
||||
@ -54,8 +54,9 @@ class PoolTest(unittest.TestCase):
|
||||
results.add(result.value)
|
||||
if result.value < 30:
|
||||
pool.add([result.value + 20])
|
||||
self.assertEquals(set(range(0, 10) + range(20, 30) + range(40, 50)),
|
||||
results)
|
||||
self.assertEqual(
|
||||
set(range(0, 10)) | set(range(20, 30)) | set(range(40, 50)),
|
||||
results)
|
||||
|
||||
|
||||
if __name__ == '__main__':
|
||||
|
@ -25,10 +25,6 @@
|
||||
# (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE
|
||||
# OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
|
||||
|
||||
# for py2/py3 compatibility
|
||||
from __future__ import print_function
|
||||
from __future__ import absolute_import
|
||||
|
||||
import os
|
||||
import re
|
||||
|
||||
|
@ -1,10 +1,8 @@
|
||||
#!/usr/bin/env python
|
||||
#!/usr/bin/env python3
|
||||
# Copyright 2016 the V8 project authors. All rights reserved.
|
||||
# Use of this source code is governed by a BSD-style license that can be
|
||||
# found in the LICENSE file.
|
||||
|
||||
|
||||
from __future__ import absolute_import
|
||||
import os
|
||||
import sys
|
||||
import unittest
|
||||
|
@ -1,4 +1,4 @@
|
||||
#!/usr/bin/env python
|
||||
#!/usr/bin/env python3
|
||||
# Copyright 2016 the V8 project authors. All rights reserved.
|
||||
# Use of this source code is governed by a BSD-style license that can be
|
||||
# found in the LICENSE file.
|
||||
|
@ -25,9 +25,6 @@
|
||||
# (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE
|
||||
# OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
|
||||
|
||||
# for py2/py3 compatibility
|
||||
from __future__ import print_function
|
||||
|
||||
from os.path import exists
|
||||
from os.path import isdir
|
||||
from os.path import join
|
||||
|
@ -25,9 +25,6 @@
|
||||
# (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE
|
||||
# OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
|
||||
|
||||
# for py2/py3 compatibility
|
||||
from __future__ import print_function
|
||||
|
||||
import sys
|
||||
import time
|
||||
|
||||
|
@ -1,13 +1,9 @@
|
||||
#!/usr/bin/env python
|
||||
#!/usr/bin/env python3
|
||||
#
|
||||
# Copyright 2017 the V8 project authors. All rights reserved.
|
||||
# Use of this source code is governed by a BSD-style license that can be
|
||||
# found in the LICENSE file.
|
||||
|
||||
# for py2/py3 compatibility
|
||||
from __future__ import absolute_import
|
||||
from __future__ import print_function
|
||||
|
||||
import random
|
||||
import sys
|
||||
|
||||
|
@ -2,12 +2,7 @@
|
||||
# Use of this source code is governed by a BSD-style license that can be
|
||||
# found in the LICENSE file.
|
||||
|
||||
try: # Python3
|
||||
from itertools import zip_longest
|
||||
PYTHON3 = True
|
||||
except ImportError: # Python2
|
||||
from itertools import izip_longest as zip_longest
|
||||
PYTHON3 = False
|
||||
from itertools import zip_longest
|
||||
|
||||
from ..testproc.base import (
|
||||
DROP_RESULT, DROP_OUTPUT, DROP_PASS_OUTPUT, DROP_PASS_STDOUT)
|
||||
@ -147,9 +142,7 @@ class ExpectedOutProc(OutProc):
|
||||
if output.exit_code != 0:
|
||||
return True
|
||||
|
||||
# TODO(https://crbug.com/1292013): Simplify after Python3 migration.
|
||||
kwargs = {'encoding': 'utf-8'} if PYTHON3 else {}
|
||||
with open(self._expected_filename, 'r', **kwargs) as f:
|
||||
with open(self._expected_filename, 'r', encoding='utf-8') as f:
|
||||
expected_lines = f.readlines()
|
||||
|
||||
for act_iterator in self._act_block_iterator(output):
|
||||
|
@ -5,10 +5,7 @@
|
||||
import os
|
||||
import re
|
||||
|
||||
try: # Python3
|
||||
from itertools import zip_longest
|
||||
except ImportError: # Python2
|
||||
from itertools import izip_longest as zip_longest
|
||||
from itertools import zip_longest
|
||||
|
||||
from . import base
|
||||
|
||||
|
@ -1,12 +1,9 @@
|
||||
#!/usr/bin/env python
|
||||
#!/usr/bin/env python3
|
||||
#
|
||||
# Copyright 2017 the V8 project authors. All rights reserved.
|
||||
# Use of this source code is governed by a BSD-style license that can be
|
||||
# found in the LICENSE file.
|
||||
|
||||
# for py2/py3 compatibility
|
||||
from __future__ import absolute_import
|
||||
from __future__ import print_function
|
||||
from functools import reduce
|
||||
|
||||
import datetime
|
||||
|
@ -2,9 +2,6 @@
|
||||
# Use of this source code is governed by a BSD-style license that can be
|
||||
# found in the LICENSE file.
|
||||
|
||||
# for py2/py3 compatibility
|
||||
from __future__ import print_function
|
||||
|
||||
from collections import defaultdict
|
||||
import time
|
||||
|
||||
|
@ -2,10 +2,6 @@
|
||||
# Use of this source code is governed by a BSD-style license that can be
|
||||
# found in the LICENSE file.
|
||||
|
||||
# for py2/py3 compatibility
|
||||
from __future__ import print_function
|
||||
from __future__ import absolute_import
|
||||
|
||||
import datetime
|
||||
import json
|
||||
import os
|
||||
|
@ -1,4 +1,4 @@
|
||||
#!/usr/bin/env python
|
||||
#!/usr/bin/env python3
|
||||
# Copyright 2021 the V8 project authors. All rights reserved.
|
||||
# Use of this source code is governed by a BSD-style license that can be
|
||||
# found in the LICENSE file.
|
||||
@ -87,7 +87,8 @@ class TestSequenceProc(unittest.TestCase):
|
||||
self.assertEqual(set(test.n for test in tests), results.tests)
|
||||
|
||||
def test_wrong_usage(self):
|
||||
self.assertRaises(lambda: SequenceProc(0))
|
||||
with self.assertRaises(Exception):
|
||||
SequenceProc(0)
|
||||
|
||||
def test_no_tests(self):
|
||||
self._test([], 1, 1)
|
||||
|
@ -1,4 +1,4 @@
|
||||
#!/usr/bin/env python
|
||||
#!/usr/bin/env python3
|
||||
# Copyright 2019 the V8 project authors. All rights reserved.
|
||||
# Use of this source code is governed by a BSD-style license that can be
|
||||
# found in the LICENSE file.
|
||||
|
@ -2,9 +2,6 @@
|
||||
# Use of this source code is governed by a BSD-style license that can be
|
||||
# found in the LICENSE file.
|
||||
|
||||
# for py2/py3 compatibility
|
||||
from __future__ import print_function
|
||||
|
||||
import signal
|
||||
|
||||
from . import base
|
||||
|
@ -1,4 +1,3 @@
|
||||
from __future__ import print_function
|
||||
# Copyright 2018 the V8 project authors. All rights reserved.
|
||||
# Use of this source code is governed by a BSD-style license that can be
|
||||
# found in the LICENSE file.
|
||||
|
@ -1,4 +1,4 @@
|
||||
#!/usr/bin/env python
|
||||
#!/usr/bin/env python3
|
||||
# Copyright 2020 the V8 project authors. All rights reserved.
|
||||
# Use of this source code is governed by a BSD-style license that can be
|
||||
# found in the LICENSE file.
|
||||
|
@ -1,10 +1,8 @@
|
||||
#!/usr/bin/env python
|
||||
#!/usr/bin/env python3
|
||||
# Copyright 2020 the V8 project authors. All rights reserved.
|
||||
# Use of this source code is governed by a BSD-style license that can be
|
||||
# found in the LICENSE file.
|
||||
|
||||
from __future__ import absolute_import
|
||||
|
||||
import os
|
||||
import sys
|
||||
import unittest
|
||||
|
@ -1,4 +1,4 @@
|
||||
#!/usr/bin/env python
|
||||
#!/usr/bin/env python3
|
||||
# Copyright 2019 the V8 project authors. All rights reserved.
|
||||
# Use of this source code is governed by a BSD-style license that can be
|
||||
# found in the LICENSE file.
|
||||
|
@ -11,9 +11,6 @@ Raw gyp values are supported - they will be tranformed into valid json.
|
||||
"""
|
||||
# TODO(machenbach): Remove this when gyp is deprecated.
|
||||
|
||||
# for py2/py3 compatibility
|
||||
from __future__ import print_function
|
||||
|
||||
import json
|
||||
import os
|
||||
import sys
|
||||
|
@ -1,4 +1,4 @@
|
||||
#!/usr/bin/env python
|
||||
#!/usr/bin/env python3
|
||||
# Copyright 2017 the V8 project authors. All rights reserved.
|
||||
# Use of this source code is governed by a BSD-style license that can be
|
||||
# found in the LICENSE file.
|
||||
@ -17,9 +17,6 @@ with different test suite extensions and build configurations.
|
||||
# TODO(machenbach): Coverage data from multiprocessing doesn't work.
|
||||
# TODO(majeski): Add some tests for the fuzzers.
|
||||
|
||||
# for py2/py3 compatibility
|
||||
from __future__ import print_function
|
||||
|
||||
import collections
|
||||
import contextlib
|
||||
import json
|
||||
@ -30,11 +27,7 @@ import sys
|
||||
import tempfile
|
||||
import unittest
|
||||
|
||||
# TODO(https://crbug.com/1292016): Remove after Python3 migration.
|
||||
try:
|
||||
from cStringIO import StringIO
|
||||
except ImportError:
|
||||
from io import StringIO
|
||||
from io import StringIO
|
||||
|
||||
TOOLS_ROOT = os.path.dirname(os.path.dirname(os.path.abspath(__file__)))
|
||||
TEST_DATA_ROOT = os.path.join(TOOLS_ROOT, 'unittests', 'testdata')
|
||||
|
@ -1,4 +1,4 @@
|
||||
#!/usr/bin/env python
|
||||
#!/usr/bin/env python3
|
||||
#
|
||||
# Copyright 2012 the V8 project authors. All rights reserved.
|
||||
# Redistribution and use in source and binary forms, with or without
|
||||
@ -27,17 +27,8 @@
|
||||
# (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE
|
||||
# OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
|
||||
|
||||
|
||||
# for py2/py3 compatibility
|
||||
from __future__ import absolute_import
|
||||
from __future__ import print_function
|
||||
|
||||
try:
|
||||
import hashlib
|
||||
md5er = hashlib.md5
|
||||
except ImportError as e:
|
||||
import md5
|
||||
md5er = md5.new
|
||||
import hashlib
|
||||
md5er = hashlib.md5
|
||||
|
||||
|
||||
import json
|
||||
@ -55,13 +46,11 @@ from testrunner.local import statusfile
|
||||
from testrunner.local import testsuite
|
||||
from testrunner.local import utils
|
||||
|
||||
PYTHON3 = sys.version_info >= (3, 0)
|
||||
def decode(arg, encoding="utf-8"):
|
||||
return arg.decode(encoding)
|
||||
|
||||
def maybe_decode(arg, encoding="utf-8"):
|
||||
return arg.decode(encoding) if PYTHON3 else arg
|
||||
|
||||
def maybe_encode(arg, encoding="utf-8"):
|
||||
return arg.encode(encoding) if PYTHON3 else arg
|
||||
def encode(arg, encoding="utf-8"):
|
||||
return arg.encode(encoding)
|
||||
|
||||
# Special LINT rules diverging from default and reason.
|
||||
# build/header_guard: Our guards have the form "V8_FOO_H_", not "SRC_FOO_H_".
|
||||
@ -100,7 +89,7 @@ def CppLintWorker(command):
|
||||
out_lines = ""
|
||||
error_count = -1
|
||||
while True:
|
||||
out_line = maybe_decode(process.stderr.readline())
|
||||
out_line = decode(process.stderr.readline())
|
||||
if out_line == '' and process.poll() != None:
|
||||
if error_count == -1:
|
||||
print("Failed to process %s" % command.pop())
|
||||
@ -126,7 +115,7 @@ def TorqueLintWorker(command):
|
||||
out_lines = ""
|
||||
error_count = 0
|
||||
while True:
|
||||
out_line = maybe_decode(process.stderr.readline())
|
||||
out_line = decode(process.stderr.readline())
|
||||
if out_line == '' and process.poll() != None:
|
||||
break
|
||||
out_lines += out_line
|
||||
@ -156,7 +145,7 @@ def JSLintWorker(command):
|
||||
sys.stdout.write("error code " + str(rc) + " running clang-format.\n")
|
||||
return rc
|
||||
|
||||
if maybe_decode(output) != contents:
|
||||
if decode(output) != contents:
|
||||
return 1
|
||||
|
||||
return 0
|
||||
@ -214,7 +203,7 @@ class FileContentsCache(object):
|
||||
for file in files:
|
||||
try:
|
||||
handle = open(file, "r")
|
||||
file_sum = md5er(maybe_encode(handle.read())).digest()
|
||||
file_sum = md5er(encode(handle.read())).digest()
|
||||
if not file in self.sums or self.sums[file] != file_sum:
|
||||
changed_or_new.append(file)
|
||||
self.sums[file] = file_sum
|
||||
@ -498,7 +487,7 @@ class SourceProcessor(SourceFileProcessor):
|
||||
output = subprocess.Popen('git ls-files --full-name',
|
||||
stdout=PIPE, cwd=path, shell=True)
|
||||
result = []
|
||||
for file in maybe_decode(output.stdout.read()).split():
|
||||
for file in decode(output.stdout.read()).split():
|
||||
for dir_part in os.path.dirname(file).replace(os.sep, '/').split('/'):
|
||||
if self.IgnoreDir(dir_part):
|
||||
break
|
||||
@ -632,7 +621,7 @@ class SourceProcessor(SourceFileProcessor):
|
||||
for file in files:
|
||||
try:
|
||||
handle = open(file, "rb")
|
||||
contents = maybe_decode(handle.read(), "ISO-8859-1")
|
||||
contents = decode(handle.read(), "ISO-8859-1")
|
||||
if len(contents) > 0 and not self.ProcessContents(file, contents):
|
||||
success = False
|
||||
violations += 1
|
||||
|
Loading…
Reference in New Issue
Block a user