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

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

Issue 1839193004: Run auto-formatter (autopep8) on webkitpy. (Closed) Base URL: https://chromium.googlesource.com/chromium/src.git@master
Patch Set: Rebased Created 4 years, 8 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 18 matching lines...) Expand all
29 from StringIO import StringIO 29 from StringIO import StringIO
30 30
31 from webkitpy.common.system.filesystem import FileSystem 31 from webkitpy.common.system.filesystem import FileSystem
32 from webkitpy.common.system.executive import Executive 32 from webkitpy.common.system.executive import Executive
33 from webkitpy.common.webkit_finder import WebKitFinder 33 from webkitpy.common.webkit_finder import WebKitFinder
34 from webkitpy.thirdparty import pep8 34 from webkitpy.thirdparty import pep8
35 35
36 36
37 class PythonChecker(object): 37 class PythonChecker(object):
38 """Processes text lines for checking style.""" 38 """Processes text lines for checking style."""
39
39 def __init__(self, file_path, handle_style_error): 40 def __init__(self, file_path, handle_style_error):
40 self._file_path = file_path 41 self._file_path = file_path
41 self._handle_style_error = handle_style_error 42 self._handle_style_error = handle_style_error
42 43
43 def check(self, lines): 44 def check(self, lines):
44 self._check_pep8(lines) 45 self._check_pep8(lines)
45 self._check_pylint(lines) 46 self._check_pylint(lines)
46 47
47 def _check_pep8(self, lines): 48 def _check_pep8(self, lines):
48 # Initialize pep8.options, which is necessary for 49 # Initialize pep8.options, which is necessary for
(...skipping 20 matching lines...) Expand all
69 output = self._run_pylint(self._file_path) 70 output = self._run_pylint(self._file_path)
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', 'bu ild', 'scripts'), 81 wkf.path_from_webkit_base('Source', 'build', 'scripts'),
81 os.pathsep, 82 os.pathsep,
82 wkf.path_from_webkit_base('Tools', 'Scr ipts', '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 '--errors-only',
86 '--rcfile=' + wkf.path_from_webkit_base('T ools', 'Scripts', 'webkitpy', 'pylintrc'), 87 '--rcfile=' + wkf.path_from_webkit_base('T ools', 'Scripts', 'webkitpy', 'pylintrc'),
87 path], 88 path],
88 env=env, 89 env=env,
89 error_handler=executive.ignore_error) 90 error_handler=executive.ignore_error)
90 91
91 def _parse_pylint_output(self, output): 92 def _parse_pylint_output(self, output):
92 # We filter out these messages because they are bugs in pylint that prod uce false positives. 93 # We filter out these messages because they are bugs in pylint that prod uce false positives.
(...skipping 20 matching lines...) Expand all
113 114
114 line_number = int(match_obj.group(2)) 115 line_number = int(match_obj.group(2))
115 category_and_method = match_obj.group(3).split(', ') 116 category_and_method = match_obj.group(3).split(', ')
116 category = 'pylint/' + (category_and_method[0]) 117 category = 'pylint/' + (category_and_method[0])
117 if len(category_and_method) > 1: 118 if len(category_and_method) > 1:
118 message = '[%s] %s' % (category_and_method[1], match_obj.group(4 )) 119 message = '[%s] %s' % (category_and_method[1], match_obj.group(4 ))
119 else: 120 else:
120 message = match_obj.group(4) 121 message = match_obj.group(4)
121 errors.append((line_number, category, message)) 122 errors.append((line_number, category, message))
122 return errors 123 return errors
OLDNEW

Powered by Google App Engine
This is Rietveld 408576698