Browse Source

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
tags/9.0.0.0rc1
Andreas Jaeger 3 months ago
parent
commit
d1dae85ac7
7 changed files with 18 additions and 20 deletions
  1. +1
    -1
      murano/engine/system/workflowclient.py
  2. +7
    -7
      murano/hacking/checks.py
  3. +1
    -1
      murano/policy/model_policy_enforcer.py
  4. +1
    -1
      murano/tests/unit/engine/system/test_workflowclient.py
  5. +0
    -8
      murano/tests/unit/test_hacking.py
  6. +1
    -1
      test-requirements.txt
  7. +7
    -1
      tox.ini

+ 1
- 1
murano/engine/system/workflowclient.py View File

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


+ 7
- 7
murano/hacking/checks.py View File

@@ -13,7 +13,6 @@
# License for the specific language governing permissions and limitations
# under the License.

import re

"""
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
"""

import re

from hacking import core

mutable_default_args = re.compile(r"^\s*def .+\((.+=\{\}|.+=\[\])")
assert_equal_end_with_none_re = re.compile(
r"(.)*assertEqual\((\w|\.|\'|\"|\[|\])+, None\)")
@@ -35,6 +38,7 @@ assert_equal_start_with_none_re = re.compile(
r"(.)*assertEqual\(None, (\w|\.|\'|\"|\[|\])+\)")


@core.flake8ext
def assert_equal_none(logical_line):
"""Check for assertEqual(A, None) or assertEqual(None, A) sentences

@@ -48,20 +52,16 @@ def assert_equal_none(logical_line):
yield (0, msg)


@core.flake8ext
def no_mutable_default_args(logical_line):
msg = "M322: Method's default argument shouldn't be mutable!"
if mutable_default_args.match(logical_line):
yield (0, msg)


@core.flake8ext
def check_no_basestring(logical_line):
if re.search(r"\bbasestring\b", logical_line):
msg = ("M326: basestring is not Python3-compatible, use "
"six.string_types instead.")
yield(0, msg)


def factory(register):
register(assert_equal_none)
register(no_mutable_default_args)
register(check_no_basestring)

+ 1
- 1
murano/policy/model_policy_enforcer.py View File

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



+ 1
- 1
murano/tests/unit/engine/system/test_workflowclient.py View File

@@ -18,7 +18,7 @@ import random

try:
from mistralclient.api import client as mistralcli
except ImportError as mistral_import_error:
except ImportError:
mistralcli = None

import mock


+ 0
- 8
murano/tests/unit/test_hacking.py View File

@@ -104,11 +104,3 @@ class HackingTestCase(base.MuranoTestCase):

self.assertEqual(0, len(list(checks.check_no_basestring(
"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)

+ 1
- 1
test-requirements.txt View File

@@ -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>=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
fixtures>=3.0.0 # Apache-2.0/BSD


+ 7
- 1
tox.ini View File

@@ -99,10 +99,16 @@ ignore = W605,W504,W503,E123,H405
exclude=.venv,.git,.tox,dist,doc,*lib/python*,*egg,build

[hacking]
local-check-factory = murano.hacking.checks.factory
import_exceptions = oslo.db.sqlalchemy.test_base,
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]
# 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


Loading…
Cancel
Save