diff --git a/components/style/counter_style/update_predefined.py b/components/style/counter_style/update_predefined.py index 2820ccaea68..1523958ff3e 100755 --- a/components/style/counter_style/update_predefined.py +++ b/components/style/counter_style/update_predefined.py @@ -17,16 +17,18 @@ def main(filename): or 'data-dfn-for=""' in line ] with open(filename, "wb") as f: - f.write("""\ + f.write( + """\ /* This Source Code Form is subject to the terms of the Mozilla Public * License, v. 2.0. If a copy of the MPL was not distributed with this * file, You can obtain one at https://mozilla.org/MPL/2.0/. */ predefined! { -""") +""" + ) for name in names: f.write(' "%s",\n' % name) - f.write('}\n') + f.write("}\n") if __name__ == "__main__": diff --git a/components/style/gecko/regen_atoms.py b/components/style/gecko/regen_atoms.py index 5c59a5c566c..f05ddb8d644 100755 --- a/components/style/gecko/regen_atoms.py +++ b/components/style/gecko/regen_atoms.py @@ -10,21 +10,33 @@ import sys from io import BytesIO -GECKO_DIR = os.path.dirname(__file__.replace('\\', '/')) +GECKO_DIR = os.path.dirname(__file__.replace("\\", "/")) sys.path.insert(0, os.path.join(os.path.dirname(GECKO_DIR), "properties")) import build # Matches lines like `GK_ATOM(foo, "foo", 0x12345678, true, nsStaticAtom, PseudoElementAtom)`. -PATTERN = re.compile('^GK_ATOM\(([^,]*),[^"]*"([^"]*)",\s*(0x[0-9a-f]+),\s*[^,]*,\s*([^,]*),\s*([^)]*)\)', - re.MULTILINE) +PATTERN = re.compile( + '^GK_ATOM\(([^,]*),[^"]*"([^"]*)",\s*(0x[0-9a-f]+),\s*[^,]*,\s*([^,]*),\s*([^)]*)\)', + re.MULTILINE, +) FILE = "include/nsGkAtomList.h" def map_atom(ident): - if ident in {"box", "loop", "match", "mod", "ref", - "self", "type", "use", "where", "in"}: + if ident in { + "box", + "loop", + "match", + "mod", + "ref", + "self", + "type", + "use", + "where", + "in", + }: return ident + "_" return ident @@ -42,7 +54,11 @@ class Atom: # or "InheritingAnonBox". self.atom_type = atom_type - if self.is_pseudo_element() or self.is_anon_box() or self.is_tree_pseudo_element(): + if ( + self.is_pseudo_element() + or self.is_anon_box() + or self.is_tree_pseudo_element() + ): self.pseudo_ident = (ident.split("_", 1))[1] if self.is_anon_box(): @@ -82,34 +98,42 @@ def collect_atoms(objdir): with open(path) as f: content = f.read() for result in PATTERN.finditer(content): - atoms.append(Atom(result.group(1), result.group(2), result.group(3), - result.group(4), result.group(5))) + atoms.append( + Atom( + result.group(1), + result.group(2), + result.group(3), + result.group(4), + result.group(5), + ) + ) return atoms class FileAvoidWrite(BytesIO): """File-like object that buffers output and only writes if content changed.""" + def __init__(self, filename): BytesIO.__init__(self) self.name = filename def write(self, buf): if isinstance(buf, str): - buf = buf.encode('utf-8') + buf = buf.encode("utf-8") BytesIO.write(self, buf) def close(self): buf = self.getvalue() BytesIO.close(self) try: - with open(self.name, 'rb') as f: + with open(self.name, "rb") as f: old_content = f.read() if old_content == buf: print("{} is not changed, skip".format(self.name)) return except IOError: pass - with open(self.name, 'wb') as f: + with open(self.name, "wb") as f: f.write(buf) def __enter__(self): @@ -120,45 +144,57 @@ class FileAvoidWrite(BytesIO): self.close() -PRELUDE = ''' +PRELUDE = """ /* This Source Code Form is subject to the terms of the Mozilla Public * License, v. 2.0. If a copy of the MPL was not distributed with this * file, You can obtain one at https://mozilla.org/MPL/2.0/. */ // Autogenerated file created by components/style/gecko/regen_atoms.py. // DO NOT EDIT DIRECTLY -'''[1:] +"""[ + 1: +] -RULE_TEMPLATE = ''' +RULE_TEMPLATE = """ ("{atom}") => {{{{ #[allow(unsafe_code)] #[allow(unused_unsafe)] unsafe {{ $crate::string_cache::Atom::from_index_unchecked({index}) }} }}}}; -'''[1:] +"""[ + 1: +] -MACRO_TEMPLATE = ''' +MACRO_TEMPLATE = """ /// Returns a static atom by passing the literal string it represents. #[macro_export] macro_rules! atom {{ {body}\ }} -''' +""" + def write_atom_macro(atoms, file_name): with FileAvoidWrite(file_name) as f: f.write(PRELUDE) - macro_rules = [RULE_TEMPLATE.format(atom=atom.value, name=atom.ident, index=i) - for (i, atom) in enumerate(atoms)] - f.write(MACRO_TEMPLATE.format(body=''.join(macro_rules))) + macro_rules = [ + RULE_TEMPLATE.format(atom=atom.value, name=atom.ident, index=i) + for (i, atom) in enumerate(atoms) + ] + f.write(MACRO_TEMPLATE.format(body="".join(macro_rules))) def write_pseudo_elements(atoms, target_filename): pseudos = [] for atom in atoms: - if atom.type() == "nsCSSPseudoElementStaticAtom" or atom.type() == "nsCSSAnonBoxPseudoStaticAtom": + if ( + atom.type() == "nsCSSPseudoElementStaticAtom" + or atom.type() == "nsCSSAnonBoxPseudoStaticAtom" + ): pseudos.append(atom) - pseudo_definition_template = os.path.join(GECKO_DIR, "pseudo_element_definition.mako.rs") + pseudo_definition_template = os.path.join( + GECKO_DIR, "pseudo_element_definition.mako.rs" + ) print("cargo:rerun-if-changed={}".format(pseudo_definition_template)) contents = build.render(pseudo_definition_template, PSEUDOS=pseudos) diff --git a/components/style/properties/build.py b/components/style/properties/build.py index 92966ce1b2d..e74c9b9795f 100644 --- a/components/style/properties/build.py +++ b/components/style/properties/build.py @@ -7,7 +7,7 @@ import os.path import re import sys -BASE = os.path.dirname(__file__.replace('\\', '/')) +BASE = os.path.dirname(__file__.replace("\\", "/")) sys.path.insert(0, os.path.join(BASE, "Mako-1.1.2-py2.py3-none-any.whl")) sys.path.insert(0, BASE) # For importing `data.py` @@ -17,7 +17,7 @@ from mako.template import Template import data -RE_PYTHON_ADDR = re.compile(r'<.+? object at 0x[0-9a-fA-F]+>') +RE_PYTHON_ADDR = re.compile(r"<.+? object at 0x[0-9a-fA-F]+>") OUT_DIR = os.environ.get("OUT_DIR", "") @@ -48,15 +48,20 @@ STYLE_STRUCT_LIST = [ def main(): - usage = ("Usage: %s [ servo-2013 | servo-2020 | gecko ] [ style-crate | geckolib