Update hacking for Python3

The repo is Python 3 now, so update hacking to version 3.0 which
supports Python 3.

Update local hacking check for new flake8 version.

Blacklist:
W504 line break after binary operator

Fix:
E741 ambiguous variable name
E117 over-indented
E305 expected 2 blank lines after class or function definition, found 1
F841 local variable 'e' is assigned to but never used
W605 invalid escape sequence '\.'

Change-Id: I99d574ca6569f1f177d2c5ce1011f269f4343619
This commit is contained in:
Andreas Jaeger 2020-03-27 19:16:32 +01:00 committed by Andreas Jaeger
parent d87618b24f
commit 7f638bb493
11 changed files with 50 additions and 40 deletions

View File

@ -146,7 +146,7 @@ rabbit_opts = [
'queue. If you just want to make sure that all queues (except '
'those with auto-generated names) are mirrored across all '
'nodes, run: '
"""\"rabbitmqctl set_policy HA '^(?!amq\.).*' """
"""\"rabbitmqctl set_policy HA '^(?!amq\\.).*' """
"""'{"ha-mode": "all"}' \""""),
cfg.IntOpt('rabbit_transient_queues_ttl',
min=1,
@ -192,7 +192,7 @@ def _get_queue_arguments(rabbit_ha_queues, rabbit_queue_ttl):
no longer controlled by the x-ha-policy argument when declaring a
queue. If you just want to make sure that all queues (except those
with auto-generated names) are mirrored across all nodes, run:
rabbitmqctl set_policy HA '^(?!amq\.).*' '{"ha-mode": "all"}'
rabbitmqctl set_policy HA '^(?!amq\\.).*' '{"ha-mode": "all"}'
If the rabbit_queue_ttl option is > 0, then the queue is
declared with the "Queue TTL" value as described here:
@ -1204,8 +1204,8 @@ class Connection(object):
"""Publish a message."""
if not (exchange.passive or exchange.name in self._declared_exchanges):
exchange(self.channel).declare()
self._declared_exchanges.add(exchange.name)
exchange(self.channel).declare()
self._declared_exchanges.add(exchange.name)
log_info = {'msg': msg,
'who': exchange or 'default',

View File

@ -15,8 +15,10 @@
import re
import ast
from hacking import core
import six
oslo_namespace_imports_dot = re.compile(r"import[\s]+oslo[.][^\s]+")
oslo_namespace_imports_from_dot = re.compile(r"from[\s]+oslo[.]")
oslo_namespace_imports_from_root = re.compile(r"from[\s]+oslo[\s]+import[\s]+")
@ -24,32 +26,34 @@ mock_imports_directly = re.compile(r"import[\s]+mock")
mock_imports_direclty_from = re.compile(r"from[\s]+mock[\s]+import[\s]+")
@core.flake8ext
def check_oslo_namespace_imports(logical_line):
if re.match(oslo_namespace_imports_from_dot, logical_line):
msg = ("O323: '%s' must be used instead of '%s'.") % (
msg = ("O321: '%s' must be used instead of '%s'.") % (
logical_line.replace('oslo.', 'oslo_'),
logical_line)
yield(0, msg)
elif re.match(oslo_namespace_imports_from_root, logical_line):
msg = ("O323: '%s' must be used instead of '%s'.") % (
msg = ("O321: '%s' must be used instead of '%s'.") % (
logical_line.replace('from oslo import ', 'import oslo_'),
logical_line)
yield(0, msg)
elif re.match(oslo_namespace_imports_dot, logical_line):
msg = ("O323: '%s' must be used instead of '%s'.") % (
msg = ("O321: '%s' must be used instead of '%s'.") % (
logical_line.replace('import', 'from').replace('.', ' import '),
logical_line)
yield(0, msg)
@core.flake8ext
def check_mock_imports(logical_line):
if re.match(mock_imports_directly, logical_line):
msg = ("O324: '%s' must be used instead of '%s'.") % (
msg = ("O322: '%s' must be used instead of '%s'.") % (
logical_line.replace('import mock', 'from six.moves import mock'),
logical_line)
yield(0, msg)
elif re.match(mock_imports_direclty_from, logical_line):
msg = "O324: Use mock from six.moves."
msg = "O322: Use mock from six.moves."
yield(0, msg)
@ -96,6 +100,9 @@ class CheckForLoggingIssues(BaseASTChecker):
EXCESS_HELPER_CHECK_DESC = 'O326 Using hints when _ is necessary'
LOG_MODULES = ('logging')
name = 'check_for_logging_issues'
version = '1.0'
def __init__(self, tree, filename):
super(CheckForLoggingIssues, self).__init__(tree, filename)
@ -291,9 +298,3 @@ class CheckForLoggingIssues(BaseASTChecker):
elif isinstance(peer, ast.Assign):
if name in (t.id for t in peer.targets if hasattr(t, 'id')):
return False
def factory(register):
register(CheckForLoggingIssues)
register(check_oslo_namespace_imports)
register(check_mock_imports)

View File

@ -20,7 +20,7 @@ import six
class NotificationFilter(object):
"""Filter notification messages
r"""Filter notification messages
The NotificationFilter class is used to filter notifications that an
endpoint will received.

View File

@ -13,7 +13,8 @@
# WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. See the
# License for the specific language governing permissions and limitations
# under the License.
"""A notification listener is used to process notification messages sent by a
r"""A notification listener is used to process notification messages sent by a
notifier that uses the ``messaging`` driver.
A notification listener subscribes to the topic - and optionally exchange - in

View File

@ -1026,26 +1026,26 @@ class ConnectionLockTestCase(test_utils.BaseTestCase):
return get_elapsed_time
def test_workers_only(self):
l = rabbit_driver.ConnectionLock()
t1 = self._thread(l, 1)
t2 = self._thread(l, 1)
lock = rabbit_driver.ConnectionLock()
t1 = self._thread(lock, 1)
t2 = self._thread(lock, 1)
self.assertAlmostEqual(1, t1(), places=0)
self.assertAlmostEqual(2, t2(), places=0)
def test_worker_and_heartbeat(self):
l = rabbit_driver.ConnectionLock()
t1 = self._thread(l, 1)
t2 = self._thread(l, 1, heartbeat=True)
lock = rabbit_driver.ConnectionLock()
t1 = self._thread(lock, 1)
t2 = self._thread(lock, 1, heartbeat=True)
self.assertAlmostEqual(1, t1(), places=0)
self.assertAlmostEqual(2, t2(), places=0)
def test_workers_and_heartbeat(self):
l = rabbit_driver.ConnectionLock()
t1 = self._thread(l, 1)
t2 = self._thread(l, 1)
t3 = self._thread(l, 1)
t4 = self._thread(l, 1, heartbeat=True)
t5 = self._thread(l, 1)
lock = rabbit_driver.ConnectionLock()
t1 = self._thread(lock, 1)
t2 = self._thread(lock, 1)
t3 = self._thread(lock, 1)
t4 = self._thread(lock, 1, heartbeat=True)
t5 = self._thread(lock, 1)
self.assertAlmostEqual(1, t1(), places=0)
self.assertAlmostEqual(2, t4(), places=0)
self.assertAlmostEqual(3, t2(), places=0)
@ -1053,8 +1053,8 @@ class ConnectionLockTestCase(test_utils.BaseTestCase):
self.assertAlmostEqual(5, t5(), places=0)
def test_heartbeat(self):
l = rabbit_driver.ConnectionLock()
t1 = self._thread(l, 1, heartbeat=True)
t2 = self._thread(l, 1)
lock = rabbit_driver.ConnectionLock()
t1 = self._thread(lock, 1, heartbeat=True)
t2 = self._thread(lock, 1)
self.assertAlmostEqual(1, t1(), places=0)
self.assertAlmostEqual(2, t2(), places=0)

View File

@ -152,20 +152,20 @@ class TestDispatcherFilter(test_utils.BaseTestCase):
context={},
match=False)),
('event_type_match',
dict(filter_rule=dict(event_type='^instance\.create'),
dict(filter_rule=dict(event_type=r'^instance\.create'),
publisher_id='compute01.manager',
event_type='instance.create.start',
context={},
match=True)),
('event_type_nomatch',
dict(filter_rule=dict(event_type='^instance\.delete'),
dict(filter_rule=dict(event_type=r'^instance\.delete'),
publisher_id='compute01.manager',
event_type='instance.create.start',
context={},
match=False)),
# this is only for simulation
('event_type_not_string',
dict(filter_rule=dict(event_type='^instance\.delete'),
dict(filter_rule=dict(event_type=r'^instance\.delete'),
publisher_id='compute01.manager',
event_type=['instance.swim', 'instance.fly'],
context={},
@ -220,7 +220,7 @@ class TestDispatcherFilter(test_utils.BaseTestCase):
context={},
match=False)),
('mix_match',
dict(filter_rule=dict(event_type='^instance\.create',
dict(filter_rule=dict(event_type=r'^instance\.create',
publisher_id='^compute',
context={'user': '^adm'}),
publisher_id='compute01.manager',

View File

@ -225,6 +225,7 @@ class TestMessagingNotifier(test_utils.BaseTestCase):
self.assertTrue(notifier.is_enabled())
TestMessagingNotifier.generate_scenarios()

View File

@ -504,6 +504,7 @@ class TestVersionCap(test_utils.BaseTestCase):
transport_options=None,
**kwargs)
TestVersionCap.generate_scenarios()

View File

@ -27,7 +27,7 @@ class TestExpectedExceptions(test_utils.BaseTestCase):
raise ValueError()
except Exception:
raise oslo_messaging.ExpectedException()
except oslo_messaging.ExpectedException as e:
except oslo_messaging.ExpectedException as e: # noqa: F841
self.assertIsInstance(e, oslo_messaging.ExpectedException)
self.assertTrue(hasattr(e, 'exc_info'))
self.assertIsInstance(e.exc_info[1], ValueError)

View File

@ -3,7 +3,7 @@
# process, which may cause wedges in the gate later.
# Hacking already pins down pep8, pyflakes and flake8
hacking>=1.1.0,<1.2.0 # Apache-2.0
hacking>=3.0,<3.1.0 # Apache-2.0
fixtures>=3.0.0 # Apache-2.0/BSD
mock>=2.0.0 # BSD

10
tox.ini
View File

@ -96,13 +96,19 @@ commands = bandit -r oslo_messaging -x tests -n5
show-source = True
enable-extensions = H203,H106
ignore = E731,H405
ignore = E731,H405,W504
exclude = .tox,dist,doc,*.egg,build,__init__.py
[hacking]
import_exceptions =
six.moves
local-check-factory = oslo_messaging.hacking.checks.factory
[flake8:local-plugins]
extension =
O321 = checks:check_oslo_namespace_imports
O322 = checks:check_mock_imports
O324 = checks:CheckForLoggingIssues
paths = ./oslo_messaging/hacking
[testenv:releasenotes]
whitelist_externals = rm