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 @@ ...@@ -2,7 +2,6 @@
# Copyright 2017 The Chromium Authors. All rights reserved. # Copyright 2017 The Chromium Authors. All rights reserved.
# Use of this source code is governed by a BSD-style license that can be # Use of this source code is governed by a BSD-style license that can be
# found in the LICENSE file. # found in the LICENSE file.
"""Utilities for checking for disallowed usage of non-Blink declarations. """Utilities for checking for disallowed usage of non-Blink declarations.
The scanner assumes that usage of non-Blink code is always namespace qualified. The scanner assumes that usage of non-Blink code is always namespace qualified.
...@@ -449,11 +448,13 @@ _CONFIG = [ ...@@ -449,11 +448,13 @@ _CONFIG = [
'base::(scoped_nsobject|ScopedCFTypeRef)', 'base::(scoped_nsobject|ScopedCFTypeRef)',
], ],
'disallowed': [ '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)', ('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. ' '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. ' '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::mojom::Foo is allowed to use as non-blink mojom type.
('(|::)(?!network::)(\w+::)?mojom::(?!blink).+', ('(|::)(?!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', '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 = [ ...@@ -465,7 +466,8 @@ _CONFIG = [
'allowed': ['gin::.+'], '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': [ 'allowed': [
# For the script streaming to be able to block when reading from a # For the script streaming to be able to block when reading from a
# mojo datapipe. # mojo datapipe.
...@@ -475,20 +477,25 @@ _CONFIG = [ ...@@ -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': [ 'allowed': [
# For memory reduction histogram. # For memory reduction histogram.
'base::ProcessMetrics', 'base::ProcessMetrics',
], ],
}, },
{ {
'paths': ['third_party/blink/renderer/controller/oom_intervention_impl.cc'], 'paths':
['third_party/blink/renderer/controller/oom_intervention_impl.cc'],
'allowed': [ 'allowed': [
'base::BindOnce', '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': [ 'allowed': [
'base::MemoryPressureListener', 'base::MemoryPressureListener',
], ],
...@@ -500,9 +507,11 @@ _CONFIG = [ ...@@ -500,9 +507,11 @@ _CONFIG = [
], ],
}, },
{ {
'paths': ['third_party/blink/renderer/core/animation_frame', 'paths': [
'third_party/blink/renderer/core/animation_frame',
'third_party/blink/renderer/core/offscreencanvas', 'third_party/blink/renderer/core/offscreencanvas',
'third_party/blink/renderer/core/html/canvas'], 'third_party/blink/renderer/core/html/canvas'
],
'allowed': [ 'allowed': [
'viz::BeginFrameArgs', 'viz::BeginFrameArgs',
], ],
...@@ -532,27 +541,33 @@ _CONFIG = [ ...@@ -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': [ 'allowed': [
# The existing code already contains gin::IsolateHolder. # The existing code already contains gin::IsolateHolder.
'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': [ 'allowed': [
'cc::SwapPromise', 'cc::SwapPromise',
'viz::CompositorFrameMetadata', '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': [ 'allowed': [
'net::ERR_FILE_NOT_FOUND', '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': [ 'allowed': [
# Used by WebPackageRequestMatcher in //third_party/blink/common. # Used by WebPackageRequestMatcher in //third_party/blink/common.
'net::HttpRequestHeaders', 'net::HttpRequestHeaders',
...@@ -593,7 +608,9 @@ _CONFIG = [ ...@@ -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': [ 'allowed': [
'base::ModuleCache', 'base::ModuleCache',
'base::PoissonAllocationSampler', 'base::PoissonAllocationSampler',
...@@ -601,7 +618,9 @@ _CONFIG = [ ...@@ -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': [ 'allowed': [
# cc painting types. # cc painting types.
'cc::ContentLayerClient', 'cc::ContentLayerClient',
...@@ -610,7 +629,8 @@ _CONFIG = [ ...@@ -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': [ 'allowed': [
'base::i18n::SetICUDefaultLocale', 'base::i18n::SetICUDefaultLocale',
], ],
...@@ -627,13 +647,16 @@ _CONFIG = [ ...@@ -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': [ 'allowed': [
'base::subtle::TimeTicksNowIgnoringOverride', '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': [ 'allowed': [
'gfx::CocoaScrollbarPainter', 'gfx::CocoaScrollbarPainter',
], ],
...@@ -1009,15 +1032,19 @@ _CONFIG = [ ...@@ -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'], 'allowed': ['net::RequestPriority'],
}, },
{ {
'paths': ['third_party/blink/renderer/core/frame/local_frame_view.cc'], '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'], 'allowed': ['base::ThreadPriority'],
}, },
{ {
...@@ -1058,7 +1085,8 @@ def _precompile_config(): ...@@ -1058,7 +1085,8 @@ def _precompile_config():
else: else:
match, advice, warning = entry match, advice, warning = entry
match_list.append(match) 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: else:
# Just a string # Just a string
match_list.append(entry) match_list.append(entry)
...@@ -1068,10 +1096,14 @@ def _precompile_config(): ...@@ -1068,10 +1096,14 @@ def _precompile_config():
for raw_entry in _CONFIG: for raw_entry in _CONFIG:
disallowed, advice = compile_disallowed(raw_entry.get('disallowed')) disallowed, advice = compile_disallowed(raw_entry.get('disallowed'))
compiled_config.append({ compiled_config.append({
'paths': raw_entry['paths'], 'paths':
'allowed': compile_regexp(raw_entry.get('allowed')), raw_entry['paths'],
'disallowed': disallowed, 'allowed':
'advice': advice, compile_regexp(raw_entry.get('allowed')),
'disallowed':
disallowed,
'advice':
advice,
}) })
return compiled_config return compiled_config
...@@ -1133,6 +1165,7 @@ def _find_advice_for_identifier(entries, identifier): ...@@ -1133,6 +1165,7 @@ def _find_advice_for_identifier(entries, identifier):
class BadIdentifier(object): class BadIdentifier(object):
"""Represents a single instance of a bad identifier.""" """Represents a single instance of a bad identifier."""
def __init__(self, identifier, line, advice=None, warning=False): def __init__(self, identifier, line, advice=None, warning=False):
self.identifier = identifier self.identifier = identifier
self.line = line self.line = line
...@@ -1155,13 +1188,10 @@ def check(path, contents): ...@@ -1155,13 +1188,10 @@ def check(path, contents):
path = path.replace('\\', '/') path = path.replace('\\', '/')
basename, ext = os.path.splitext(path) basename, ext = os.path.splitext(path)
# Only check code. Ignore tests and fuzzers. # Only check code. Ignore tests and fuzzers.
if (ext not in ('.cc', '.cpp', '.h', '.mm') if (ext not in ('.cc', '.cpp', '.h', '.mm') or path.find('/testing/') >= 0
or path.find('/testing/') >= 0 or path.find('/tests/') >= 0 or basename.endswith('_test')
or path.find('/tests/') >= 0
or basename.endswith('_test')
or basename.endswith('_test_helpers') or basename.endswith('_test_helpers')
or basename.endswith('_unittest') or basename.endswith('_unittest') or basename.endswith('_fuzzer')):
or basename.endswith('_fuzzer')):
return results return results
entries = _find_matching_entries(path) entries = _find_matching_entries(path)
if not entries: if not entries:
...@@ -1174,7 +1204,8 @@ def check(path, contents): ...@@ -1174,7 +1204,8 @@ def check(path, contents):
if match: if match:
identifier = match.group(0) identifier = match.group(0)
if not _check_entries_for_identifier(entries, identifier): 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( results.append(
BadIdentifier(identifier, line_number, advice, warning)) BadIdentifier(identifier, line_number, advice, warning))
return results return results
...@@ -1185,13 +1216,13 @@ def main(): ...@@ -1185,13 +1216,13 @@ def main():
try: try:
with open(path, 'r') as f: with open(path, 'r') as f:
contents = f.read() contents = f.read()
disallowed_identifiers = check(path, [ disallowed_identifiers = check(
(i + 1, l) for i, l in path,
enumerate(contents.splitlines())]) [(i + 1, l) for i, l in enumerate(contents.splitlines())])
if disallowed_identifiers: if disallowed_identifiers:
print '%s uses disallowed identifiers:' % path print '%s uses disallowed identifiers:' % path
for i in disallowed_identifiers: for i in disallowed_identifiers:
print (i.line, i.identifier, i.advice) print(i.line, i.identifier, i.advice)
except IOError as e: except IOError as e:
print 'could not open %s: %s' % (path, e) print 'could not open %s: %s' % (path, e)
......
...@@ -31,19 +31,42 @@ class TestAuditNonBlinkUsageTest(unittest.TestCase): ...@@ -31,19 +31,42 @@ class TestAuditNonBlinkUsageTest(unittest.TestCase):
for entry in audit_non_blink_usage._COMPILED_CONFIG: for entry in audit_non_blink_usage._COMPILED_CONFIG:
if entry['paths'] == ['third_party/blink/renderer/']: if entry['paths'] == ['third_party/blink/renderer/']:
check_list = [ check_list = [
{'type': 'url::mojom::Origin', 'allowed': False}, {
{'type': '::media::mojom::InterfaceFactory', 'allowed': False}, 'type': 'url::mojom::Origin',
{'type': 'Hogenetwork::mojom::URLLoaderFactory', 'allowed': False}, 'allowed': False
{'type': 'url::mojom::blink::Origin', 'allowed': True}, },
{'type': '::media::mojom::blink::InterfaceFactory', 'allowed': True}, {
{'type': 'network::mojom::URLLoaderFactory', 'allowed': True}, 'type': '::media::mojom::InterfaceFactory',
{'type': '::network::mojom::URLLoaderFactory', 'allowed': True}, '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: for item in check_list:
if item['allowed']: if item['allowed']:
self.assertIsNone(re.match(entry['disallowed'], item['type'])) self.assertIsNone(
re.match(entry['disallowed'], item['type']))
elif not item['allowed']: elif not item['allowed']:
self.assertIsNotNone(re.match(entry['disallowed'], item['type'])) self.assertIsNotNone(
re.match(entry['disallowed'], item['type']))
if __name__ == '__main__': 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