Rietveld Code Review Tool
Help | Bug tracker | Discussion group | Source code

Delta Between Two Patch Sets: flake8-abp/setup.py

Issue 29340727: Noissue - Added flake8 extension accounting for our coding style and some other stuff (Closed)
Left Patch Set: Added more checks Created April 22, 2016, 12:02 p.m.
Right Patch Set: Addressed comments, fixed two bugs, use ascii() Created May 9, 2016, 4:47 p.m.
Left:
Right:
Use n/p to move between diff chunks; N/P to move between comments.
Jump to:
Left: Side by side diff | Download
Right: Side by side diff | Download
« no previous file with change/comment | « flake8-abp/flake8_abp.py ('k') | flake8-abp/tests/A101.py » ('j') | no next file with change/comment »
Toggle Intra-line Diffs ('i') | Expand Comments ('e') | Collapse Comments ('c') | Show Comments Hide Comments ('s')
LEFTRIGHT
1 # This file is part of Adblock Plus <https://adblockplus.org/>, 1 # This file is part of Adblock Plus <https://adblockplus.org/>,
2 # Copyright (C) 2006-2016 Eyeo GmbH 2 # Copyright (C) 2006-2016 Eyeo GmbH
3 # 3 #
4 # Adblock Plus is free software: you can redistribute it and/or modify 4 # Adblock Plus is free software: you can redistribute it and/or modify
5 # it under the terms of the GNU General Public License version 3 as 5 # it under the terms of the GNU General Public License version 3 as
6 # published by the Free Software Foundation. 6 # published by the Free Software Foundation.
7 # 7 #
8 # Adblock Plus is distributed in the hope that it will be useful, 8 # Adblock Plus is distributed in the hope that it will be useful,
9 # but WITHOUT ANY WARRANTY; without even the implied warranty of 9 # but WITHOUT ANY WARRANTY; without even the implied warranty of
10 # MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the 10 # MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
11 # GNU General Public License for more details. 11 # GNU General Public License for more details.
12 # 12 #
13 # You should have received a copy of the GNU General Public License 13 # You should have received a copy of the GNU General Public License
14 # along with Adblock Plus. If not, see <http://www.gnu.org/licenses/>. 14 # along with Adblock Plus. If not, see <http://www.gnu.org/licenses/>.
15 from __future__ import print_function
15 16
16 from setuptools import setup 17 import os
18 import glob
19 import tokenize
20 import sys
21 import re
22
23 try:
24 from StringIO import StringIO
25 except ImportError:
26 from io import StringIO
27
28 from setuptools import setup, Command
29
30
31 class TestCommand(Command):
32 user_options = []
33
34 def _get_expected_errors(self, filename):
35 errors = set()
36
37 def tokeneater(kind, token, start, end, line):
38 if kind == tokenize.COMMENT:
39 match = re.search(r'^#+[*\s]*(A\d+)', token)
40 if match:
41 try:
42 offset = token.index('*')
43 except ValueError:
44 offset = 0
45 errors.add((start[0] + 1,
46 start[1] + 1 + offset,
47 match.group(1)))
48
49 with open(filename, 'rb') as file:
50 if sys.version_info[0] >= 3:
51 for token in tokenize.tokenize(file.readline):
52 tokeneater(*token)
53 else:
54 tokenize.tokenize(file.readline, tokeneater)
55
56 return errors
57
58 def _get_reported_errors(self, filename, style_guide):
59 orig_stdout = sys.stdout
60 sys.stdout = stdout = StringIO()
61
62 try:
63 style_guide.check_files([filename])
64 finally:
65 sys.stdout = orig_stdout
66
67 stdout.seek(0)
68 errors = set()
69
70 for line in stdout:
71 _, lineno, colno, error = line.split(':', 3)
72 errors.add((int(lineno), int(colno), error.split()[0]))
73
74 return errors
75
76 def initialize_options(self):
77 pass
78
79 def finalize_options(self):
80 pass
81
82 def run(self):
83 import flake8.engine
84
85 directory = os.path.dirname(__file__)
86 filenames = glob.glob(os.path.join(directory, 'tests', '*.py'))
87 style_guide = flake8.engine.get_style_guide()
88 failed = False
89
90 for filename in sorted(filenames):
91 expected = self._get_expected_errors(filename)
92 reported = self._get_reported_errors(filename, style_guide)
93 failures = expected ^ reported
94
95 if not failures:
96 print(filename + ': OK')
97 continue
98
99 for record in sorted(failures):
100 lineno, colno, error = record
101
102 print('{}:{}:{}: '.format(filename, lineno, colno), end='')
103 if record in expected:
104 print(error + ' expected')
105 else:
106 print('unexpected ' + error)
107
108 failed = True
109
110 if failed:
111 sys.exit(1)
112
17 113
18 setup( 114 setup(
19 name='flake8-abp', 115 name='flake8-abp',
116 version='0.1',
20 py_modules=['flake8_abp'], 117 py_modules=['flake8_abp'],
21 entry_points={ 118 entry_points={
22 'flake8.extension': [ 119 'flake8.extension': [
23 'A1 = flake8_abp:ASTChecker', 120 'AXXX = flake8_abp:ASTChecker',
24 'A2 = flake8_abp:check_non_default_encoding', 121 'A109-A110 = flake8_abp:check_quotes',
25 'A3 = flake8_abp:check_quotes', 122 'A111 = flake8_abp:check_redundant_parenthesis',
26 ], 123 'A303 = flake8_abp:check_non_default_encoding',
27 } 124 ],
125 },
126 cmdclass={'test': TestCommand}
28 ) 127 )
LEFTRIGHT

Powered by Google App Engine
This is Rietveld