Update hacking for Python3

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

Update local hacking checks for new flake8.

Remove hacking and friends from lower-constraints, they are not
needed in installations.

Change-Id: Ia4740a1dc343d7a4a303674d9377bc64f6df762b
This commit is contained in:
Andreas Jaeger 2020-04-01 19:56:00 +02:00
parent 869cac9def
commit 2c99ddc3ef
4 changed files with 24 additions and 15 deletions

View File

@ -7,8 +7,6 @@ doc8==0.6.0
dogpile.cache==0.6.2
eventlet==0.20.0
fixtures==3.0.0
flake8==2.6.2
hacking==1.1.0
Jinja2==2.10
jsonschema==2.6.0
keystonemiddleware==4.18.0

View File

@ -26,12 +26,14 @@ import ast
import re
import six
from hacking import core
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]+")
@core.flake8ext
def no_assert_equal_true_false(logical_line):
"""Check for assertTrue/assertFalse sentences
@ -47,6 +49,7 @@ def no_assert_equal_true_false(logical_line):
"Use assertTrue(A) or assertFalse(A) instead")
@core.flake8ext
def no_assert_true_false_is_not(logical_line):
"""Check for assertIs/assertIsNot sentences
@ -60,6 +63,7 @@ def no_assert_true_false_is_not(logical_line):
"Use assertIs(A, B) or assertIsNot(A, B) instead")
@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'.") % (
@ -78,12 +82,14 @@ def check_oslo_namespace_imports(logical_line):
yield(0, msg)
@core.flake8ext
def check_python3_xrange(logical_line):
if re.search(r"\bxrange\s*\(", logical_line):
yield(0, "M327: Do not use xrange(). 'xrange()' is not compatible "
"with Python 3. Use range() or six.moves.range() instead.")
@core.flake8ext
def check_python3_no_iteritems(logical_line):
msg = ("M328: Use six.iteritems() instead of dict.iteritems().")
@ -91,6 +97,7 @@ def check_python3_no_iteritems(logical_line):
yield(0, msg)
@core.flake8ext
def check_python3_no_iterkeys(logical_line):
msg = ("M329: Use six.iterkeys() instead of dict.iterkeys().")
@ -98,6 +105,7 @@ def check_python3_no_iterkeys(logical_line):
yield(0, msg)
@core.flake8ext
def check_python3_no_itervalues(logical_line):
msg = ("M330: Use six.itervalues() instead of dict.itervalues().")
@ -144,6 +152,9 @@ class BaseASTChecker(ast.NodeVisitor):
class CheckForLoggingIssues(BaseASTChecker):
name = "check_for_logging_issues"
version = "1.0"
CHECK_DESC = ('M001 Using the deprecated Logger.warn')
LOG_MODULES = ('logging', 'oslo_log.log')
@ -262,14 +273,3 @@ class CheckForLoggingIssues(BaseASTChecker):
self.add_error(node.args[0])
return super(CheckForLoggingIssues, self).generic_visit(node)
def factory(register):
register(no_assert_equal_true_false)
register(no_assert_true_false_is_not)
register(check_oslo_namespace_imports)
register(CheckForLoggingIssues)
register(check_python3_no_iteritems)
register(check_python3_no_iterkeys)
register(check_python3_no_itervalues)
register(check_python3_xrange)

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 # Apache-2.0
hacking>=3.0,<3.1.0 # Apache-2.0
coverage!=4.4,>=4.0 # Apache-2.0
doc8>=0.6.0 # Apache-2.0

13
tox.ini
View File

@ -112,9 +112,20 @@ extensions = .rst, .yaml, .mistral
max-line-length = 80
[hacking]
local-check-factory = mistral.hacking.checks.factory
import_exceptions = mistral._i18n
[flake8:local-plugins]
extension =
M001 = checks:CheckForLoggingIssues
M319 = checks:no_assert_equal_true_false
M320 = checks:no_assert_true_false_is_not
M327 = checks:check_python3_xrange
M328 = checks:check_python3_no_iteritems
M329 = checks:check_python3_no_iterkeys
M330 = checks:check_python3_no_itervalues
O323 = checks:check_oslo_namespace_imports
paths = ./mistral/hacking
[testenv:lower-constraints]
deps =
-c{toxinidir}/lower-constraints.txt