Mojo: Add PRESUBMIT.py to mojo/.

Currently, it only adds pylint checks, with a blacklist for all the
files that fail horribly (or in otherwise mysterious ways).

Also fix a few (less mysterious) pylint failures. Remove some pylint
suppressions (since we now add appropriate directories to the python
module path for pylint).

R=sky@chromium.org

Review URL: https://codereview.chromium.org/443293003

git-svn-id: svn://svn.chromium.org/chrome/trunk/src@287988 0039d316-1c4b-4281-b951-d872f2087c98
parent 0239bc50
# Copyright 2014 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.
"""Presubmit script for mojo/embedder.
See http://dev.chromium.org/developers/how-tos/depottools/presubmit-scripts
for more details about the presubmit API built into depot_tools.
"""
import os.path
def CheckChangeOnUpload(input_api, output_api):
# Additional python module paths (we're in src/mojo/); not everyone needs
# them, but it's easiest to add them to everyone's path.
# For ply and jinja2:
third_party_path = os.path.join(
input_api.PresubmitLocalPath(), "..", "third_party")
# For the bindings generator:
mojo_public_bindings_pylib_path = os.path.join(
input_api.PresubmitLocalPath(), "public", "tools", "bindings", "pylib")
# TODO(vtl): Don't lint these files until the (many) problems are fixed
# (possibly by deleting/rewriting some files).
temporary_black_list = input_api.DEFAULT_BLACK_LIST + \
(r".*\bpublic[\\\/]tools[\\\/]bindings[\\\/]pylib[\\\/]mojom[\\\/]"
r"generate[\\\/].+\.py$",
r".*\bpublic[\\\/]tools[\\\/]bindings[\\\/]generators[\\\/].+\.py$",
r".*\bspy[\\\/]ui[\\\/].+\.py$",
r".*\btools[\\\/]pylib[\\\/]transitive_hash\.py$",
r".*\btools[\\\/]test_runner\.py$")
results = []
pylint_extra_paths = [third_party_path, mojo_public_bindings_pylib_path]
results += input_api.canned_checks.RunPylint(
input_api, output_api, extra_paths_list=pylint_extra_paths,
black_list=temporary_black_list)
return results
......@@ -76,12 +76,12 @@ def MakeImportStackMessage(imported_filename_stack):
zip(imported_filename_stack[1:], imported_filename_stack)]))
def FindImportFile(dir, file, search_dirs):
for search_dir in [dir] + search_dirs:
path = os.path.join(search_dir, file)
def FindImportFile(dir_name, file_name, search_dirs):
for search_dir in [dir_name] + search_dirs:
path = os.path.join(search_dir, file_name)
if os.path.isfile(path):
return path
return os.path.join(dir, file);
return os.path.join(dir_name, file_name)
# Disable check for dangerous default arguments (they're "private" keyword
......@@ -127,7 +127,7 @@ def ProcessFile(args, remaining_args, generator_modules, filename,
for import_data in mojom['imports']:
import_filename = FindImportFile(dirname,
import_data['filename'],
args.import_directories);
args.import_directories)
import_data['module'] = ProcessFile(
args, remaining_args, generator_modules, import_filename,
_processed_files=_processed_files,
......
......@@ -38,9 +38,9 @@ def istr(index, string):
def __lt__(self, other):
return self.__index__ < other.__index__
istr = IndexedString(string)
istr.__index__ = index
return istr
rv = IndexedString(string)
rv.__index__ = index
return rv
def LookupKind(kinds, spec, scope):
"""Tries to find which Kind a spec refers to, given the scope in which its
......@@ -350,7 +350,6 @@ def ModuleFromData(data):
def OrderedModuleFromData(data):
module = ModuleFromData(data)
next_interface_ordinal = 0
for interface in module.interfaces:
next_ordinal = 0
for method in interface.methods:
......
......@@ -220,8 +220,7 @@ class Module(object):
self.interfaces = []
def AddInterface(self, name):
interface=Interface(name, module=self);
self.interfaces.append(interface)
self.interfaces.append(Interface(name, module=self))
return interface
def AddStruct(self, name):
......
......@@ -39,7 +39,7 @@ def ApplyTemplate(mojo_generator, base_dir, path_to_template, params,
final_kwargs.update(kwargs)
jinja_env = jinja2.Environment(loader=loader, keep_trailing_newline=True,
**final_kwargs)
jinja_env.globals.update(mojo_generator.GetGlobals());
jinja_env.globals.update(mojo_generator.GetGlobals())
if filters:
jinja_env.filters.update(filters)
template = jinja_env.get_template(template_name)
......
......@@ -6,9 +6,6 @@ import imp
import os.path
import sys
# Disable lint check for finding modules:
# pylint: disable=F0401
def _GetDirAbove(dirname):
"""Returns the directory "above" this file containing |dirname| (which must
also be "above" this file)."""
......@@ -28,8 +25,6 @@ from ply.lex import TOKEN
from ..error import Error
# Disable lint check for exceptions deriving from Exception:
# pylint: disable=W0710
class LexError(Error):
"""Class for errors from the lexer."""
......
......@@ -8,9 +8,6 @@ import imp
import os.path
import sys
# Disable lint check for finding modules:
# pylint: disable=F0401
def _GetDirAbove(dirname):
"""Returns the directory "above" this file containing |dirname| (which must
also be "above" this file)."""
......@@ -29,16 +26,14 @@ from ply import lex
from ply import yacc
from ..error import Error
import ast
from lexer import Lexer
from . import ast
from .lexer import Lexer
_MAX_ORDINAL_VALUE = 0xffffffff
_MAX_ARRAY_SIZE = 0xffffffff
# Disable lint check for exceptions deriving from Exception:
# pylint: disable=W0710
class ParseError(Error):
"""Class for errors from the parser."""
......
......@@ -5,9 +5,10 @@
"""Translates parse tree to Mojom IR."""
import ast
import re
from . import ast
def _MapTreeForType(func, tree, type_to_map):
assert isinstance(type_to_map, type)
......
......@@ -7,9 +7,6 @@ import os.path
import sys
import unittest
# Disable lint check for finding modules:
# pylint: disable=F0401
def _GetDirAbove(dirname):
"""Returns the directory "above" this file containing |dirname| (which must
also be "above" this file)."""
......
......@@ -7,9 +7,6 @@ import os.path
import sys
import unittest
# Disable lint check for finding modules:
# pylint: disable=F0401
def _GetDirAbove(dirname):
"""Returns the directory "above" this file containing |dirname| (which must
also be "above" this file)."""
......
......@@ -7,9 +7,6 @@ import os.path
import sys
import unittest
# Disable lint check for finding modules:
# pylint: disable=F0401
def _GetDirAbove(dirname):
"""Returns the directory "above" this file containing |dirname| (which must
also be "above" this file)."""
......
......@@ -12,9 +12,6 @@ import sys
sys.path.insert(0, os.path.join(os.path.dirname(os.path.abspath(__file__)),
os.path.pardir, os.path.pardir))
# Disable lint check for finding modules:
# pylint: disable=F0401
from mojom.parse.parser import Parse, ParseError
......
......@@ -12,9 +12,6 @@ import sys
sys.path.insert(0, os.path.join(os.path.dirname(os.path.abspath(__file__)),
os.path.pardir, os.path.pardir))
# Disable lint check for finding modules:
# pylint: disable=F0401
from mojom.parse.parser import Parse
from mojom.parse.translate import Translate
......
......@@ -2,7 +2,7 @@
# Use of this source code is governed by a BSD-style license that can be
# found in the LICENSE file.
from fnmatch import filter
import fnmatch
from os import walk
from os.path import join
import sys
......@@ -13,7 +13,7 @@ def FindFiles(top, pattern, **kwargs):
list of paths."""
matches = []
for dirpath, _, filenames in walk(top, **kwargs):
for filename in filter(filenames, pattern):
for filename in fnmatch.filter(filenames, pattern):
matches.append(join(dirpath, filename))
return matches
......
......@@ -35,14 +35,14 @@ public interface Callbacks {
}""")
def GenerateCallback(nb_args):
params = '\n * '.join(
['@param <T%d> the type of argument %d.' % (i+1, i+1)
for i in xrange(nb_args)])
template_parameters = ', '.join(['T%d' % (i+1) for i in xrange(nb_args)])
callback_parameters = ', '.join(['T%d arg%d' % ((i+1), (i+1))
for i in xrange(nb_args)])
return CALLBACK_TEMPLATE % (nb_args, params, nb_args, template_parameters,
callback_parameters)
params = '\n * '.join(
['@param <T%d> the type of argument %d.' % (i+1, i+1)
for i in xrange(nb_args)])
template_parameters = ', '.join(['T%d' % (i+1) for i in xrange(nb_args)])
callback_parameters = ', '.join(['T%d arg%d' % ((i+1), (i+1))
for i in xrange(nb_args)])
return CALLBACK_TEMPLATE % (nb_args, params, nb_args, template_parameters,
callback_parameters)
def main():
parser = argparse.ArgumentParser(
......
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