Codebase list python-osprofiler / 6e6d76a
Update hacking for Python3 The repo is Python 3 now, so update hacking to version 3.0 which supports Python 3. Fix problems found. Update local hacking checks for new flake8. Change-Id: I8ba89483c8e6b76011833cfc5080eab3fd269c8b Andreas Jaeger 4 years ago
3 changed file(s) with 30 addition(s) and 18 deletion(s). Raw diff Collapse all Expand all
2626 import functools
2727 import re
2828 import tokenize
29
30 from hacking import core
2931
3032 re_assert_true_instance = re.compile(
3133 r"(.)*assertTrue\(isinstance\((\w|\.|\'|\"|\[|\])+, "
6264 r"\s:raise[^s] *.*$|\s:raises *:.*$|\s:raises *[^:]+$")
6365
6466
67 @core.flake8ext
6568 def skip_ignored_lines(func):
6669
6770 @functools.wraps(func)
8588
8689
8790 @skip_ignored_lines
91 @core.flake8ext
8892 def check_assert_methods_from_mock(logical_line, filename):
8993 """Ensure that ``assert_*`` methods from ``mock`` library is used correctly
9094
131135
132136
133137 @skip_ignored_lines
138 @core.flake8ext
134139 def assert_true_instance(logical_line, filename):
135140 """Check for assertTrue(isinstance(a, b)) sentences
136141
142147
143148
144149 @skip_ignored_lines
150 @core.flake8ext
145151 def assert_equal_type(logical_line, filename):
146152 """Check for assertEqual(type(A), B) sentences
147153
153159
154160
155161 @skip_ignored_lines
162 @core.flake8ext
156163 def assert_equal_none(logical_line, filename):
157164 """Check for assertEqual(A, None) or assertEqual(None, A) sentences
158165
167174
168175
169176 @skip_ignored_lines
177 @core.flake8ext
170178 def assert_true_or_false_with_in(logical_line, filename):
171179 """Check assertTrue/False(A in/not in B) with collection contents
172180
185193
186194
187195 @skip_ignored_lines
196 @core.flake8ext
188197 def assert_equal_in(logical_line, filename):
189198 """Check assertEqual(A in/not in B, True/False) with collection contents
190199
203212
204213
205214 @skip_ignored_lines
215 @core.flake8ext
206216 def check_quotes(logical_line, filename):
207217 """Check that single quotation marks are not used
208218
256266
257267
258268 @skip_ignored_lines
269 @core.flake8ext
259270 def check_no_constructor_data_struct(logical_line, filename):
260271 """Check that data structs (lists, dicts) are declared using literals
261272
270281 yield (0, "N351 Remove list() construct and use literal []")
271282
272283
284 @core.flake8ext
273285 def check_dict_formatting_in_string(logical_line, tokens):
274286 """Check that strings do not use dict-formatting with a single replacement
275287
321333 format_keys.add(match.group(1))
322334 if len(format_keys) == 1:
323335 yield (0,
324 "N353 Do not use mapping key string formatting "
336 "N352 Do not use mapping key string formatting "
325337 "with a single key")
326338 if text != ")":
327339 # NOTE(stpierre): You can have a parenthesized string
338350
339351
340352 @skip_ignored_lines
353 @core.flake8ext
341354 def check_using_unicode(logical_line, filename):
342355 """Check crosspython unicode usage
343356
349362 "use 'six.text_type' instead.")
350363
351364
365 @core.flake8ext
352366 def check_raises(physical_line, filename):
353367 """Check raises usage
354368
361375 if re_raises.search(physical_line):
362376 return (0, "N354 ':Please use ':raises Exception: conditions' "
363377 "in docstrings.")
364
365
366 def factory(register):
367 register(check_assert_methods_from_mock)
368 register(assert_true_instance)
369 register(assert_equal_type)
370 register(assert_equal_none)
371 register(assert_true_or_false_with_in)
372 register(assert_equal_in)
373 register(check_quotes)
374 register(check_no_constructor_data_struct)
375 register(check_dict_formatting_in_string)
376 register(check_using_unicode)
377 register(check_raises)
0 hacking>=2.0,<=2.1 # Apache-2.0
0 hacking>=3.0,<3.1.0 # Apache-2.0
11
22 coverage>=4.0 # Apache-2.0
33 ddt>=1.0.1 # MIT
6262 builtins = _
6363 exclude=.venv,.git,.tox,dist,doc,*lib/python*,*egg,tools,setup.py,build,releasenotes
6464
65 [hacking]
66 local-check-factory = osprofiler.hacking.checks.factory
65 [flake8:local-plugins]
66 extension =
67 N301 = checks:check_assert_methods_from_mock
68 N320 = checks:assert_true_instance
69 N321 = checks:assert_equal_type
70 N322 = checks:assert_equal_none
71 N323 = checks:assert_true_or_false_with_in
72 N324 = checks:assert_equal_in
73 N350 = checks:check_quotes
74 N351 = checks:check_no_constructor_data_struct
75 N352 = checks:check_dict_formatting_in_string
76 N353 = checks:check_using_unicode
77 N354 = checks:check_raises
78 paths = ./osprofiler/hacking
6779
6880 [testenv:releasenotes]
6981 commands = sphinx-build -a -E -W -d releasenotes/build/doctrees -b html releasenotes/source releasenotes/build/html