Commit 324dd225 authored by Igor Makarov's avatar Igor Makarov Committed by Commit Bot

Reformat python code in third_party/blink/tools/blinkpy/presubmit for PEP8

- added .style.yapf file
- reformat *.py files

Bug: 1051750
Change-Id: Id46a74411f7053437297e6857530aaa5f351efca
Reviewed-on: https://chromium-review.googlesource.com/c/chromium/src/+/2135687Reviewed-by: default avatarKent Tamura <tkent@chromium.org>
Commit-Queue: Kent Tamura <tkent@chromium.org>
Cr-Commit-Position: refs/heads/master@{#758446}
parent 378b7b0f
......@@ -2,7 +2,6 @@
# 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.
"""Utilities for checking for disallowed usage of non-Blink declarations.
The scanner assumes that usage of non-Blink code is always namespace qualified.
......@@ -449,11 +448,13 @@ _CONFIG = [
'base::(scoped_nsobject|ScopedCFTypeRef)',
],
'disallowed': [
('base::Bind(|Once|Repeating)', 'Use WTF::Bind or WTF::BindRepeating.'),
('base::Bind(|Once|Repeating)',
'Use WTF::Bind or WTF::BindRepeating.'),
('std::(deque|map|multimap|set|vector|unordered_set|unordered_map)',
'Use WTF containers like WTF::Deque, WTF::HashMap, WTF::HashSet or WTF::Vector instead of the banned std containers. '
'However, it is fine to use std containers at the boundary layer between Blink and Chromium. '
'If you are in this case, you can use --bypass-hooks option to avoid the presubmit check when uploading your CL.'),
'If you are in this case, you can use --bypass-hooks option to avoid the presubmit check when uploading your CL.'
),
# network::mojom::Foo is allowed to use as non-blink mojom type.
('(|::)(?!network::)(\w+::)?mojom::(?!blink).+',
'Using non-blink mojom types, consider using "::mojom::blink::Foo" instead of "::mojom::Foo" unless you have clear reasons not to do so',
......@@ -465,7 +466,8 @@ _CONFIG = [
'allowed': ['gin::.+'],
},
{
'paths': ['third_party/blink/renderer/bindings/core/v8/script_streamer.cc'],
'paths':
['third_party/blink/renderer/bindings/core/v8/script_streamer.cc'],
'allowed': [
# For the script streaming to be able to block when reading from a
# mojo datapipe.
......@@ -475,20 +477,25 @@ _CONFIG = [
],
},
{
'paths': ['third_party/blink/renderer/bindings/core/v8/v8_gc_for_context_dispose.cc'],
'paths': [
'third_party/blink/renderer/bindings/core/v8/v8_gc_for_context_dispose.cc'
],
'allowed': [
# For memory reduction histogram.
'base::ProcessMetrics',
],
},
{
'paths': ['third_party/blink/renderer/controller/oom_intervention_impl.cc'],
'paths':
['third_party/blink/renderer/controller/oom_intervention_impl.cc'],
'allowed': [
'base::BindOnce',
],
},
{
'paths': ['third_party/blink/renderer/controller/user_level_memory_pressure_signal_generator.cc'],
'paths': [
'third_party/blink/renderer/controller/user_level_memory_pressure_signal_generator.cc'
],
'allowed': [
'base::MemoryPressureListener',
],
......@@ -500,9 +507,11 @@ _CONFIG = [
],
},
{
'paths': ['third_party/blink/renderer/core/animation_frame',
'third_party/blink/renderer/core/offscreencanvas',
'third_party/blink/renderer/core/html/canvas'],
'paths': [
'third_party/blink/renderer/core/animation_frame',
'third_party/blink/renderer/core/offscreencanvas',
'third_party/blink/renderer/core/html/canvas'
],
'allowed': [
'viz::BeginFrameArgs',
],
......@@ -532,27 +541,33 @@ _CONFIG = [
],
},
{
'paths': ['third_party/blink/renderer/core/fetch/data_consumer_handle_test_util.cc'],
'paths': [
'third_party/blink/renderer/core/fetch/data_consumer_handle_test_util.cc'
],
'allowed': [
# The existing code already contains gin::IsolateHolder.
'gin::IsolateHolder',
],
},
{
'paths': ['third_party/blink/renderer/core/frame/web_frame_widget_base.cc'],
'paths':
['third_party/blink/renderer/core/frame/web_frame_widget_base.cc'],
'allowed': [
'cc::SwapPromise',
'viz::CompositorFrameMetadata',
],
},
{
'paths': ['third_party/blink/renderer/core/fileapi/file_reader_loader.cc'],
'paths':
['third_party/blink/renderer/core/fileapi/file_reader_loader.cc'],
'allowed': [
'net::ERR_FILE_NOT_FOUND',
],
},
{
'paths': ['third_party/blink/renderer/core/loader/alternate_signed_exchange_resource_info.cc'],
'paths': [
'third_party/blink/renderer/core/loader/alternate_signed_exchange_resource_info.cc'
],
'allowed': [
# Used by WebPackageRequestMatcher in //third_party/blink/common.
'net::HttpRequestHeaders',
......@@ -593,7 +608,9 @@ _CONFIG = [
],
},
{
'paths': ['third_party/blink/renderer/core/inspector/inspector_memory_agent.cc'],
'paths': [
'third_party/blink/renderer/core/inspector/inspector_memory_agent.cc'
],
'allowed': [
'base::ModuleCache',
'base::PoissonAllocationSampler',
......@@ -601,7 +618,9 @@ _CONFIG = [
],
},
{
'paths': ['third_party/blink/renderer/core/inspector/inspector_overlay_agent.cc'],
'paths': [
'third_party/blink/renderer/core/inspector/inspector_overlay_agent.cc'
],
'allowed': [
# cc painting types.
'cc::ContentLayerClient',
......@@ -610,7 +629,8 @@ _CONFIG = [
],
},
{
'paths': ['third_party/blink/renderer/core/inspector/locale_controller.cc'],
'paths':
['third_party/blink/renderer/core/inspector/locale_controller.cc'],
'allowed': [
'base::i18n::SetICUDefaultLocale',
],
......@@ -627,13 +647,16 @@ _CONFIG = [
],
},
{
'paths': ['third_party/blink/renderer/core/inspector/inspector_performance_agent.cc'],
'paths': [
'third_party/blink/renderer/core/inspector/inspector_performance_agent.cc'
],
'allowed': [
'base::subtle::TimeTicksNowIgnoringOverride',
],
},
{
'paths': ['third_party/blink/renderer/core/scroll/scrollbar_theme_mac.mm'],
'paths':
['third_party/blink/renderer/core/scroll/scrollbar_theme_mac.mm'],
'allowed': [
'gfx::CocoaScrollbarPainter',
],
......@@ -1009,15 +1032,19 @@ _CONFIG = [
],
},
{
'paths': ['third_party/blink/renderer/core/fetch/fetch_request_data.cc'],
'paths':
['third_party/blink/renderer/core/fetch/fetch_request_data.cc'],
'allowed': ['net::RequestPriority'],
},
{
'paths': ['third_party/blink/renderer/core/frame/local_frame_view.cc'],
'allowed': ['cc::frame_viewer_instrumentation::IsTracingLayerTreeSnapshots'],
'allowed':
['cc::frame_viewer_instrumentation::IsTracingLayerTreeSnapshots'],
},
{
'paths': ['third_party/blink/renderer/modules/webaudio/audio_worklet_thread.cc'],
'paths': [
'third_party/blink/renderer/modules/webaudio/audio_worklet_thread.cc'
],
'allowed': ['base::ThreadPriority'],
},
{
......@@ -1058,7 +1085,8 @@ def _precompile_config():
else:
match, advice, warning = entry
match_list.append(match)
advice_list.append((compile_regexp(match, False), advice, warning == 'Warning'))
advice_list.append((compile_regexp(match, False), advice,
warning == 'Warning'))
else:
# Just a string
match_list.append(entry)
......@@ -1068,10 +1096,14 @@ def _precompile_config():
for raw_entry in _CONFIG:
disallowed, advice = compile_disallowed(raw_entry.get('disallowed'))
compiled_config.append({
'paths': raw_entry['paths'],
'allowed': compile_regexp(raw_entry.get('allowed')),
'disallowed': disallowed,
'advice': advice,
'paths':
raw_entry['paths'],
'allowed':
compile_regexp(raw_entry.get('allowed')),
'disallowed':
disallowed,
'advice':
advice,
})
return compiled_config
......@@ -1133,6 +1165,7 @@ def _find_advice_for_identifier(entries, identifier):
class BadIdentifier(object):
"""Represents a single instance of a bad identifier."""
def __init__(self, identifier, line, advice=None, warning=False):
self.identifier = identifier
self.line = line
......@@ -1155,13 +1188,10 @@ def check(path, contents):
path = path.replace('\\', '/')
basename, ext = os.path.splitext(path)
# Only check code. Ignore tests and fuzzers.
if (ext not in ('.cc', '.cpp', '.h', '.mm')
or path.find('/testing/') >= 0
or path.find('/tests/') >= 0
or basename.endswith('_test')
if (ext not in ('.cc', '.cpp', '.h', '.mm') or path.find('/testing/') >= 0
or path.find('/tests/') >= 0 or basename.endswith('_test')
or basename.endswith('_test_helpers')
or basename.endswith('_unittest')
or basename.endswith('_fuzzer')):
or basename.endswith('_unittest') or basename.endswith('_fuzzer')):
return results
entries = _find_matching_entries(path)
if not entries:
......@@ -1174,7 +1204,8 @@ def check(path, contents):
if match:
identifier = match.group(0)
if not _check_entries_for_identifier(entries, identifier):
advice, warning = _find_advice_for_identifier(entries, identifier)
advice, warning = _find_advice_for_identifier(
entries, identifier)
results.append(
BadIdentifier(identifier, line_number, advice, warning))
return results
......@@ -1185,13 +1216,13 @@ def main():
try:
with open(path, 'r') as f:
contents = f.read()
disallowed_identifiers = check(path, [
(i + 1, l) for i, l in
enumerate(contents.splitlines())])
disallowed_identifiers = check(
path,
[(i + 1, l) for i, l in enumerate(contents.splitlines())])
if disallowed_identifiers:
print '%s uses disallowed identifiers:' % path
for i in disallowed_identifiers:
print (i.line, i.identifier, i.advice)
print(i.line, i.identifier, i.advice)
except IOError as e:
print 'could not open %s: %s' % (path, e)
......
......@@ -31,19 +31,42 @@ class TestAuditNonBlinkUsageTest(unittest.TestCase):
for entry in audit_non_blink_usage._COMPILED_CONFIG:
if entry['paths'] == ['third_party/blink/renderer/']:
check_list = [
{'type': 'url::mojom::Origin', 'allowed': False},
{'type': '::media::mojom::InterfaceFactory', 'allowed': False},
{'type': 'Hogenetwork::mojom::URLLoaderFactory', 'allowed': False},
{'type': 'url::mojom::blink::Origin', 'allowed': True},
{'type': '::media::mojom::blink::InterfaceFactory', 'allowed': True},
{'type': 'network::mojom::URLLoaderFactory', 'allowed': True},
{'type': '::network::mojom::URLLoaderFactory', 'allowed': True},
{
'type': 'url::mojom::Origin',
'allowed': False
},
{
'type': '::media::mojom::InterfaceFactory',
'allowed': False
},
{
'type': 'Hogenetwork::mojom::URLLoaderFactory',
'allowed': False
},
{
'type': 'url::mojom::blink::Origin',
'allowed': True
},
{
'type': '::media::mojom::blink::InterfaceFactory',
'allowed': True
},
{
'type': 'network::mojom::URLLoaderFactory',
'allowed': True
},
{
'type': '::network::mojom::URLLoaderFactory',
'allowed': True
},
]
for item in check_list:
if item['allowed']:
self.assertIsNone(re.match(entry['disallowed'], item['type']))
self.assertIsNone(
re.match(entry['disallowed'], item['type']))
elif not item['allowed']:
self.assertIsNotNone(re.match(entry['disallowed'], item['type']))
self.assertIsNotNone(
re.match(entry['disallowed'], item['type']))
if __name__ == '__main__':
......
Markdown is supported
0%
or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment