diff options
author | Zuul <zuul@review.opendev.org> | 2020-04-04 03:41:33 +0000 |
---|---|---|
committer | Gerrit Code Review <review@openstack.org> | 2020-04-04 03:41:33 +0000 |
commit | 341c6c4cccce75a125825093272c34d17ca7a23f (patch) | |
tree | c383743e20c8959dd20214b9a68fe75a43bf92da | |
parent | 9d8fb455d5d7111424091800ebfb6147cfde2871 (diff) | |
parent | f33c2130511f09a6014f45c12345aa158ab9fb6d (diff) | |
download | trove-341c6c4cccce75a125825093272c34d17ca7a23f.tar.gz |
Merge "Update hacking for Python3"
-rw-r--r-- | lower-constraints.txt | 4 | ||||
-rw-r--r-- | test-requirements.txt | 2 | ||||
-rw-r--r-- | tox.ini | 9 | ||||
-rw-r--r-- | trove/hacking/checks.py | 19 | ||||
-rw-r--r-- | trove/tests/unittests/hacking/test_check.py | 17 |
5 files changed, 24 insertions, 27 deletions
diff --git a/lower-constraints.txt b/lower-constraints.txt index 51caa274..81b58e1e 100644 --- a/lower-constraints.txt +++ b/lower-constraints.txt @@ -33,13 +33,11 @@ eventlet==0.18.2 extras==1.0.0 fasteners==0.14.1 fixtures==3.0.0 -flake8==2.5.5 future==0.16.0 futurist==1.6.0 gitdb2==2.0.3 GitPython==2.1.8 greenlet==0.4.13 -hacking==0.12.0 httplib2==0.9.1 idna==2.6 imagesize==1.0.0 @@ -96,7 +94,6 @@ passlib==1.7.0 Paste==2.0.2 PasteDeploy==1.5.0 pbr==2.0.0 -pep8==1.7.1 pexpect==3.1 pika-pool==0.1.3 pika==0.10.0 @@ -106,7 +103,6 @@ psycopg2==2.6.2 ptyprocess==0.5.2 pycadf==2.7.0 pycparser==2.18 -pyflakes==1.0.0 Pygments==2.2.0 pyinotify==0.9.6 pylint==1.9.2 # GPLv2 diff --git a/test-requirements.txt b/test-requirements.txt index 4080244b..c8dbd865 100644 --- a/test-requirements.txt +++ b/test-requirements.txt @@ -2,7 +2,7 @@ # of appearance. Changing the order has an impact on the overall integration # process, which may cause wedges in the gate later. # Hacking already pins down pep8, pyflakes and flake8 -hacking!=0.13.0,<0.14,>=0.12.0 # Apache-2.0 +hacking>=3.0,<3.1.0 # Apache-2.0 bandit>=1.1.0 # Apache-2.0 coverage!=4.4,>=4.0 # Apache-2.0 nose>=1.3.7 # LGPL @@ -65,7 +65,14 @@ filename=*.py,trove-*,app.wsgi [hacking] import_exceptions = trove.common.i18n -local-check-factory = trove.hacking.checks.factory + +[flake8:local-plugins] +extension = + T103= checks:check_raised_localized_exceptions + T104 = checks:check_no_basestring + T105 = checks:no_translate_logs + N335 = checks:assert_raises_regexp +paths = ./trove/hacking [testenv:api-ref] # This environment is called from CI scripts to test and publish diff --git a/trove/hacking/checks.py b/trove/hacking/checks.py index 26d30ec9..851ddd66 100644 --- a/trove/hacking/checks.py +++ b/trove/hacking/checks.py @@ -12,7 +12,9 @@ import re -import pep8 +import pycodestyle + +from hacking import core _all_log_levels = ( 'critical', @@ -34,6 +36,7 @@ def _translation_is_not_expected(filename): return any(pat in filename for pat in ["/tests/"]) +@core.flake8ext def check_raised_localized_exceptions(logical_line, filename): """T103 - Untranslated exception message. :param logical_line: The logical line to check. @@ -55,6 +58,7 @@ def check_raised_localized_exceptions(logical_line, filename): yield (logical_line.index(exception_msg), msg) +@core.flake8ext def check_no_basestring(logical_line): """T104 - Don't use basestring, use six.string_types instead basestring is not supported by py3, using six.string_types to ensure @@ -66,7 +70,8 @@ def check_no_basestring(logical_line): yield(0, msg) -def no_translate_logs(logical_line, physical_line, filename): +@core.flake8ext +def no_translate_logs(physical_line, logical_line, filename): """T105 - Log messages shouldn't be translated from the Pike release. :param logical_line: The logical line to check. @@ -79,7 +84,7 @@ def no_translate_logs(logical_line, physical_line, filename): if _translation_is_not_expected(filename): return - if pep8.noqa(physical_line): + if pycodestyle.noqa(physical_line): return msg = "T105: Log message shouldn't be translated." @@ -90,6 +95,7 @@ def no_translate_logs(logical_line, physical_line, filename): asse_raises_regexp = re.compile(r"assertRaisesRegexp\(") +@core.flake8ext def assert_raises_regexp(logical_line): """Check for usage of deprecated assertRaisesRegexp @@ -99,10 +105,3 @@ def assert_raises_regexp(logical_line): if res: yield (0, "N335: assertRaisesRegex must be used instead " "of assertRaisesRegexp") - - -def factory(register): - register(check_raised_localized_exceptions) - register(check_no_basestring) - register(no_translate_logs) - register(assert_raises_regexp) diff --git a/trove/tests/unittests/hacking/test_check.py b/trove/tests/unittests/hacking/test_check.py index d2874b44..3f6c4021 100644 --- a/trove/tests/unittests/hacking/test_check.py +++ b/trove/tests/unittests/hacking/test_check.py @@ -11,7 +11,7 @@ # under the License. import mock -import pep8 +import pycodestyle import textwrap from trove.hacking import checks as tc @@ -28,11 +28,6 @@ class HackingTestCase(trove_testtools.TestCase): def assertLineFails(self, func, *args): self.assertIsInstance(next(func(*args)), tuple) - def test_factory(self): - def check_callable(fn): - self.assertTrue(hasattr(fn, '__call__')) - self.assertIsNone(tc.factory(check_callable)) - def test_log_translations(self): all_log_levels = ( 'critical', @@ -89,20 +84,20 @@ class HackingTestCase(trove_testtools.TestCase): 0, len(list(tc.check_no_basestring("this basestring is good)")))) - # We are patching pep8 so that only the check under test is actually + # We are patching pycodestyle so that only the check under test is actually # installed. - @mock.patch('pep8._checks', + @mock.patch('pycodestyle._checks', {'physical_line': {}, 'logical_line': {}, 'tree': {}}) def _run_check(self, code, checker, filename=None): - pep8.register_check(checker) + pycodestyle.register_check(checker) lines = textwrap.dedent(code).strip().splitlines(True) - checker = pep8.Checker(filename=filename, lines=lines) + checker = pycodestyle.Checker(filename=filename, lines=lines) # NOTE(sdague): the standard reporter has printing to stdout # as a normal part of check_all, which bleeds through to the # test output stream in an unhelpful way. This blocks that printing. - with mock.patch('pep8.StandardReport.get_file_results'): + with mock.patch('pycodestyle.StandardReport.get_file_results'): checker.check_all() checker.report._deferred_print.sort() return checker.report._deferred_print |