summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorAndreas Jaeger <aj@suse.com>2020-03-27 19:16:32 +0100
committerAndreas Jaeger <jaegerandi@gmail.com>2020-03-30 13:49:29 +0000
commit7f638bb493571f2a6d30d3679945119d6596cfa7 (patch)
treee348dc8e9eaf5f8e99cda8b222c8c704da025987
parentd87618b24fc9b11b5ae216e241e1a4d1d4fb8e72 (diff)
downloadoslo-messaging-7f638bb493571f2a6d30d3679945119d6596cfa7.tar.gz
Update hacking for Python312.1.0
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
-rw-r--r--oslo_messaging/_drivers/impl_rabbit.py8
-rw-r--r--oslo_messaging/hacking/checks.py23
-rw-r--r--oslo_messaging/notify/filter.py2
-rw-r--r--oslo_messaging/notify/listener.py3
-rw-r--r--oslo_messaging/tests/drivers/test_impl_rabbit.py30
-rw-r--r--oslo_messaging/tests/notify/test_dispatcher.py8
-rwxr-xr-xoslo_messaging/tests/notify/test_notifier.py1
-rwxr-xr-xoslo_messaging/tests/rpc/test_client.py1
-rw-r--r--oslo_messaging/tests/test_expected_exceptions.py2
-rw-r--r--test-requirements.txt2
-rw-r--r--tox.ini10
11 files changed, 50 insertions, 40 deletions
diff --git a/oslo_messaging/_drivers/impl_rabbit.py b/oslo_messaging/_drivers/impl_rabbit.py
index 78c5f55..46c5ae0 100644
--- a/oslo_messaging/_drivers/impl_rabbit.py
+++ b/oslo_messaging/_drivers/impl_rabbit.py
@@ -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',
diff --git a/oslo_messaging/hacking/checks.py b/oslo_messaging/hacking/checks.py
index 4a6a45f..3925ab4 100644
--- a/oslo_messaging/hacking/checks.py
+++ b/oslo_messaging/hacking/checks.py
@@ -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)
diff --git a/oslo_messaging/notify/filter.py b/oslo_messaging/notify/filter.py
index f6d6098..44eb827 100644
--- a/oslo_messaging/notify/filter.py
+++ b/oslo_messaging/notify/filter.py
@@ -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.
diff --git a/oslo_messaging/notify/listener.py b/oslo_messaging/notify/listener.py
index de9a26a..f069150 100644
--- a/oslo_messaging/notify/listener.py
+++ b/oslo_messaging/notify/listener.py
@@ -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
diff --git a/oslo_messaging/tests/drivers/test_impl_rabbit.py b/oslo_messaging/tests/drivers/test_impl_rabbit.py
index b7ab4f3..9212196 100644
--- a/oslo_messaging/tests/drivers/test_impl_rabbit.py
+++ b/oslo_messaging/tests/drivers/test_impl_rabbit.py
@@ -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)
diff --git a/oslo_messaging/tests/notify/test_dispatcher.py b/oslo_messaging/tests/notify/test_dispatcher.py
index 9780cd3..93a1467 100644
--- a/oslo_messaging/tests/notify/test_dispatcher.py
+++ b/oslo_messaging/tests/notify/test_dispatcher.py
@@ -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',
diff --git a/oslo_messaging/tests/notify/test_notifier.py b/oslo_messaging/tests/notify/test_notifier.py
index 02bb8a4..2d6b771 100755
--- a/oslo_messaging/tests/notify/test_notifier.py
+++ b/oslo_messaging/tests/notify/test_notifier.py
@@ -225,6 +225,7 @@ class TestMessagingNotifier(test_utils.BaseTestCase):
self.assertTrue(notifier.is_enabled())
+
TestMessagingNotifier.generate_scenarios()
diff --git a/oslo_messaging/tests/rpc/test_client.py b/oslo_messaging/tests/rpc/test_client.py
index 6c54625..4063562 100755
--- a/oslo_messaging/tests/rpc/test_client.py
+++ b/oslo_messaging/tests/rpc/test_client.py
@@ -504,6 +504,7 @@ class TestVersionCap(test_utils.BaseTestCase):
transport_options=None,
**kwargs)
+
TestVersionCap.generate_scenarios()
diff --git a/oslo_messaging/tests/test_expected_exceptions.py b/oslo_messaging/tests/test_expected_exceptions.py
index 40c4a22..770c74e 100644
--- a/oslo_messaging/tests/test_expected_exceptions.py
+++ b/oslo_messaging/tests/test_expected_exceptions.py
@@ -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)
diff --git a/test-requirements.txt b/test-requirements.txt
index da96f05..7666105 100644
--- a/test-requirements.txt
+++ b/test-requirements.txt
@@ -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
diff --git a/tox.ini b/tox.ini
index 42af5fb..41536f1 100644
--- a/tox.ini
+++ b/tox.ini
@@ -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