diff --git a/.vpython3 b/.vpython3 index 1f38037812250a..39206c2700f540 100644 --- a/.vpython3 +++ b/.vpython3 @@ -28,7 +28,7 @@ python_version: "3.8" # components/policy/test_support/policy_testserver.py wheel: < name: "infra/python/wheels/protobuf-py2_py3" - version: "version:3.6.1" + version: "version:3.15.8" > # TODO(https://crbug.com/898348): Add in necessary wheels as Python3 versions diff --git a/chrome/browser/media/media_engagement_autoplay_browsertest.cc b/chrome/browser/media/media_engagement_autoplay_browsertest.cc index 12149380c424ea..96c2f6ccfb547b 100644 --- a/chrome/browser/media/media_engagement_autoplay_browsertest.cc +++ b/chrome/browser/media/media_engagement_autoplay_browsertest.cc @@ -28,18 +28,8 @@ namespace { base::FilePath GetPythonPath() { -#if defined(OS_WIN) - // Windows bots do not have python installed and available on the PATH. - // Please see infra/doc/users/python.md - base::FilePath bot_path = - base::FilePath(FILE_PATH_LITERAL("c:/infra-system/bin/python.exe")); - - if (base::PathExists(bot_path)) - return bot_path; - return base::FilePath(FILE_PATH_LITERAL("python.exe")); -#else - return base::FilePath(FILE_PATH_LITERAL("python")); -#endif + // Every environment should have vpython3. + return base::FilePath(FILE_PATH_LITERAL("vpython3")); } const base::FilePath kTestDataPath = base::FilePath( diff --git a/chrome/test/data/media/engagement/preload/BUILD.gn b/chrome/test/data/media/engagement/preload/BUILD.gn index 597329be4a9be7..f3f9634841f1d2 100644 --- a/chrome/test/data/media/engagement/preload/BUILD.gn +++ b/chrome/test/data/media/engagement/preload/BUILD.gn @@ -3,11 +3,9 @@ # found in the LICENSE file. import("//build/compiled_action.gni") -import("//build/config/python.gni") # Generates a proto file based on the real list. -# TODO(crbug.com/1112471): Get this to run cleanly under Python 3. -python2_action_foreach("generate_preload_list") { +action_foreach("generate_preload_list") { script = "//tools/media_engagement_preload/make_dafsa.py" sources = [ "test.json" ] diff --git a/tools/media_engagement_preload/PRESUBMIT.py b/tools/media_engagement_preload/PRESUBMIT.py index df19c77f97ceb3..97e25f9fe8ec05 100644 --- a/tools/media_engagement_preload/PRESUBMIT.py +++ b/tools/media_engagement_preload/PRESUBMIT.py @@ -5,6 +5,10 @@ """Chromium presubmit script for src/tools/media_engagement_preload.""" +# This line is 'magic' in that git-cl looks for it to decide whether to +# use Python3 instead of Python2 when running the code in this file. +USE_PYTHON3 = True + def _RunMakeDafsaTests(input_api, output_api): """Runs unittest for make_dafsa if any related file has been modified.""" @@ -12,16 +16,14 @@ def _RunMakeDafsaTests(input_api, output_api): 'tools/media_engagement_preload/make_dafsa_unittest.py') if not any(f in input_api.LocalPaths() for f in files): return [] - test_path = input_api.os_path.join(input_api.PresubmitLocalPath(), - 'make_dafsa_unittest.py') - cmd_name = 'make_dafsa_unittest' - cmd = [input_api.python_executable, test_path] - test_cmd = input_api.Command( - name=cmd_name, - cmd=cmd, - kwargs={}, - message=output_api.PresubmitPromptWarning) - return input_api.RunTests([test_cmd]) + + return input_api.RunTests( + input_api.canned_checks.RunUnitTestsInDirectory( + input_api, + output_api, + input_api.PresubmitLocalPath(), + files_to_check=['.*test\.py$'], + run_on_python2=False)) def CheckChangeOnUpload(input_api, output_api): diff --git a/tools/media_engagement_preload/make_dafsa.py b/tools/media_engagement_preload/make_dafsa.py index 72cbf7d32f8da8..db78c6720f48f3 100755 --- a/tools/media_engagement_preload/make_dafsa.py +++ b/tools/media_engagement_preload/make_dafsa.py @@ -1,4 +1,4 @@ -#!/usr/bin/env python +#!/usr/bin/env python3 # Copyright 2017 The Chromium Authors. All rights reserved. # Use of this source code is governed by a BSD-style license that can be # found in the LICENSE file. @@ -9,7 +9,7 @@ import json import sys import os -import urlparse +import urllib.parse SOURCE_ROOT = os.path.join(os.path.dirname( os.path.abspath(__file__)), os.pardir, os.pardir) @@ -440,7 +440,7 @@ def encode(dafsa): def to_proto(data): """Generates protobuf from a list of encoded bytes.""" message = media_engagement_preload_pb2.PreloadedData() - message.dafsa = array.array('B', data).tostring() + message.dafsa = array.array('B', data).tobytes() return message.SerializeToString() @@ -458,7 +458,7 @@ def parse_json(infile): netlocs = {} for entry in json.loads(infile): # Parse the origin and reject any with an invalid protocol. - parsed = urlparse.urlparse(entry) + parsed = urllib.parse.urlparse(entry) if parsed.scheme != 'http' and parsed.scheme != 'https': raise InputError('Invalid protocol: %s' % entry) @@ -471,7 +471,7 @@ def parse_json(infile): # Join the numerical values to the netlocs. output = [] - for location, value in netlocs.iteritems(): + for location, value in netlocs.items(): output.append(location + str(value)) return output except ValueError: diff --git a/tools/media_engagement_preload/make_dafsa_unittest.py b/tools/media_engagement_preload/make_dafsa_unittest.py index cdf7965b64bd16..3575af58790234 100755 --- a/tools/media_engagement_preload/make_dafsa_unittest.py +++ b/tools/media_engagement_preload/make_dafsa_unittest.py @@ -1,4 +1,4 @@ -#!/usr/bin/env python +#!/usr/bin/env python3 # Copyright 2017 The Chromium Authors. All rights reserved. # Use of this source code is governed by a BSD-style license that can be # found in the LICENSE file. @@ -6,6 +6,7 @@ import sys import unittest + import make_dafsa @@ -678,14 +679,14 @@ class ExamplesTest(unittest.TestCase): def testExample1(self): """Tests Example 1 from make_dafsa.py.""" infile = '["https://www.example.com:8081", "http://www.example.org"]' - outfile = "\n\x1c\x81www.example\xae\x02\x89com:8081\x80org\x81" + outfile = b'\n\x1c\x81www.example\xae\x02\x84org\x81com:8081\x80' self.assertEqual(make_dafsa.words_to_proto(make_dafsa.parse_json(infile)), outfile) def testExample2(self): """Tests Example 2 from make_dafsa.py.""" infile = '["https://www.example.org", "http://www.google.com"]' - outfile = "\n\x1e\x81www\xae\x02\x8bgoogle.com\x81example.org\x80" + outfile = b'\n\x1e\x81www\xae\x02\x8bgoogle.com\x81example.org\x80' self.assertEqual(make_dafsa.words_to_proto(make_dafsa.parse_json(infile)), outfile) diff --git a/tools/media_engagement_preload/media_engagement_preload_pb2.py b/tools/media_engagement_preload/media_engagement_preload_pb2.py index 0cde5091568cf9..bdb9bdce6036b9 100644 --- a/tools/media_engagement_preload/media_engagement_preload_pb2.py +++ b/tools/media_engagement_preload/media_engagement_preload_pb2.py @@ -1,23 +1,26 @@ -# Copyright 2017 The Chromium Authors. All rights reserved. -# Use of this source code is governed by a BSD-style license that can be -# found in the LICENSE file. - +# -*- coding: utf-8 -*- # Generated by the protocol buffer compiler. DO NOT EDIT! # source: media_engagement_preload.proto from google.protobuf import descriptor as _descriptor from google.protobuf import message as _message from google.protobuf import reflection as _reflection -from google.protobuf import descriptor_pb2 +from google.protobuf import symbol_database as _symbol_database # @@protoc_insertion_point(imports) +_sym_db = _symbol_database.Default() + DESCRIPTOR = _descriptor.FileDescriptor( name='media_engagement_preload.proto', package='chrome_browser_media', - serialized_pb='\n\x1emedia_engagement_preload.proto\x12\x14\x63hrome_browser_media\"\x1e\n\rPreloadedData\x12\r\n\x05\x64\x61\x66sa\x18\x01 \x01(\x0c\x42\x02H\x03') + syntax='proto2', + serialized_options=b'H\003', + create_key=_descriptor._internal_create_key, + serialized_pb=b'\n\x1emedia_engagement_preload.proto\x12\x14\x63hrome_browser_media\"\x1e\n\rPreloadedData\x12\r\n\x05\x64\x61\x66sa\x18\x01 \x01(\x0c\x42\x02H\x03' +) @@ -28,36 +31,41 @@ filename=None, file=DESCRIPTOR, containing_type=None, + create_key=_descriptor._internal_create_key, fields=[ _descriptor.FieldDescriptor( name='dafsa', full_name='chrome_browser_media.PreloadedData.dafsa', index=0, number=1, type=12, cpp_type=9, label=1, - has_default_value=False, default_value="", + has_default_value=False, default_value=b"", message_type=None, enum_type=None, containing_type=None, is_extension=False, extension_scope=None, - options=None), + serialized_options=None, file=DESCRIPTOR, create_key=_descriptor._internal_create_key), ], extensions=[ ], nested_types=[], enum_types=[ ], - options=None, + serialized_options=None, is_extendable=False, + syntax='proto2', extension_ranges=[], + oneofs=[ + ], serialized_start=56, serialized_end=86, ) DESCRIPTOR.message_types_by_name['PreloadedData'] = _PRELOADEDDATA +_sym_db.RegisterFileDescriptor(DESCRIPTOR) -class PreloadedData(_message.Message): - __metaclass__ = _reflection.GeneratedProtocolMessageType - DESCRIPTOR = _PRELOADEDDATA - +PreloadedData = _reflection.GeneratedProtocolMessageType('PreloadedData', (_message.Message,), { + 'DESCRIPTOR' : _PRELOADEDDATA, + '__module__' : 'media_engagement_preload_pb2' # @@protoc_insertion_point(class_scope:chrome_browser_media.PreloadedData) + }) +_sym_db.RegisterMessage(PreloadedData) -DESCRIPTOR.has_options = True -DESCRIPTOR._options = _descriptor._ParseOptions(descriptor_pb2.FileOptions(), 'H\003') +DESCRIPTOR._options = None # @@protoc_insertion_point(module_scope)