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: Ibe28b6b6bf3927e80816f0c5f1cb972fb6e2374b
This commit is contained in:
Andreas Jaeger 2020-03-30 08:09:44 +02:00
parent 25ebd01de3
commit d1dae85ac7
7 changed files with 18 additions and 20 deletions

View File

@ -19,7 +19,7 @@ import json
import eventlet import eventlet
try: try:
from mistralclient.api import client as mistralcli from mistralclient.api import client as mistralcli
except ImportError as mistral_import_error: except ImportError:
mistralcli = None mistralcli = None
from oslo_config import cfg from oslo_config import cfg
from oslo_log import log as logging from oslo_log import log as logging

View File

@ -13,7 +13,6 @@
# License for the specific language governing permissions and limitations # License for the specific language governing permissions and limitations
# under the License. # under the License.
import re
""" """
Guidelines for writing new hacking checks Guidelines for writing new hacking checks
@ -28,6 +27,10 @@ Guidelines for writing new hacking checks
- Add test cases for each new rule to /tests/unit/test_hacking.py - Add test cases for each new rule to /tests/unit/test_hacking.py
""" """
import re
from hacking import core
mutable_default_args = re.compile(r"^\s*def .+\((.+=\{\}|.+=\[\])") mutable_default_args = re.compile(r"^\s*def .+\((.+=\{\}|.+=\[\])")
assert_equal_end_with_none_re = re.compile( assert_equal_end_with_none_re = re.compile(
r"(.)*assertEqual\((\w|\.|\'|\"|\[|\])+, None\)") r"(.)*assertEqual\((\w|\.|\'|\"|\[|\])+, None\)")
@ -35,6 +38,7 @@ assert_equal_start_with_none_re = re.compile(
r"(.)*assertEqual\(None, (\w|\.|\'|\"|\[|\])+\)") r"(.)*assertEqual\(None, (\w|\.|\'|\"|\[|\])+\)")
@core.flake8ext
def assert_equal_none(logical_line): def assert_equal_none(logical_line):
"""Check for assertEqual(A, None) or assertEqual(None, A) sentences """Check for assertEqual(A, None) or assertEqual(None, A) sentences
@ -48,20 +52,16 @@ def assert_equal_none(logical_line):
yield (0, msg) yield (0, msg)
@core.flake8ext
def no_mutable_default_args(logical_line): def no_mutable_default_args(logical_line):
msg = "M322: Method's default argument shouldn't be mutable!" msg = "M322: Method's default argument shouldn't be mutable!"
if mutable_default_args.match(logical_line): if mutable_default_args.match(logical_line):
yield (0, msg) yield (0, msg)
@core.flake8ext
def check_no_basestring(logical_line): def check_no_basestring(logical_line):
if re.search(r"\bbasestring\b", logical_line): if re.search(r"\bbasestring\b", logical_line):
msg = ("M326: basestring is not Python3-compatible, use " msg = ("M326: basestring is not Python3-compatible, use "
"six.string_types instead.") "six.string_types instead.")
yield(0, msg) yield(0, msg)
def factory(register):
register(assert_equal_none)
register(no_mutable_default_args)
register(check_no_basestring)

View File

@ -18,7 +18,7 @@ import re
try: try:
# integration with congress is optional # integration with congress is optional
import congressclient.v1.client as congress_client import congressclient.v1.client as congress_client
except ImportError as congress_client_import_error: except ImportError:
congress_client = None congress_client = None
from oslo_log import log as logging from oslo_log import log as logging

View File

@ -18,7 +18,7 @@ import random
try: try:
from mistralclient.api import client as mistralcli from mistralclient.api import client as mistralcli
except ImportError as mistral_import_error: except ImportError:
mistralcli = None mistralcli = None
import mock import mock

View File

@ -104,11 +104,3 @@ class HackingTestCase(base.MuranoTestCase):
self.assertEqual(0, len(list(checks.check_no_basestring( self.assertEqual(0, len(list(checks.check_no_basestring(
"isinstance('foo', six.string_types)")))) "isinstance('foo', six.string_types)"))))
def test_factory(self):
mock_register = mock.MagicMock()
checks.factory(mock_register)
expected = [
mock.call(checks.no_mutable_default_args),
mock.call(checks.check_no_basestring)]
mock_register.assert_has_calls(expected)

View File

@ -1,7 +1,7 @@
# The order of packages is significant, because pip processes them in the order # 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 # of appearance. Changing the order has an impact on the overall integration
# process, which may cause wedges in the gate later. # process, which may cause wedges in the gate later.
hacking>=1.1.0,<1.2.0 # Apache-2.0 hacking>=3.0,<4.0.0 # Apache-2.0
coverage!=4.4,>=4.0 # Apache-2.0 coverage!=4.4,>=4.0 # Apache-2.0
fixtures>=3.0.0 # Apache-2.0/BSD fixtures>=3.0.0 # Apache-2.0/BSD

View File

@ -99,10 +99,16 @@ ignore = W605,W504,W503,E123,H405
exclude=.venv,.git,.tox,dist,doc,*lib/python*,*egg,build exclude=.venv,.git,.tox,dist,doc,*lib/python*,*egg,build
[hacking] [hacking]
local-check-factory = murano.hacking.checks.factory
import_exceptions = oslo.db.sqlalchemy.test_base, import_exceptions = oslo.db.sqlalchemy.test_base,
murano.common.i18n murano.common.i18n
[flake8:local-plugins]
extension =
M318 = checks:assert_equal_none
M322 = checks:no_mutable_default_args
M326 = checks:check_no_basestring
paths = ./murano/hacking
[testenv:bindep] [testenv:bindep]
# Do not install any requirements. We want this to be fast and work even if # Do not install any requirements. We want this to be fast and work even if
# system dependencies are missing, since it's used to tell you what system # system dependencies are missing, since it's used to tell you what system