From c096099416013414cb476e17b6bcfcbabee3856e Mon Sep 17 00:00:00 2001 From: Andreas Jaeger Date: Tue, 31 Mar 2020 17:04:21 +0200 Subject: [PATCH] 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. Remove hacking and friends from lower-constraints, those are not needed for co-installing. Change-Id: I59f0854c089a6ed4f0c4dad7755f946dc95ada3a --- keystoneauth1/access/__init__.py | 8 ++++---- keystoneauth1/extras/_saml2/v3/saml2.py | 6 +++--- keystoneauth1/fixture/__init__.py | 2 ++ keystoneauth1/hacking/checks.py | 7 +++---- keystoneauth1/identity/generic/base.py | 2 +- keystoneauth1/identity/v3/__init__.py | 2 ++ keystoneauth1/loading/__init__.py | 2 ++ keystoneauth1/tests/unit/loading/test_conf.py | 6 +++--- keystoneauth1/tests/unit/loading/test_loading.py | 6 +++--- keystoneauth1/tests/unit/test_hacking_checks.py | 10 +++++----- lower-constraints.txt | 6 ------ test-requirements.txt | 2 +- tox.ini | 10 +++++++--- 13 files changed, 36 insertions(+), 33 deletions(-) diff --git a/keystoneauth1/access/__init__.py b/keystoneauth1/access/__init__.py index 273d9cdd..b7e474a4 100644 --- a/keystoneauth1/access/__init__.py +++ b/keystoneauth1/access/__init__.py @@ -13,7 +13,7 @@ from keystoneauth1.access.access import * # noqa -__all__ = ('AccessInfo', - 'AccessInfoV2', - 'AccessInfoV3', - 'create') +__all__ = ('AccessInfo', # noqa: F405 + 'AccessInfoV2', # noqa: F405 + 'AccessInfoV3', # noqa: F405 + 'create') # noqa: F405 diff --git a/keystoneauth1/extras/_saml2/v3/saml2.py b/keystoneauth1/extras/_saml2/v3/saml2.py index 1cc58645..ab3ab933 100644 --- a/keystoneauth1/extras/_saml2/v3/saml2.py +++ b/keystoneauth1/extras/_saml2/v3/saml2.py @@ -77,10 +77,10 @@ def _response_xml(response, name): def _str_from_xml(xml, path): - l = xml.xpath(path, namespaces=_XML_NAMESPACES) - if len(l) != 1: + li = xml.xpath(path, namespaces=_XML_NAMESPACES) + if len(li) != 1: raise IndexError('%s should provide a single element list' % path) - return l[0] + return li[0] class _SamlAuth(requests.auth.AuthBase): diff --git a/keystoneauth1/fixture/__init__.py b/keystoneauth1/fixture/__init__.py index 9981f191..f5d17069 100644 --- a/keystoneauth1/fixture/__init__.py +++ b/keystoneauth1/fixture/__init__.py @@ -19,6 +19,8 @@ main client (keystoneauth or other). Because of this there may be dependencies from this module on libraries that are only available in testing. """ +# flake8: noqa: F405 + from keystoneauth1.fixture.discovery import * # noqa from keystoneauth1.fixture import exception from keystoneauth1.fixture.plugin import * # noqa diff --git a/keystoneauth1/hacking/checks.py b/keystoneauth1/hacking/checks.py index 9e4a9424..ae25459f 100644 --- a/keystoneauth1/hacking/checks.py +++ b/keystoneauth1/hacking/checks.py @@ -21,7 +21,10 @@ errors so that core devs don't have to. import re +from hacking import core + +@core.flake8ext def check_oslo_namespace_imports(logical_line, blank_before, filename): oslo_namespace_imports = re.compile( r"(((from)|(import))\s+oslo\.)|(from\s+oslo\s+import\s+)") @@ -31,7 +34,3 @@ def check_oslo_namespace_imports(logical_line, blank_before, filename): logical_line.replace('oslo.', 'oslo_'), logical_line) yield(0, msg) - - -def factory(register): - register(check_oslo_namespace_imports) diff --git a/keystoneauth1/identity/generic/base.py b/keystoneauth1/identity/generic/base.py index 543f85e5..c888be4b 100644 --- a/keystoneauth1/identity/generic/base.py +++ b/keystoneauth1/identity/generic/base.py @@ -213,7 +213,7 @@ class BaseGenericPlugin(base.BaseIdentityPlugin): # implementation to respond with a dict without the subclass modifying # it to add their own data in case the subclass doesn't support caching if not _implemented: - raise NotImplemented() + raise NotImplementedError() return {'auth_url': self.auth_url, 'project_id': self._project_id, diff --git a/keystoneauth1/identity/v3/__init__.py b/keystoneauth1/identity/v3/__init__.py index e3e666bb..052fbd97 100644 --- a/keystoneauth1/identity/v3/__init__.py +++ b/keystoneauth1/identity/v3/__init__.py @@ -10,6 +10,8 @@ # License for the specific language governing permissions and limitations # under the License. +# flake8: noqa: F405 + from keystoneauth1.identity.v3.application_credential import * # noqa from keystoneauth1.identity.v3.base import * # noqa from keystoneauth1.identity.v3.federation import * # noqa diff --git a/keystoneauth1/loading/__init__.py b/keystoneauth1/loading/__init__.py index e31b2f42..371c18c0 100644 --- a/keystoneauth1/loading/__init__.py +++ b/keystoneauth1/loading/__init__.py @@ -10,6 +10,8 @@ # License for the specific language governing permissions and limitations # under the License. +# flake8: noqa: F405 + from keystoneauth1.loading import adapter from keystoneauth1.loading.base import * # noqa from keystoneauth1.loading import cli diff --git a/keystoneauth1/tests/unit/loading/test_conf.py b/keystoneauth1/tests/unit/loading/test_conf.py index ce3e9abf..2f99388a 100644 --- a/keystoneauth1/tests/unit/loading/test_conf.py +++ b/keystoneauth1/tests/unit/loading/test_conf.py @@ -113,9 +113,9 @@ class ConfTests(utils.TestCase): self.assertEqual(auth_type, e.name) def test_loading_with_no_data(self): - l = loading.load_auth_from_conf_options(self.conf_fixture.conf, - self.GROUP) - self.assertIsNone(l) + lo = loading.load_auth_from_conf_options(self.conf_fixture.conf, + self.GROUP) + self.assertIsNone(lo) @mock.patch('stevedore.DriverManager') def test_other_params(self, m): diff --git a/keystoneauth1/tests/unit/loading/test_loading.py b/keystoneauth1/tests/unit/loading/test_loading.py index ce07c1fd..b7681def 100644 --- a/keystoneauth1/tests/unit/loading/test_loading.py +++ b/keystoneauth1/tests/unit/loading/test_loading.py @@ -55,14 +55,14 @@ class LoadingTests(utils.TestCase): Plugin, Loader = utils.create_plugin(opts=opts) - l = Loader() + lo = Loader() v = uuid.uuid4().hex - p1 = l.load_from_options(b=v) + p1 = lo.load_from_options(b=v) self.assertEqual(v, p1['b']) e = self.assertRaises(exceptions.MissingRequiredOptions, - l.load_from_options, + lo.load_from_options, a=v) self.assertEqual(1, len(e.options)) diff --git a/keystoneauth1/tests/unit/test_hacking_checks.py b/keystoneauth1/tests/unit/test_hacking_checks.py index b81ede77..958b6733 100644 --- a/keystoneauth1/tests/unit/test_hacking_checks.py +++ b/keystoneauth1/tests/unit/test_hacking_checks.py @@ -13,7 +13,7 @@ import textwrap import mock -import pep8 +import pycodestyle import testtools from keystoneauth1.hacking import checks @@ -22,16 +22,16 @@ from keystoneauth1.tests.unit import keystoneauth_fixtures class TestCheckOsloNamespaceImports(testtools.TestCase): - # 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): - pep8.register_check(checks.check_oslo_namespace_imports) + pycodestyle.register_check(checks.check_oslo_namespace_imports) lines = textwrap.dedent(code).strip().splitlines(True) - checker = pep8.Checker(lines=lines) + checker = pycodestyle.Checker(lines=lines) checker.check_all() checker.report._deferred_print.sort() return checker.report._deferred_print diff --git a/lower-constraints.txt b/lower-constraints.txt index df124226..2d288fda 100644 --- a/lower-constraints.txt +++ b/lower-constraints.txt @@ -13,13 +13,9 @@ docutils==0.14 dulwich==0.19.0 extras==1.0.0 fixtures==3.0.0 -flake8-docstrings==0.2.1.post1 -flake8-import-order==0.17.1 -flake8==2.5.5 future==0.16.0 gitdb2==2.0.3 GitPython==2.1.8 -hacking==0.12.0 idna==2.6 imagesize==1.0.0 iso8601==0.1.11 @@ -46,10 +42,8 @@ packaging==17.1 Parsley==1.3 pbr==2.0.0 pep257==0.7.0 -pep8==1.5.7 prettytable==0.7.2 pycodestyle==2.3.1 -pyflakes==0.8.1 Pygments==2.2.0 pyparsing==2.2.0 pyperclip==1.6.0 diff --git a/test-requirements.txt b/test-requirements.txt index 879b3f49..7d3622ac 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!=0.13.0,<0.14,>=0.12.0 # Apache-2.0 +hacking>=3.0,<3.1.0 # Apache-2.0 flake8-docstrings==0.2.1.post1 # MIT flake8-import-order>=0.17.1 #LGPLv3 diff --git a/tox.ini b/tox.ini index f9a7cb4e..97ff0cec 100644 --- a/tox.ini +++ b/tox.ini @@ -54,7 +54,9 @@ commands = oslo_debug_helper -t keystoneauth1/tests {posargs} # D103: Missing docstring in public function # D104: Missing docstring in public package # D203: 1 blank line required before class docstring (deprecated in pep257) -ignore = D100,D101,D102,D103,D104,D203 +# W503 line break before binary operator +# W504 line break after binary operator +ignore = D100,D101,D102,D103,D104,D203,W503,W504 # H106: Don’t put vim configuration in source files # H203: Use assertIs(Not)None to check for None enable-extensions=H106,H203 @@ -89,8 +91,10 @@ deps = -r{toxinidir}/doc/requirements.txt commands = sphinx-build -a -E -W -d releasenotes/build/doctrees -b html releasenotes/source releasenotes/build/html -[hacking] -local-check-factory = keystoneauth1.hacking.checks.factory +[flake8:local-plugins] +extension = + K333 = checks:check_oslo_namespace_imports +paths = ./keystoneauth1/hacking [testenv:lower-constraints] deps =