Skip to content

Commit

Permalink
Finalized reformat all python code in third_party/blink/renderer for …
Browse files Browse the repository at this point in the history
…PEP8

- created one root .style.yapf file for third_party/blink/renderer
- reformat *.py files in third_party/blink/renderer

Bug: 1051750
Change-Id: I0379ae76ca8d570baaff1e0527641b171b3cdf17
No-Presubmit: True
Reviewed-on: https://chromium-review.googlesource.com/c/chromium/src/+/2105303
Commit-Queue: Kent Tamura <tkent@chromium.org>
Reviewed-by: Kent Tamura <tkent@chromium.org>
Cr-Commit-Position: refs/heads/master@{#753055}
  • Loading branch information
Igor Makarov authored and Commit Bot committed Mar 24, 2020
1 parent 65c3ac9 commit b74afa9
Show file tree
Hide file tree
Showing 35 changed files with 626 additions and 449 deletions.
File renamed without changes.
2 changes: 0 additions & 2 deletions third_party/blink/renderer/build/scripts/.style.yapf

This file was deleted.

Original file line number Diff line number Diff line change
Expand Up @@ -13,8 +13,8 @@ def _RunBindingsTests(input_api, output_api):
print('Running ' + cmd_name)
else:
cmd.append('--suppress-diff')
test_cmd = input_api.Command(name=cmd_name, cmd=cmd,
kwargs={}, message=output_api.PresubmitError)
test_cmd = input_api.Command(
name=cmd_name, cmd=cmd, kwargs={}, message=output_api.PresubmitError)
return input_api.RunTests([test_cmd])


Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -66,7 +66,9 @@
'XR',
]

_SPECIAL_TOKENS_WITH_NUMBERS = [token for token in SPECIAL_TOKENS if re.search(r'[0-9]', token)]
_SPECIAL_TOKENS_WITH_NUMBERS = [
token for token in SPECIAL_TOKENS if re.search(r'[0-9]', token)
]

# Applying _TOKEN_PATTERNS repeatedly should capture any sequence of a-z, A-Z,
# 0-9.
Expand All @@ -80,7 +82,8 @@
'[0-9]+',
]

_TOKEN_RE = re.compile(r'(' + '|'.join(SPECIAL_TOKENS + _TOKEN_PATTERNS) + r')')
_TOKEN_RE = re.compile(r'(' + '|'.join(SPECIAL_TOKENS + _TOKEN_PATTERNS) +
r')')


def tokenize_name(name):
Expand All @@ -103,7 +106,8 @@ def tokenize_name(name):
# In case |name| is written in lowerCamelCase, we try to match special
# tokens that contains numbers ignoring cases only at the first step.
tokens = []
match = re.search(r'^(' + '|'.join(_SPECIAL_TOKENS_WITH_NUMBERS) + r')', name, re.IGNORECASE)
match = re.search(r'^(' + '|'.join(_SPECIAL_TOKENS_WITH_NUMBERS) + r')',
name, re.IGNORECASE)
if match:
tokens.append(match.group(0))
name = name[match.end(0):]
Expand Down Expand Up @@ -176,7 +180,8 @@ def to_lower_camel_case(self):
"""
if not self.tokens:
return ''
return self.tokens[0].lower() + ''.join([token[0].upper() + token[1:] for token in self.tokens[1:]])
return self.tokens[0].lower() + ''.join(
[token[0].upper() + token[1:] for token in self.tokens[1:]])

def to_macro_case(self):
"""Macro case is the macro name style per Google C++ Style Guide:
Expand Down

Large diffs are not rendered by default.

70 changes: 37 additions & 33 deletions third_party/blink/renderer/build/scripts/core/css/css_properties.py
Original file line number Diff line number Diff line change
Expand Up @@ -10,16 +10,10 @@
from name_utilities import enum_key_for_css_property, id_for_css_property
from name_utilities import enum_key_for_css_property_alias, id_for_css_property_alias


# These values are converted using CSSPrimitiveValue in the setter function,
# if applicable.
PRIMITIVE_TYPES = [
'short',
'unsigned short',
'int',
'unsigned int',
'unsigned',
'float',
'short', 'unsigned short', 'int', 'unsigned int', 'unsigned', 'float',
'LineClampValue'
]

Expand Down Expand Up @@ -104,7 +98,8 @@ def __init__(self, file_paths):
for feature in origin_trials_writer.origin_trial_features:
origin_trial_features[str(feature['name'])] = True

self.add_properties(css_properties_file.name_dictionaries, origin_trial_features)
self.add_properties(css_properties_file.name_dictionaries,
origin_trial_features)

assert self._first_enum_value + len(self._properties_by_id) < \
self._alias_offset, \
Expand All @@ -117,8 +112,7 @@ def __init__(self, file_paths):
self._extra_fields = []
for i in range(3, len(file_paths)):
fields = json5_generator.Json5File.load_from_files(
[file_paths[i]],
default_parameters=self._default_parameters)
[file_paths[i]], default_parameters=self._default_parameters)
self._extra_fields.extend(fields.name_dictionaries)
for field in self._extra_fields:
self.expand_parameters(field)
Expand All @@ -134,12 +128,15 @@ def add_properties(self, properties, origin_trial_features):
self.expand_surrogate(property_)

self._aliases = [
property_ for property_ in properties if property_['alias_for']]
property_ for property_ in properties if property_['alias_for']
]
self._shorthands = [
property_ for property_ in properties if property_['longhands']]
property_ for property_ in properties if property_['longhands']
]
self._longhands = [
property_ for property_ in properties if (
not property_['alias_for'] and not property_['longhands'])]
property_ for property_ in properties
if (not property_['alias_for'] and not property_['longhands'])
]

# Sort the properties by priority, then alphabetically. Ensure that
# the resulting order is deterministic.
Expand Down Expand Up @@ -215,14 +212,15 @@ def expand_aliases(self):
"Property '{}' is an alias with a runtime_flag, "\
"but runtime flags do not currently work for aliases.".format(
alias['name'])
aliased_property = self._properties_by_id[
id_for_css_property(alias['alias_for'])]
aliased_property = self._properties_by_id[id_for_css_property(
alias['alias_for'])]
aliased_property.setdefault('aliases', [])
aliased_property['aliases'].append(alias['name'].original)
updated_alias = aliased_property.copy()
updated_alias['name'] = alias['name']
updated_alias['alias_for'] = alias['alias_for']
updated_alias['aliased_property'] = aliased_property['name'].to_upper_camel_case()
updated_alias['aliased_property'] = aliased_property[
'name'].to_upper_camel_case()
updated_alias['property_id'] = id_for_css_property_alias(
alias['name'])
updated_alias['enum_key'] = enum_key_for_css_property_alias(
Expand Down Expand Up @@ -256,32 +254,35 @@ def set_if_none(property_, key, value):
set_if_none(property_, 'name_for_methods', method_name)
set_if_none(property_, 'type_name', 'E' + method_name)
set_if_none(
property_,
'getter',
method_name if simple_type_name != method_name else 'Get' + method_name)
property_, 'getter', method_name
if simple_type_name != method_name else 'Get' + method_name)
set_if_none(property_, 'setter', 'Set' + method_name)
if property_['inherited']:
property_['is_inherited_setter'] = 'Set' + method_name + 'IsInherited'
property_['is_animation_property'] = property_['priority'] == 'Animation'
property_['is_inherited_setter'] = (
'Set' + method_name + 'IsInherited')
property_['is_animation_property'] = (
property_['priority'] == 'Animation')

# Figure out whether this property should have style builders at all.
# E.g. shorthands do not get style builders.
property_['style_builder_declare'] = (property_['is_property'] and
not property_['longhands'])
property_['style_builder_declare'] = (property_['is_property']
and not property_['longhands'])

# Figure out whether we should generate style builder implementations.
for x in ['initial', 'inherit', 'value']:
suppressed = x in property_['style_builder_custom_functions']
declared = property_['style_builder_declare']
property_['style_builder_generate_%s' % x] = declared and not suppressed
property_['style_builder_generate_%s' % x] = (declared
and not suppressed)

# Expand StyleBuilderConverter params where necessary.
if property_['type_name'] in PRIMITIVE_TYPES:
set_if_none(property_, 'converter', 'CSSPrimitiveValue')
else:
set_if_none(property_, 'converter', 'CSSIdentifierValue')

assert not property_['alias_for'], 'Use expand_aliases to expand aliases'
assert not property_['alias_for'], \
'Use expand_aliases to expand aliases'
if not property_['longhands']:
property_['superclass'] = 'Longhand'
property_['namespace_group'] = 'Longhand'
Expand All @@ -294,13 +295,13 @@ def set_if_none(property_, key, value):
self._field_alias_expander.expand_field_alias(property_)

type_name = property_['type_name']
if (property_['field_template'] == 'keyword' or
property_['field_template'] == 'multi_keyword'):
if (property_['field_template'] == 'keyword'
or property_['field_template'] == 'multi_keyword'):
default_value = (type_name + '::' + NameStyleConverter(
property_['default_value']).to_enum_value())
elif (property_['field_template'] == 'external' or
property_['field_template'] == 'primitive' or
property_['field_template'] == 'pointer'):
elif (property_['field_template'] == 'external'
or property_['field_template'] == 'primitive'
or property_['field_template'] == 'pointer'):
default_value = property_['default_value']
else:
assert property_['field_template'] == 'monotonic_flag', \
Expand Down Expand Up @@ -329,7 +330,8 @@ def set_if_none(property_, key, value):
assert 'resolver' in options, 'resolver option is required'
assert 'physical_group' in options, 'physical_group option is required'
options['resolver_name'] = NameStyleConverter(options['resolver'])
options['physical_group_name'] = NameStyleConverter(options['physical_group'])
options['physical_group_name'] = NameStyleConverter(
options['physical_group'])

@property
def default_parameters(self):
Expand All @@ -353,7 +355,9 @@ def longhands(self):

@property
def longhands_including_aliases(self):
return self._longhands + [x for x in self._aliases if not x['longhands']]
return self._longhands + [
x for x in self._aliases if not x['longhands']
]

@property
def properties_by_id(self):
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -13,10 +13,12 @@ class FieldAliasExpander(object):
should point to core/css/computed_style_field_aliases.json5) and uses that to
inform which fields in a given property should be set.
"""

def __init__(self, file_path):
loaded_file = json5_generator.Json5File.load_from_files([file_path])
self._field_aliases = dict([(alias["name"], alias)
for alias in loaded_file.name_dictionaries])
self._field_aliases = dict([
(alias["name"], alias) for alias in loaded_file.name_dictionaries
])

def expand_field_alias(self, property_):
"""
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -12,13 +12,17 @@ class UnitTrieWriter(json5_generator.Writer):
def __init__(self, json5_file_paths, output_dir):
super(UnitTrieWriter, self).__init__(json5_file_paths, output_dir)

self._units = {entry['name'].original: entry['unit_type'] for entry in self.json5_file.name_dictionaries}
self._units = {
entry['name'].original: entry['unit_type']
for entry in self.json5_file.name_dictionaries
}

self._outputs = {
'css_primitive_value_unit_trie.cc': self.generate_implementation
}

@template_expander.use_jinja('core/css/templates/css_primitive_value_unit_trie.cc.tmpl')
@template_expander.use_jinja(
'core/css/templates/css_primitive_value_unit_trie.cc.tmpl')
def generate_implementation(self):
return {
'input_files': self._input_files,
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -11,7 +11,8 @@ class CSSPropertyNamesWriter(json5_generator.Writer):
file_basename = "css_property_names"

def __init__(self, json5_file_path, output_dir):
super(CSSPropertyNamesWriter, self).__init__(json5_file_path, output_dir)
super(CSSPropertyNamesWriter, self).__init__(json5_file_path,
output_dir)
self._outputs = {
(self.file_basename + ".h"): self.generate_header,
(self.file_basename + ".cc"): self.generate_implementation,
Expand All @@ -24,32 +25,40 @@ def _enum_declaration(self, property_):
def _array_item(self, property_):
return " CSSPropertyID::%(enum_key)s," % property_

@template_expander.use_jinja('core/css/templates/css_property_names.h.tmpl')
@template_expander.use_jinja(
'core/css/templates/css_property_names.h.tmpl')
def generate_header(self):
return {
'alias_offset': self._css_properties.alias_offset,
'class_name': self.class_name,
'property_enums': "\n".join(map(
self._enum_declaration,
self._css_properties.properties_including_aliases)),
'property_aliases': "\n".join(
map(self._array_item, self._css_properties.aliases)),
'first_property_id': self._css_properties.first_property_id,
'alias_offset':
self._css_properties.alias_offset,
'class_name':
self.class_name,
'property_enums':
"\n".join(
map(self._enum_declaration,
self._css_properties.properties_including_aliases)),
'property_aliases':
"\n".join(map(self._array_item, self._css_properties.aliases)),
'first_property_id':
self._css_properties.first_property_id,
'properties_count':
len(self._css_properties.properties_including_aliases),
'last_property_id': self._css_properties.last_property_id,
len(self._css_properties.properties_including_aliases),
'last_property_id':
self._css_properties.last_property_id,
'last_unresolved_property_id':
self._css_properties.last_unresolved_property_id,
self._css_properties.last_unresolved_property_id,
'max_name_length':
max(map(len, self._css_properties.properties_by_id)),
max(map(len, self._css_properties.properties_by_id)),
}

@gperf.use_jinja_gperf_template('core/css/templates/css_property_names.cc.tmpl',
['-Q', 'CSSPropStringPool'])
@gperf.use_jinja_gperf_template(
'core/css/templates/css_property_names.cc.tmpl',
['-Q', 'CSSPropStringPool'])
def generate_implementation(self):
enum_value_to_name = {}
for property_ in self._css_properties.properties_including_aliases:
enum_value_to_name[property_['enum_value']] = property_['name'].original
enum_value_to_name[property_['enum_value']] = \
property_['name'].original
property_offsets = []
property_names = []
current_offset = 0
Expand All @@ -64,23 +73,30 @@ def generate_implementation(self):
css_name_and_enum_pairs = [
(property_['name'].original,
'static_cast<int>(CSSPropertyID::' + property_['enum_key'] + ')')
for property_ in self._css_properties.properties_including_aliases]
for property_ in self._css_properties.properties_including_aliases
]

property_keys = [
property_['enum_key']
for property_ in self._css_properties.properties_including_aliases
]

return {
'class_name': 'CSSPropertyNames',
'file_basename': self.file_basename,
'property_keys': property_keys,
'property_names': property_names,
'property_offsets': property_offsets,
'class_name':
'CSSPropertyNames',
'file_basename':
self.file_basename,
'property_keys':
property_keys,
'property_names':
property_names,
'property_offsets':
property_offsets,
'property_to_enum_map':
'\n'.join('%s, %s' % property_
for property_ in css_name_and_enum_pairs),
'gperf_path': self.gperf_path,
'\n'.join(
'%s, %s' % property_ for property_ in css_name_and_enum_pairs),
'gperf_path':
self.gperf_path,
}


Expand Down
Loading

0 comments on commit b74afa9

Please sign in to comment.