From 2c99ddc3ef2bdc8b350451ef8e0e3a7a3954bef1 Mon Sep 17 00:00:00 2001 From: Andreas Jaeger Date: Wed, 1 Apr 2020 19:56:00 +0200 Subject: [PATCH] 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 --- lower-constraints.txt | 2 -- mistral/hacking/checks.py | 22 +++++++++++----------- test-requirements.txt | 2 +- tox.ini | 13 ++++++++++++- 4 files changed, 24 insertions(+), 15 deletions(-) diff --git a/lower-constraints.txt b/lower-constraints.txt index a51f4cf14..170894744 100644 --- a/lower-constraints.txt +++ b/lower-constraints.txt @@ -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 diff --git a/mistral/hacking/checks.py b/mistral/hacking/checks.py index 78dd691ea..5ddc809c5 100644 --- a/mistral/hacking/checks.py +++ b/mistral/hacking/checks.py @@ -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) diff --git a/test-requirements.txt b/test-requirements.txt index a2fdf7283..eb5002aa7 100644 --- a/test-requirements.txt +++ b/test-requirements.txt @@ -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 diff --git a/tox.ini b/tox.ini index 5490dae7c..34ac76a0c 100644 --- a/tox.ini +++ b/tox.ini @@ -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