diff --git a/HACKING.rst b/HACKING.rst index 80d58701c64..48e4ed6b8f0 100644 --- a/HACKING.rst +++ b/HACKING.rst @@ -28,7 +28,6 @@ Neutron Specific Commandments - [N334] Use unittest2 uniformly across Neutron. - [N340] Check usage of .i18n (and neutron.i18n) - [N341] Check usage of _ from python builtins -- [N342] String interpolation should be delayed at logging calls. - [N343] Production code must not import from neutron.tests.* - [N344] Python 3: Do not use filter(lambda obj: test(obj), data). Replace it with [obj for obj in data if test(obj)]. diff --git a/neutron/hacking/checks.py b/neutron/hacking/checks.py index a253a15c1a6..b83767af785 100644 --- a/neutron/hacking/checks.py +++ b/neutron/hacking/checks.py @@ -64,9 +64,6 @@ def _regex_for_level(level, hint): } -log_string_interpolation = re.compile(r".*LOG\.(?:error|warn|warning|info" - r"|critical|exception|debug)" - r"\([^,]*%[^,]*[,)]") log_translation_hint = re.compile( '|'.join('(?:%s)' % _regex_for_level(level, hint) for level, hint in six.iteritems(_all_log_levels))) @@ -364,28 +361,6 @@ def check_unittest_imports(logical_line): yield (0, msg) -@flake8ext -def check_delayed_string_interpolation(logical_line, filename, noqa): - """N342 String interpolation should be delayed at logging calls. - - N342: LOG.debug('Example: %s' % 'bad') - Okay: LOG.debug('Example: %s', 'good') - """ - msg = ("N342 String interpolation should be delayed to be " - "handled by the logging code, rather than being done " - "at the point of the logging call. " - "Use ',' instead of '%'.") - - if noqa: - return - - if 'neutron/tests/' in filename: - return - - if log_string_interpolation.match(logical_line): - yield(0, msg) - - @flake8ext def check_no_imports_from_tests(logical_line, filename, noqa): """N343 Production code must not import from neutron.tests.* @@ -432,6 +407,5 @@ def factory(register): register(check_oslo_i18n_wrapper) register(check_builtins_gettext) register(check_unittest_imports) - register(check_delayed_string_interpolation) register(check_no_imports_from_tests) register(check_python3_no_filter) diff --git a/neutron/tests/unit/hacking/test_checks.py b/neutron/tests/unit/hacking/test_checks.py index 536f58716c8..c891633b124 100644 --- a/neutron/tests/unit/hacking/test_checks.py +++ b/neutron/tests/unit/hacking/test_checks.py @@ -301,39 +301,6 @@ class HackingTestCase(base.BaseTestCase): self.assertLineFails(f, 'from unittest.TestSuite') self.assertLineFails(f, 'import unittest') - def test_check_delayed_string_interpolation(self): - dummy_noqa = CREATE_DUMMY_MATCH_OBJECT.search('a') - - # In 'logical_line', Contents of strings replaced with - # "xxx" of same length. - fail_code1 = 'LOG.error(_LE("xxxxxxxxxxxxxxx") % value)' - fail_code2 = "LOG.warning(msg % 'xxxxx')" - - self.assertEqual( - 1, len(list(checks.check_delayed_string_interpolation(fail_code1, - "neutron/common/rpc.py", None)))) - self.assertEqual( - 1, len(list(checks.check_delayed_string_interpolation(fail_code2, - "neutron/common/rpc.py", None)))) - - pass_code1 = 'LOG.error(_LE("xxxxxxxxxxxxxxxxxx"), value)' - pass_code2 = "LOG.warning(msg, 'xxxxx')" - self.assertEqual( - 0, len(list(checks.check_delayed_string_interpolation(pass_code1, - "neutron/common/rpc.py", None)))) - self.assertEqual( - 0, len(list(checks.check_delayed_string_interpolation(pass_code2, - "neutron/common/rpc.py", None)))) - # check a file in neutron/tests - self.assertEqual( - 0, len(list(checks.check_delayed_string_interpolation(fail_code1, - "neutron/tests/test_assert.py", - None)))) - # check code including 'noqa' - self.assertEqual( - 0, len(list(checks.check_delayed_string_interpolation(fail_code1, - "neutron/common/rpc.py", dummy_noqa)))) - def test_check_log_warn_deprecated(self): bad = "LOG.warn(_LW('i am zlatan!'))" self.assertEqual( diff --git a/test-requirements.txt b/test-requirements.txt index ef7410e754c..83d4eac97ae 100644 --- a/test-requirements.txt +++ b/test-requirements.txt @@ -1,7 +1,7 @@ # The order of packages is significant, because pip processes them in the order # of appearance. Changing the order has an impact on the overall integration # process, which may cause wedges in the gate later. -hacking<0.12,>=0.11.0 # Apache-2.0 +hacking<0.13,>=0.12.0 # Apache-2.0 coverage>=4.0 # Apache-2.0 fixtures>=3.0.0 # Apache-2.0/BSD diff --git a/tox.ini b/tox.ini index 0835f9af021..d3138031fe9 100644 --- a/tox.ini +++ b/tox.ini @@ -138,6 +138,8 @@ commands = sphinx-build -W -b html doc/source doc/build/html # H404 multi line docstring should start with a summary # H405 multi line docstring summary not separated with an empty line ignore = E125,E126,E128,E129,E265,H404,H405 +# H904: Delay string interpolations at logging calls +enable-extensions=H904 show-source = true exclude = ./.*,build,dist