summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorHervé Beraud <hberaud@redhat.com>2020-08-21 15:12:08 +0200
committerHervé Beraud <hberaud@redhat.com>2020-09-22 12:35:37 +0200
commita997f09e5bd9ce98cc57f1a5380453ff167e47ca (patch)
treeee280ba8adc343c65c2c81abe7343b5f5bd9b876
parent4bae96d7f7f7f99f1a3d8836c98340644925b2e2 (diff)
downloadoslo-messaging-a997f09e5bd9ce98cc57f1a5380453ff167e47ca.tar.gz
Adding pre-commit
Introduced changes: - pre-commit config and rules - Add pre-commit to pep8 gate, Flake8 is covered in the pre-commit hooks. - Applying fixes for pre-commit compliance in all code. Also commit hash will be used instead of version tags in pre-commit to prevend arbitrary code from running in developer's machines. pre-commit will be used to: - trailing whitespace; - Replaces or checks mixed line ending (mixed-line-ending); - Forbid files which have a UTF-8 byte-order marker (check-byte-order-marker); - Checks that non-binary executables have a proper shebang (check-executables-have-shebangs); - Check for files that contain merge conflict strings (check-merge-conflict); - Check for debugger imports and py37+ breakpoint() calls in python source (debug-statements); - Attempts to load all yaml files to verify syntax (check-yaml); - Run flake8 checks (flake8) (local) For further details about tests please refer to: https://github.com/pre-commit/pre-commit-hooks Change-Id: Ibd0c3d64fdc5c293d9d676d33eab828d9fde971f Co-authored-by: Moisés Guimarães de Medeiros <moguimar@redhat.com>
-rw-r--r--.pre-commit-config.yaml35
-rw-r--r--doc/source/conf.py13
-rw-r--r--doc/source/reference/index.rst2
-rw-r--r--oslo_messaging/tests/drivers/test_amqp_driver.py12
-rw-r--r--oslo_messaging/tests/functional/utils.py14
-rw-r--r--[-rwxr-xr-x]oslo_messaging/tests/notify/test_notifier.py1
-rw-r--r--[-rwxr-xr-x]oslo_messaging/tests/rpc/test_client.py0
-rw-r--r--[-rwxr-xr-x]oslo_messaging/tests/rpc/test_dispatcher.py0
-rw-r--r--[-rwxr-xr-x]oslo_messaging/tests/test_transport.py0
-rw-r--r--test-requirements.txt1
-rwxr-xr-xtools/simulator.py9
-rw-r--r--tox.ini2
12 files changed, 71 insertions, 18 deletions
diff --git a/.pre-commit-config.yaml b/.pre-commit-config.yaml
new file mode 100644
index 0000000..9d94556
--- /dev/null
+++ b/.pre-commit-config.yaml
@@ -0,0 +1,35 @@
+# We from the Oslo project decided to pin repos based on the
+# commit hash instead of the version tag to prevend arbitrary
+# code from running in developer's machines. To update to a
+# newer version, run `pre-commit autoupdate` and then replace
+# the newer versions with their commit hash.
+
+default_language_version:
+ python: python3
+
+repos:
+ - repo: https://github.com/pre-commit/pre-commit-hooks
+ rev: ebc15addedad713c86ef18ae9632c88e187dd0af # v3.1.0
+ hooks:
+ - id: trailing-whitespace
+ # Replaces or checks mixed line ending
+ - id: mixed-line-ending
+ args: ['--fix', 'lf']
+ exclude: '.*\.(svg)$'
+ # Forbid files which have a UTF-8 byte-order marker
+ - id: check-byte-order-marker
+ # Checks that non-binary executables have a proper shebang
+ - id: check-executables-have-shebangs
+ # Check for files that contain merge conflict strings.
+ - id: check-merge-conflict
+ # Check for debugger imports and py37+ breakpoint()
+ # calls in python source
+ - id: debug-statements
+ - id: check-yaml
+ files: .*\.(yaml|yml)$
+ - repo: https://gitlab.com/pycqa/flake8
+ rev: 181bb46098dddf7e2d45319ea654b4b4d58c2840 # 3.8.3
+ hooks:
+ - id: flake8
+ additional_dependencies:
+ - hacking>=3.0.1,<3.1.0
diff --git a/doc/source/conf.py b/doc/source/conf.py
index f8bd9f9..9225989 100644
--- a/doc/source/conf.py
+++ b/doc/source/conf.py
@@ -1,4 +1,17 @@
# -*- coding: utf-8 -*-
+# Copyright (C) 2020 Red Hat, Inc.
+#
+# Licensed under the Apache License, Version 2.0 (the "License"); you may
+# not use this file except in compliance with the License. You may obtain
+# a copy of the License at
+#
+# http://www.apache.org/licenses/LICENSE-2.0
+#
+# Unless required by applicable law or agreed to in writing, software
+# distributed under the License is distributed on an "AS IS" BASIS, WITHOUT
+# WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. See the
+# License for the specific language governing permissions and limitations
+# under the License.
#
# Configuration file for the Sphinx documentation builder.
#
diff --git a/doc/source/reference/index.rst b/doc/source/reference/index.rst
index 97fd328..3ab44fd 100644
--- a/doc/source/reference/index.rst
+++ b/doc/source/reference/index.rst
@@ -16,4 +16,4 @@ Reference
notification_driver
notification_listener
serializer
- exceptions
+ exceptions
diff --git a/oslo_messaging/tests/drivers/test_amqp_driver.py b/oslo_messaging/tests/drivers/test_amqp_driver.py
index 7f39da8..1861014 100644
--- a/oslo_messaging/tests/drivers/test_amqp_driver.py
+++ b/oslo_messaging/tests/drivers/test_amqp_driver.py
@@ -1208,8 +1208,8 @@ class TestLinkRecovery(_AmqpBrokerTestCase):
else:
# unblock all link when RPC call is made
link.add_capacity(10)
- for l in self._blocked_links:
- l.add_capacity(10)
+ for li in self._blocked_links:
+ li.add_capacity(10)
self._broker.on_receiver_active = _on_active
self._broker.on_credit_exhausted = lambda link: None
@@ -1293,15 +1293,15 @@ class TestAddressing(test_utils.BaseTestCase):
{"msg": topic}, 2.0)
expected.append(topic)
- for l in rl:
- l.join(timeout=30)
+ for li in rl:
+ li.join(timeout=30)
# anycast will not evenly distribute an odd number of msgs
predicate = lambda: len(expected) == (nl[0].messages.qsize() +
nl[1].messages.qsize())
_wait_until(predicate, 30)
- for l in nl:
- l.kill(timeout=30)
+ for li in nl:
+ li.kill(timeout=30)
s1_payload = [m.message.get('msg') for m in rl[0].get_messages()]
s2_payload = [m.message.get('msg') for m in rl[1].get_messages()]
diff --git a/oslo_messaging/tests/functional/utils.py b/oslo_messaging/tests/functional/utils.py
index 371c170..b5a7a1a 100644
--- a/oslo_messaging/tests/functional/utils.py
+++ b/oslo_messaging/tests/functional/utils.py
@@ -280,13 +280,13 @@ class IsValidDistributionOf(object):
def match(self, actual):
errors = InvalidDistribution(self.original, actual)
- received = [[i for i in l] for l in actual]
+ received = [[idx for idx in act] for act in actual]
def _remove(obj, lists):
- for l in lists:
- if obj in l:
- front = l[0]
- l.remove(obj)
+ for li in lists:
+ if obj in li:
+ front = li[0]
+ li.remove(obj)
return front
return None
@@ -296,8 +296,8 @@ class IsValidDistributionOf(object):
errors.missing += item
elif item != o:
errors.wrong_order.append([item, o])
- for l in received:
- errors.extra += l
+ for li in received:
+ errors.extra += li
return errors or None
diff --git a/oslo_messaging/tests/notify/test_notifier.py b/oslo_messaging/tests/notify/test_notifier.py
index 832ee02..c36a432 100755..100644
--- a/oslo_messaging/tests/notify/test_notifier.py
+++ b/oslo_messaging/tests/notify/test_notifier.py
@@ -1,4 +1,3 @@
-
# Copyright 2013 Red Hat, Inc.
#
# Licensed under the Apache License, Version 2.0 (the "License"); you may
diff --git a/oslo_messaging/tests/rpc/test_client.py b/oslo_messaging/tests/rpc/test_client.py
index af1282a..af1282a 100755..100644
--- a/oslo_messaging/tests/rpc/test_client.py
+++ b/oslo_messaging/tests/rpc/test_client.py
diff --git a/oslo_messaging/tests/rpc/test_dispatcher.py b/oslo_messaging/tests/rpc/test_dispatcher.py
index 337593b..337593b 100755..100644
--- a/oslo_messaging/tests/rpc/test_dispatcher.py
+++ b/oslo_messaging/tests/rpc/test_dispatcher.py
diff --git a/oslo_messaging/tests/test_transport.py b/oslo_messaging/tests/test_transport.py
index 31fec16..31fec16 100755..100644
--- a/oslo_messaging/tests/test_transport.py
+++ b/oslo_messaging/tests/test_transport.py
diff --git a/test-requirements.txt b/test-requirements.txt
index cbed7dc..983c1c9 100644
--- a/test-requirements.txt
+++ b/test-requirements.txt
@@ -7,6 +7,7 @@ hacking>=3.0.1,<3.1.0 # Apache-2.0
fixtures>=3.0.0 # Apache-2.0/BSD
stestr>=2.0.0 # Apache-2.0
+pre-commit>=2.6.0 # MIT
testscenarios>=0.4 # Apache-2.0/BSD
testtools>=2.2.0 # MIT
oslotest>=3.2.0 # Apache-2.0
diff --git a/tools/simulator.py b/tools/simulator.py
index ab2529b..8b37f50 100755
--- a/tools/simulator.py
+++ b/tools/simulator.py
@@ -1,3 +1,4 @@
+#!/usr/bin/env python3
# Licensed under the Apache License, Version 2.0 (the "License"); you may
# not use this file except in compliance with the License. You may obtain
# a copy of the License at
@@ -10,8 +11,12 @@
# License for the specific language governing permissions and limitations
# under the License.
-import eventlet # noqa
-eventlet.monkey_patch() # noqa
+try:
+ # Avoid https://github.com/PyCQA/pycodestyle/issues/472
+ import eventlet
+ eventlet.monkey_patch()
+except ImportError:
+ raise
import argparse
import bisect
diff --git a/tox.ini b/tox.ini
index 9646cb2..bed65f9 100644
--- a/tox.ini
+++ b/tox.ini
@@ -19,7 +19,7 @@ commands = stestr run --slowest {posargs}
[testenv:pep8]
commands =
- flake8
+ pre-commit run -a
# run security linter
bandit -r oslo_messaging -x tests -n5