Chromium Code Reviews
chromiumcodereview-hr@appspot.gserviceaccount.com (chromiumcodereview-hr) | Please choose your nickname with Settings | Help | Chromium Project | Gerrit Changes | Sign out
(107)

Side by Side Diff: third_party/WebKit/Tools/Scripts/webkitpy/style/checkers/python.py

Issue 2010173003: Enable pylint warnings on presubmit checks. (Closed) Base URL: https://chromium.googlesource.com/chromium/src.git@master
Patch Set: Remove print statement in test Created 4 years, 6 months ago
Use n/p to move between diff chunks; N/P to move between comments. Draft comments are only viewable by you.
Jump to:
View unified diff | Download patch
OLDNEW
1 # Copyright (C) 2010 Chris Jerdonek (cjerdonek@webkit.org) 1 # Copyright (C) 2010 Chris Jerdonek (cjerdonek@webkit.org)
2 # 2 #
3 # Redistribution and use in source and binary forms, with or without 3 # Redistribution and use in source and binary forms, with or without
4 # modification, are permitted provided that the following conditions 4 # modification, are permitted provided that the following conditions
5 # are met: 5 # are met:
6 # 1. Redistributions of source code must retain the above copyright 6 # 1. Redistributions of source code must retain the above copyright
7 # notice, this list of conditions and the following disclaimer. 7 # notice, this list of conditions and the following disclaimer.
8 # 2. Redistributions in binary form must reproduce the above copyright 8 # 2. Redistributions in binary form must reproduce the above copyright
9 # notice, this list of conditions and the following disclaimer in the 9 # notice, this list of conditions and the following disclaimer in the
10 # documentation and/or other materials provided with the distribution. 10 # documentation and/or other materials provided with the distribution.
(...skipping 22 matching lines...) Expand all
33 from webkitpy.thirdparty import pep8 33 from webkitpy.thirdparty import pep8
34 34
35 35
36 class PythonChecker(object): 36 class PythonChecker(object):
37 """Processes text lines for checking style.""" 37 """Processes text lines for checking style."""
38 38
39 def __init__(self, file_path, handle_style_error): 39 def __init__(self, file_path, handle_style_error):
40 self._file_path = file_path 40 self._file_path = file_path
41 self._handle_style_error = handle_style_error 41 self._handle_style_error = handle_style_error
42 42
43 def check(self, lines): 43 def check(self, lines_unused=None):
44 self._check_pep8(lines) 44 self._check_pep8()
45 self._check_pylint(lines) 45 self._check_pylint()
46 46
47 def _check_pep8(self, lines): 47 def _check_pep8(self):
48 # Initialize pep8.options, which is necessary for 48 # Initialize pep8.options, which is necessary for
49 # Checker.check_all() to execute. 49 # Checker.check_all() to execute.
50 pep8.process_options(arglist=[self._file_path]) 50 pep8.process_options(arglist=[self._file_path])
51 51
52 pep8_checker = pep8.Checker(self._file_path) 52 pep8_checker = pep8.Checker(self._file_path)
53 53
54 def _pep8_handle_error(line_number, offset, text, check): 54 def _pep8_handle_error(line_number, offset, text, check):
55 # FIXME: Incorporate the character offset into the error output. 55 # FIXME: Incorporate the character offset into the error output.
56 # This will require updating the error handler __call__ 56 # This will require updating the error handler __call__
57 # signature to include an optional "offset" parameter. 57 # signature to include an optional "offset" parameter.
58 pep8_code = text[:4] 58 pep8_code = text[:4]
59 pep8_message = text[5:] 59 pep8_message = text[5:]
60 60
61 category = "pep8/" + pep8_code 61 category = "pep8/" + pep8_code
62 62
63 self._handle_style_error(line_number, category, 5, pep8_message) 63 self._handle_style_error(line_number, category, 5, pep8_message)
64 64
65 pep8_checker.report_error = _pep8_handle_error 65 pep8_checker.report_error = _pep8_handle_error
66 pep8_errors = pep8_checker.check_all() 66 pep8_errors = pep8_checker.check_all()
67 67
68 def _check_pylint(self, lines): 68 def _check_pylint(self):
69 output = self._run_pylint(self._file_path) 69 output = self._run_pylint(self._file_path)
70 print output
70 errors = self._parse_pylint_output(output) 71 errors = self._parse_pylint_output(output)
71 for line_number, category, message in errors: 72 for line_number, category, message in errors:
72 self._handle_style_error(line_number, category, 5, message) 73 self._handle_style_error(line_number, category, 5, message)
73 74
74 def _run_pylint(self, path): 75 def _run_pylint(self, path):
75 wkf = WebKitFinder(FileSystem()) 76 wkf = WebKitFinder(FileSystem())
76 executive = Executive() 77 executive = Executive()
77 env = os.environ.copy() 78 env = os.environ.copy()
78 env['PYTHONPATH'] = ('%s%s%s%s%s' % (wkf.path_from_webkit_base('Tools', 'Scripts'), 79 env['PYTHONPATH'] = ('%s%s%s%s%s' % (wkf.path_from_webkit_base('Tools', 'Scripts'),
79 os.pathsep, 80 os.pathsep,
80 wkf.path_from_webkit_base('Source', 'build', 'scripts'), 81 wkf.path_from_webkit_base('Source', 'build', 'scripts'),
81 os.pathsep, 82 os.pathsep,
82 wkf.path_from_webkit_base('Tools', 'Scripts', 'webkitpy', 'thirdparty'))) 83 wkf.path_from_webkit_base('Tools', 'Scripts', 'webkitpy', 'thirdparty')))
83 return executive.run_command([sys.executable, wkf.path_from_depot_tools_ base('pylint.py'), 84 return executive.run_command([sys.executable, wkf.path_from_depot_tools_ base('pylint.py'),
84 '--output-format=parseable', 85 '--output-format=parseable',
85 '--errors-only',
86 '--rcfile=' + wkf.path_from_webkit_base('T ools', 'Scripts', 'webkitpy', 'pylintrc'), 86 '--rcfile=' + wkf.path_from_webkit_base('T ools', 'Scripts', 'webkitpy', 'pylintrc'),
87 path], 87 path],
88 env=env, 88 env=env,
89 error_handler=executive.ignore_error) 89 error_handler=executive.ignore_error)
90 90
91 def _parse_pylint_output(self, output): 91 def _parse_pylint_output(self, output):
92 # We filter out these messages because they are bugs in pylint that prod uce false positives. 92 # We filter out these messages because they are bugs in pylint that prod uce false positives.
93 # FIXME: Does it make sense to combine these rules with the rules in sty le/checker.py somehow? 93 # FIXME: Does it make sense to combine these rules with the rules in sty le/checker.py somehow?
94 FALSE_POSITIVES = [ 94 FALSE_POSITIVES = [
95 # possibly http://www.logilab.org/ticket/98613 ? 95 # possibly http://www.logilab.org/ticket/98613 ?
(...skipping 17 matching lines...) Expand all
113 113
114 line_number = int(match_obj.group(2)) 114 line_number = int(match_obj.group(2))
115 category_and_method = match_obj.group(3).split(', ') 115 category_and_method = match_obj.group(3).split(', ')
116 category = 'pylint/' + (category_and_method[0]) 116 category = 'pylint/' + (category_and_method[0])
117 if len(category_and_method) > 1: 117 if len(category_and_method) > 1:
118 message = '[%s] %s' % (category_and_method[1], match_obj.group(4 )) 118 message = '[%s] %s' % (category_and_method[1], match_obj.group(4 ))
119 else: 119 else:
120 message = match_obj.group(4) 120 message = match_obj.group(4)
121 errors.append((line_number, category, message)) 121 errors.append((line_number, category, message))
122 return errors 122 return errors
OLDNEW

Powered by Google App Engine
This is Rietveld 408576698