0

Reland "chrome: run tools/media_engagement_preload/make_dafsa.py in python3"

This reverts commit e30fcda2eb.

Reason for revert:
use python3 instead of vpython3 explicitly in
chrome/browser/media/media_engagement_autoplay_browsertest.cc


.vpython3 change is for PRESUBMIT.py which uses vpython3 by default.

Original change's description:
> Revert "chrome: run tools/media_engagement_preload/make_dafsa.py in python3"
>
> This reverts commit 07e05386c5.
>
> Reason for revert: MediaEngagementAutoplayBrowserTest is failing on mac bots:
> https://ci.chromium.org/ui/p/chromium/builders/ci/Mac10.11%20Tests/63046/overview
> https://ci.chromium.org/ui/p/chromium/builders/ci/Mac10.12%20Tests/43848/overview
>
> Original change's description:
> > chrome: run tools/media_engagement_preload/make_dafsa.py in python3
> >
> > Fixed: 1210295
> > Change-Id: I531f99ba4209086c25157854321e3addf1ce632e
> > Reviewed-on: https://chromium-review.googlesource.com/c/chromium/src/+/2903407
> > Auto-Submit: Takuto Ikuta <tikuta@chromium.org>
> > Reviewed-by: Dirk Pranke <dpranke@google.com>
> > Reviewed-by: Sergey Ulanov <sergeyu@chromium.org>
> > Commit-Queue: Sergey Ulanov <sergeyu@chromium.org>
> > Cr-Commit-Position: refs/heads/master@{#884796}
>
> Change-Id: I4bb812fa3ddbfba0450574edf1e4b8e8d36c01eb
> No-Presubmit: true
> No-Tree-Checks: true
> No-Try: true
> Reviewed-on: https://chromium-review.googlesource.com/c/chromium/src/+/2909213
> Bot-Commit: Rubber Stamper <rubber-stamper@appspot.gserviceaccount.com>
> Commit-Queue: Tim Sergeant <tsergeant@chromium.org>
> Owners-Override: Tim Sergeant <tsergeant@chromium.org>
> Reviewed-by: Takuto Ikuta <tikuta@chromium.org>
> Cr-Commit-Position: refs/heads/master@{#884891}

Change-Id: I5246afcacdf289da798240c60fafd530b8ef60ae
Reviewed-on: https://chromium-review.googlesource.com/c/chromium/src/+/2908796
Auto-Submit: Takuto Ikuta <tikuta@chromium.org>
Reviewed-by: Nico Weber <thakis@chromium.org>
Reviewed-by: Dirk Pranke <dpranke@google.com>
Commit-Queue: Takuto Ikuta <tikuta@chromium.org>
Cr-Commit-Position: refs/heads/master@{#885449}
This commit is contained in:
Takuto Ikuta
2021-05-21 10:26:36 +00:00
committed by Chromium LUCI CQ
parent 1929be69d7
commit cbc8a0bf45
7 changed files with 48 additions and 49 deletions

@ -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

@ -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 python3.
return base::FilePath(FILE_PATH_LITERAL("python3"));
}
const base::FilePath kTestDataPath = base::FilePath(

@ -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" ]

@ -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):

@ -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 array
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:

@ -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)

@ -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 @@ _PRELOADEDDATA = _descriptor.Descriptor(
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)