Bug 1468273 - autopep8 on gfx/ r=ted draft
authorSylvestre Ledru <sledru@mozilla.com>
Sun, 10 Jun 2018 14:13:44 +0200
changeset 817272 33413a297adc1d980c56c17799ce04f73e40ad73
parent 817271 56062a63fa8c1eb577eedd5ea3b972f0f93ca740
child 817273 b0a1b5aa60e0c91cd83cec4bfffef219e70a261c
push id116007
push userbmo:sledru@mozilla.com
push dateThu, 12 Jul 2018 10:21:37 +0000
reviewersted
bugs1468273
milestone63.0a1
Bug 1468273 - autopep8 on gfx/ r=ted MozReview-Commit-ID: 8j8EU3E08GP
.flake8
gfx/gl/GLParseRegistryXML.py
gfx/layers/d3d11/genshaders.py
servo/components/style/counter_style/update_predefined.py
servo/components/style/gecko/regen_atoms.py
servo/components/style/properties/build.py
servo/components/style/properties/data.py
tools/lint/flake8.yml
--- a/.flake8
+++ b/.flake8
@@ -2,15 +2,19 @@
 # See http://pep8.readthedocs.io/en/latest/intro.html#configuration
 ignore = E121, E123, E126, E129, E133, E226, E241, E242, E704, W503, E402, E741
 max-line-length = 99
 exclude =
     browser/extensions/mortar/ppapi/,
     browser/moz.configure,
     build/moz.configure/*.configure,
     build/pymake/,
+    editor/libeditor/tests/browserscope/,
+    gfx/angle/,
+    gfx/harfbuzz,
+    glx/skia/,
     js/*.configure,
     memory/moz.configure,
     mobile/android/*.configure,
     node_modules,
     security/nss/,
     testing/mochitest/pywebsocket,
     tools/lint/test/files,
--- a/gfx/gl/GLParseRegistryXML.py
+++ b/gfx/gl/GLParseRegistryXML.py
@@ -29,26 +29,24 @@ import xml.etree.ElementTree
 
 ################################################################################
 # export management
 
 class GLConstHeader:
     def __init__(self, f):
         self.f = f
 
-
     def write(self, arg):
         if isinstance(arg, list):
             self.f.write('\n'.join(arg) + '\n')
         elif isinstance(arg, (int, long)):
             self.f.write('\n' * arg)
         else:
             self.f.write(str(arg) + '\n')
 
-
     def formatFileBegin(self):
         self.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 http://mozilla.org/MPL/2.0/. */',
             '',
             '#ifndef GLCONSTS_H_',
             '#define GLCONSTS_H_',
@@ -58,46 +56,42 @@ class GLConstHeader:
             ' * This is a file generated directly from the official OpenGL registry',
             ' * xml available http://www.opengl.org/registry/#specfiles.',
             ' *',
             ' * To generate this file, see tutorial in \'GLParseRegistryXML.py\'.',
             ' */',
             ''
         ])
 
-
     def formatLibBegin(self, lib):
         # lib would be 'GL', 'EGL', 'GLX' or 'WGL'
         self.write('// ' + lib)
 
-
     def formatLibConstant(self, lib, name, value):
         # lib would be 'GL', 'EGL', 'GLX' or 'WGL'
         # name is the name of the const (example: MAX_TEXTURE_SIZE)
         # value is the value of the const (example: 0xABCD)
 
         define = '#define LOCAL_' + lib + '_' + name
         whitespace = 60 - len(define)
-        
+
         if whitespace < 0:
             whitespace = whitespace % 8
-        
+
         self.write(define + ' ' * whitespace + ' ' + value)
 
-
     def formatLibEnd(self, lib):
         # lib would be 'GL', 'EGL', 'GLX' or 'WGL'
         self.write(2)
 
-
     def formatFileEnd(self):
         self.write([
-                    '',
-                    '#endif // GLCONSTS_H_'
-                   ])
+            '',
+            '#endif // GLCONSTS_H_'
+        ])
 
 
 ################################################################################
 # underground code
 
 def getScriptDir():
     return os.path.dirname(__file__) + '/'
 
@@ -127,17 +121,16 @@ class GLDatabase:
 
     def __init__(self):
         self.consts = {}
         self.libs = set(GLDatabase.LIBS)
         self.vendors = set(['EXT', 'ATI'])
         # there is no vendor="EXT" and vendor="ATI" in gl.xml,
         # so we manualy declare them
 
-
     def loadXML(self, path):
         xmlPath = getXMLDir() + path
 
         if not os.path.isfile(xmlPath):
             print 'missing file "' + xmlPath + '"'
             return False
 
         tree = xml.etree.ElementTree.parse(xmlPath)
@@ -174,19 +167,18 @@ class GLDatabase:
                 if not type:
                     # if no type specified, we get the namespace's default type
                     type = namespaceType
 
                 self.consts[lib + '_' + name] = GLConst(lib, name, value, type)
 
         return True
 
-
     def exportConsts(self, path):
-        with open(getScriptDir() + path,'w') as f:
+        with open(getScriptDir() + path, 'w') as f:
 
             headerFile = GLConstHeader(f)
             headerFile.formatFileBegin()
 
             constNames = self.consts.keys()
             constNames.sort()
 
             for lib in GLDatabase.LIBS:
--- a/gfx/layers/d3d11/genshaders.py
+++ b/gfx/layers/d3d11/genshaders.py
@@ -7,152 +7,165 @@ import locale
 import os
 import re
 import subprocess
 import sys
 import tempfile
 import yaml
 import buildconfig
 
+
 def shell_main():
-  parser = argparse.ArgumentParser()
-  parser.add_argument('-o', '--output', type=str, required=True,
-                      help='Output file')
-  parser.add_argument('manifest', type=str,
-                      help='Manifest source file')
-  args = parser.parse_args()
+    parser = argparse.ArgumentParser()
+    parser.add_argument('-o', '--output', type=str, required=True,
+                        help='Output file')
+    parser.add_argument('manifest', type=str,
+                        help='Manifest source file')
+    args = parser.parse_args()
 
-  with open(args.output, 'w') as out_file:
-    process_manifest(out_file, args.manifest)
+    with open(args.output, 'w') as out_file:
+        process_manifest(out_file, args.manifest)
+
 
 def main(output_fp, input_filename):
-  return process_manifest(output_fp, input_filename)
+    return process_manifest(output_fp, input_filename)
+
 
 HEADER = """// AUTOGENERATED - DO NOT EDIT
 namespace mozilla {
 namespace layers {
 
 struct ShaderBytes { const void* mData; size_t mLength; };
 """
 FOOTER = """
 } // namespace layers
 } // namespace mozilla"""
 
+
 def process_manifest(output_fp, manifest_filename):
-  with codecs.open(manifest_filename, 'r', 'UTF-8') as in_fp:
-    manifest = yaml.safe_load(in_fp)
-  shader_folder, _ = os.path.split(manifest_filename)
+    with codecs.open(manifest_filename, 'r', 'UTF-8') as in_fp:
+        manifest = yaml.safe_load(in_fp)
+    shader_folder, _ = os.path.split(manifest_filename)
 
-  output_fp.write(HEADER)
+    output_fp.write(HEADER)
 
-  deps = set()
-  for block in manifest:
-    if 'type' not in block:
-      raise Exception("Expected 'type' key with shader mode")
-    if 'file' not in block:
-      raise Exception("Expected 'file' key with shader file")
-    if 'shaders' not in block:
-      raise Exception("Expected 'shaders' key with shader name list")
+    deps = set()
+    for block in manifest:
+        if 'type' not in block:
+            raise Exception("Expected 'type' key with shader mode")
+        if 'file' not in block:
+            raise Exception("Expected 'file' key with shader file")
+        if 'shaders' not in block:
+            raise Exception("Expected 'shaders' key with shader name list")
 
-    shader_file = os.path.join(shader_folder, block['file'])
-    deps.add(shader_file)
+        shader_file = os.path.join(shader_folder, block['file'])
+        deps.add(shader_file)
 
-    shader_model = block['type']
-    for shader_name in block['shaders']:
-      new_deps = run_fxc(
-        shader_model = shader_model,
-        shader_file = shader_file,
-        shader_name = shader_name,
-        output_fp = output_fp)
-      deps |= new_deps
+        shader_model = block['type']
+        for shader_name in block['shaders']:
+            new_deps = run_fxc(
+                shader_model=shader_model,
+                shader_file=shader_file,
+                shader_name=shader_name,
+                output_fp=output_fp)
+            deps |= new_deps
 
-  output_fp.write(FOOTER)
-  return deps
+    output_fp.write(FOOTER)
+    return deps
+
 
 def run_fxc(shader_model,
             shader_file,
             shader_name,
             output_fp):
-  fxc_location = buildconfig.substs['FXC']
+    fxc_location = buildconfig.substs['FXC']
+
+    argv = [
+        fxc_location,
+        '-nologo',
+        '-T{0}'.format(shader_model),
+        shader_file,
+        '-E{0}'.format(shader_name),
+        '-Vn{0}'.format(shader_name),
+        '-Vi',
+    ]
+    if 'Linux' in buildconfig.substs['HOST_OS_ARCH']:
+        argv.insert(0, buildconfig.substs['WINE'])
+    if shader_model.startswith('vs_'):
+        argv += ['-DVERTEX_SHADER']
+    elif shader_model.startswith('ps_'):
+        argv += ['-DPIXEL_SHADER']
 
-  argv = [
-    fxc_location,
-    '-nologo',
-    '-T{0}'.format(shader_model),
-    shader_file,
-    '-E{0}'.format(shader_name),
-    '-Vn{0}'.format(shader_name),
-    '-Vi',
-  ]
-  if 'Linux' in buildconfig.substs['HOST_OS_ARCH']:
-    argv.insert(0, buildconfig.substs['WINE'])
-  if shader_model.startswith('vs_'):
-    argv += ['-DVERTEX_SHADER']
-  elif shader_model.startswith('ps_'):
-    argv += ['-DPIXEL_SHADER']
+    deps = None
+    with ScopedTempFilename() as temp_filename:
+        argv += ['-Fh{0}'.format(temp_filename)]
 
-  deps = None
-  with ScopedTempFilename() as temp_filename:
-    argv += ['-Fh{0}'.format(temp_filename)]
+        sys.stdout.write('{0}\n'.format(' '.join(argv)))
+        proc_stdout = subprocess.check_output(argv)
+        proc_stdout = decode_console_text(sys.stdout, proc_stdout)
+        deps = find_dependencies(proc_stdout)
+        assert 'fxc2' in fxc_location or len(deps) > 0
 
-    sys.stdout.write('{0}\n'.format(' '.join(argv)))
-    proc_stdout = subprocess.check_output(argv)
-    proc_stdout = decode_console_text(sys.stdout, proc_stdout)
-    deps = find_dependencies(proc_stdout)
-    assert 'fxc2' in fxc_location or len(deps) > 0
+        with open(temp_filename, 'r') as temp_fp:
+            output_fp.write(temp_fp.read())
 
-    with open(temp_filename, 'r') as temp_fp:
-      output_fp.write(temp_fp.read())
+    output_fp.write("ShaderBytes s{0} = {{ {0}, sizeof({0}) }};\n".format(
+        shader_name))
+    return deps
 
-  output_fp.write("ShaderBytes s{0} = {{ {0}, sizeof({0}) }};\n".format(
-    shader_name))
-  return deps
 
 def find_dependencies(fxc_output):
-  # Dependencies look like this:
-  #   Resolved to [<path>]
-  #
-  # Microsoft likes to change output strings based on the user's language, so
-  # instead of pattern matching on that string, we take everything in between
-  # brackets. We filter out potentially bogus strings later.
-  deps = set()
-  for line in fxc_output.split('\n'):
-    m = re.search(r"\[([^\]]+)\]", line)
-    if m is None:
-      continue
-    dep_path = m.group(1)
-    dep_path = os.path.normpath(dep_path)
-    if os.path.isfile(dep_path):
-      deps.add(dep_path)
-  return deps
+    # Dependencies look like this:
+    #   Resolved to [<path>]
+    #
+    # Microsoft likes to change output strings based on the user's language, so
+    # instead of pattern matching on that string, we take everything in between
+    # brackets. We filter out potentially bogus strings later.
+    deps = set()
+    for line in fxc_output.split('\n'):
+        m = re.search(r"\[([^\]]+)\]", line)
+        if m is None:
+            continue
+        dep_path = m.group(1)
+        dep_path = os.path.normpath(dep_path)
+        if os.path.isfile(dep_path):
+            deps.add(dep_path)
+    return deps
 
 # Python reads the raw bytes from stdout, so we need to try our best to
 # capture that as a valid Python string.
+
+
 def decode_console_text(pipe, text):
-  try:
-    if pipe.encoding:
-      return text.decode(pipe.encoding, 'replace')
-  except:
-    pass
-  try:
-    return text.decode(locale.getpreferredencoding(), 'replace')
-  except:
-    return text.decode('utf8', 'replace')
+    try:
+        if pipe.encoding:
+            return text.decode(pipe.encoding, 'replace')
+    except:
+        pass
+    try:
+        return text.decode(locale.getpreferredencoding(), 'replace')
+    except:
+        return text.decode('utf8', 'replace')
 
 # Allocate a temporary file name and delete it when done. We need an extra
 # wrapper for this since TemporaryNamedFile holds the file open.
+
+
 class ScopedTempFilename(object):
-  def __init__(self):
-    self.name = None
-  def __enter__(self):
-    with tempfile.NamedTemporaryFile(delete = False) as tmp:
-      self.name = tmp.name
-      return self.name
-  def __exit__(self, type, value, traceback):
-    if not self.name:
-      return
-    try:
-      os.unlink(self.name)
-    except:
-      pass
+    def __init__(self):
+        self.name = None
+
+    def __enter__(self):
+        with tempfile.NamedTemporaryFile(delete=False) as tmp:
+            self.name = tmp.name
+            return self.name
+
+    def __exit__(self, type, value, traceback):
+        if not self.name:
+            return
+        try:
+            os.unlink(self.name)
+        except:
+            pass
+
 
 if __name__ == '__main__':
-  shell_main()
+    shell_main()
--- a/servo/components/style/counter_style/update_predefined.py
+++ b/servo/components/style/counter_style/update_predefined.py
@@ -23,10 +23,11 @@ def main(filename):
  * file, You can obtain one at http://mozilla.org/MPL/2.0/. */
 
 predefined! {
 """)
         for name in names:
             f.write('    "%s",\n' % name)
         f.write('}\n')
 
+
 if __name__ == "__main__":
     main(os.path.join(os.path.dirname(__file__), "predefined.rs"))
--- a/servo/components/style/gecko/regen_atoms.py
+++ b/servo/components/style/gecko/regen_atoms.py
@@ -16,17 +16,17 @@ sys.path.insert(0, os.path.join(os.path.
 import build
 
 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 http://mozilla.org/MPL/2.0/. */
 
 /* Autogenerated file created by components/style/gecko/binding_tools/regen_atoms.py, DO NOT EDIT DIRECTLY */
-"""[1:]
+"""[1:]   # NOQA: E501
 
 
 def gnu_symbolify(source, ident):
     return "_ZN{}{}{}{}E".format(len(source.CLASS), source.CLASS, len(ident), ident)
 
 
 def msvc64_symbolify(source, ident):
     return "?{}@{}@@2PEAV{}@@EA".format(ident, source.CLASS, source.TYPE)
@@ -52,17 +52,17 @@ class CSSPseudoElementsAtomSource:
     FILE = "include/nsCSSPseudoElementList.h"
     CLASS = "nsCSSPseudoElements"
     # NB: nsICSSPseudoElement is effectively the same as a nsStaticAtom, but we need
     # this for MSVC name mangling.
     TYPE = "nsICSSPseudoElement"
 
 
 class CSSAnonBoxesAtomSource:
-    PATTERN = re.compile('^(CSS_ANON_BOX|CSS_NON_INHERITING_ANON_BOX|CSS_WRAPPER_ANON_BOX)\(([^,]*),[^"]*"([^"]*)"\)',
+    PATTERN = re.compile('^(CSS_ANON_BOX|CSS_NON_INHERITING_ANON_BOX|CSS_WRAPPER_ANON_BOX)\(([^,]*),[^"]*"([^"]*)"\)',  # NOQA: E501
                          re.MULTILINE)
     FILE = "include/nsCSSAnonBoxList.h"
     CLASS = "nsCSSAnonBoxes"
     TYPE = "nsICSSAnonBoxPseudo"
 
 
 SOURCES = [
     GkAtomSource,
--- a/servo/components/style/properties/build.py
+++ b/servo/components/style/properties/build.py
@@ -44,17 +44,18 @@ STYLE_STRUCT_LIST = [
     "text",
     "ui",
     "svg",
     "xul",
 ]
 
 
 def main():
-    usage = "Usage: %s [ servo | gecko ] [ style-crate | geckolib <template> | html ]" % sys.argv[0]
+    usage = ("Usage: %s [ servo | gecko ] [ style-crate | geckolib <template> | html ]" %
+             sys.argv[0])
     if len(sys.argv) < 3:
         abort(usage)
     product = sys.argv[1]
     output = sys.argv[2]
 
     if product not in ["servo", "gecko"] or output not in ["style-crate", "geckolib", "html"]:
         abort(usage)
 
@@ -117,17 +118,17 @@ def render(filename, **context):
         template = Template(open(filename, "rb").read(),
                             filename=filename,
                             input_encoding="utf8",
                             lookup=lookup,
                             strict_undefined=True)
         # Uncomment to debug generated Python code:
         # write("/tmp", "mako_%s.py" % os.path.basename(filename), template.code)
         return template.render(**context).encode("utf8")
-    except:
+    except Exception:
         # Uncomment to see a traceback in generated Python code:
         # raise
         abort(exceptions.text_error_template().render().encode("utf8"))
 
 
 def write(directory, filename, content):
     if not os.path.exists(directory):
         os.makedirs(directory)
--- a/servo/components/style/properties/data.py
+++ b/servo/components/style/properties/data.py
@@ -70,17 +70,18 @@ class Keyword(object):
                  extra_gecko_values=None, extra_servo_values=None,
                  aliases=None,
                  extra_gecko_aliases=None,
                  gecko_strip_moz_prefix=None,
                  gecko_inexhaustive=None):
         self.name = name
         self.values = values.split()
         if gecko_constant_prefix and gecko_enum_prefix:
-            raise TypeError("Only one of gecko_constant_prefix and gecko_enum_prefix can be specified")
+            raise TypeError("Only one of gecko_constant_prefix and gecko_enum_prefix "
+                            "can be specified")
         self.gecko_constant_prefix = gecko_constant_prefix or \
             "NS_STYLE_" + self.name.upper().replace("-", "_")
         self.gecko_enum_prefix = gecko_enum_prefix
         self.extra_gecko_values = (extra_gecko_values or "").split()
         self.extra_servo_values = (extra_servo_values or "").split()
         self.aliases = parse_aliases(aliases or "")
         self.extra_gecko_aliases = parse_aliases(extra_gecko_aliases or "")
         self.consts_map = {} if custom_consts is None else custom_consts
@@ -111,17 +112,18 @@ class Keyword(object):
         if product == "gecko":
             return self.gecko_aliases()
         elif product == "servo":
             return self.aliases
         else:
             raise Exception("Bad product: " + product)
 
     def gecko_constant(self, value):
-        moz_stripped = value.replace("-moz-", '') if self.gecko_strip_moz_prefix else value.replace("-moz-", 'moz-')
+        moz_stripped = (value.replace("-moz-", '')
+                        if self.gecko_strip_moz_prefix else value.replace("-moz-", 'moz-'))
         mapped = self.consts_map.get(value)
         if self.gecko_enum_prefix:
             parts = moz_stripped.replace('-', '_').split('_')
             parts = mapped if mapped else [p.title() for p in parts]
             return self.gecko_enum_prefix + "::" + "".join(parts)
         else:
             suffix = mapped if mapped else moz_stripped.replace("-", "_")
             return self.gecko_constant_prefix + "_" + suffix.upper()
@@ -162,17 +164,18 @@ def parse_property_aliases(alias_list):
 
 class Longhand(object):
     def __init__(self, style_struct, name, spec=None, animation_value_type=None, keyword=None,
                  predefined_type=None, servo_pref=None, gecko_pref=None,
                  enabled_in="content", need_index=False,
                  gecko_ffi_name=None,
                  allowed_in_keyframe_block=True, cast_type='u8',
                  logical=False, alias=None, extra_prefixes=None, boxed=False,
-                 flags=None, allowed_in_page_rule=False, allow_quirks=False, ignored_when_colors_disabled=False,
+                 flags=None, allowed_in_page_rule=False, allow_quirks=False,
+                 ignored_when_colors_disabled=False,
                  vector=False, servo_restyle_damage="repaint"):
         self.name = name
         if not spec:
             raise TypeError("Spec should be specified for %s" % name)
         self.spec = spec
         self.keyword = keyword
         self.predefined_type = predefined_type
         self.ident = to_rust_ident(name)
--- a/tools/lint/flake8.yml
+++ b/tools/lint/flake8.yml
@@ -17,16 +17,17 @@ flake8:
         - python/mozboot
         - python/mozbuild/mozpack/path.py
         - python/mozlint
         - python/mozterm
         - python/mozversioncontrol
         - python/safety
         - security/
         - security/manager
+        - servo/
         - taskcluster
         - testing/firefox-ui
         - testing/mach_commands.py
         - testing/marionette/client
         - testing/marionette/harness
         - testing/marionette/puppeteer
         - testing/mochitest
         - testing/mozbase