From 454489762cc49a7c6cdaac4ad759c1b8c1c1c57c Mon Sep 17 00:00:00 2001 From: Andreas Jaeger Date: Fri, 3 Apr 2020 22:07:16 +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 by updated hacking version. Remove hacking and friends from lower-constraints, they are not needed during installation. Change-Id: I7ef5ac8a89e94f5da97780198619b6facc86ecfe --- ansible/library/kolla_toolbox.py | 10 +++++----- kolla_ansible/tests/unit/test_address_filters.py | 6 +++--- kolla_ansible/tests/unit/test_filters.py | 6 +++--- lower-constraints.txt | 4 ---- test-requirements.txt | 2 +- tests/test_kolla_docker.py | 2 +- tools/validate-all-file.py | 1 + tools/validate-yaml.py | 1 + tox.ini | 5 +++++ 9 files changed, 20 insertions(+), 17 deletions(-) diff --git a/ansible/library/kolla_toolbox.py b/ansible/library/kolla_toolbox.py index 276661df29..c860c33bc9 100644 --- a/ansible/library/kolla_toolbox.py +++ b/ansible/library/kolla_toolbox.py @@ -96,10 +96,10 @@ EXAMPLES = ''' ''' -JSON_REG = re.compile('^(?P\w+) \| (?P\w+)!? =>(?P.*)$', +JSON_REG = re.compile(r'^(?P\w+) \| (?P\w+)!? =>(?P.*)$', re.MULTILINE | re.DOTALL) -NON_JSON_REG = re.compile(('^(?P\w+) \| (?P\w+)!? \| ' - 'rc=(?P\d+) >>\n(?P.*)\n$'), +NON_JSON_REG = re.compile((r'^(?P\w+) \| (?P\w+)!? \| ' + r'rc=(?P\d+) >>\n(?P.*)\n$'), re.MULTILINE | re.DOTALL) @@ -172,7 +172,7 @@ def main(): try: output = json.loads(json_output) - except Exception as e: + except Exception: module.fail_json( msg='Can not parse the inner module output: %s' % json_output) @@ -194,7 +194,7 @@ def main(): # } try: ret = output['plays'][0]['tasks'][0]['hosts']['localhost'] - except (KeyError, IndexError) as e: + except (KeyError, IndexError): module.fail_json( msg='Ansible JSON output has unexpected format: %s' % output) diff --git a/kolla_ansible/tests/unit/test_address_filters.py b/kolla_ansible/tests/unit/test_address_filters.py index 5f157ab9bc..de2aadfe65 100644 --- a/kolla_ansible/tests/unit/test_address_filters.py +++ b/kolla_ansible/tests/unit/test_address_filters.py @@ -143,12 +143,12 @@ class TestKollaAddressFilter(unittest.TestCase): 'prefix': 64, }, { - 'address': addr+'1', + 'address': addr + '1', 'scope': 'link', 'prefix': 64, }, { - 'address': addr+'2', + 'address': addr + '2', 'scope': 'global', 'prefix': 64, }, @@ -175,7 +175,7 @@ class TestKollaAddressFilter(unittest.TestCase): 'prefix': 64, }, { - 'address': addr+'1', + 'address': addr + '1', 'scope': 'link', 'prefix': 64, }, diff --git a/kolla_ansible/tests/unit/test_filters.py b/kolla_ansible/tests/unit/test_filters.py index 2ae334ce37..e35f503d97 100644 --- a/kolla_ansible/tests/unit/test_filters.py +++ b/kolla_ansible/tests/unit/test_filters.py @@ -122,7 +122,7 @@ class TestFilters(unittest.TestCase): @mock.patch.object(filters, 'service_enabled') @mock.patch.object(filters, 'service_mapped_to_host') - def test_service_enabled_and_mapped_to_host(self, mock_mapped, + def test_service_enabled_and_mapped_to_host(self, mock_mapped, mock_enabled): service = {} mock_enabled.return_value = True @@ -134,7 +134,7 @@ class TestFilters(unittest.TestCase): @mock.patch.object(filters, 'service_enabled') @mock.patch.object(filters, 'service_mapped_to_host') - def test_service_enabled_and_mapped_to_host_disabled(self, mock_mapped, + def test_service_enabled_and_mapped_to_host_disabled(self, mock_mapped, mock_enabled): service = {} mock_enabled.return_value = False @@ -146,7 +146,7 @@ class TestFilters(unittest.TestCase): @mock.patch.object(filters, 'service_enabled') @mock.patch.object(filters, 'service_mapped_to_host') - def test_service_enabled_and_mapped_to_host_not_mapped(self, mock_mapped, + def test_service_enabled_and_mapped_to_host_not_mapped(self, mock_mapped, mock_enabled): service = {} mock_enabled.return_value = True diff --git a/lower-constraints.txt b/lower-constraints.txt index a714d26beb..13855e307c 100644 --- a/lower-constraints.txt +++ b/lower-constraints.txt @@ -23,10 +23,8 @@ dogpile.cache==0.6.5 dulwich==0.19.0 extras==1.0.0 fixtures==3.0.0 -flake8==2.5.5 gitdb2==2.0.3 GitPython==2.1.8 -hacking==1.1.0 idna==2.6 imagesize==1.0.0 iso8601==0.1.12 @@ -38,7 +36,6 @@ jsonschema==2.6.0 keystoneauth1==3.4.0 linecache2==1.0.0 MarkupSafe==1.0 -mccabe==0.2.1 monotonic==1.4 mox3==0.25.0 msgpack==0.5.6 @@ -61,7 +58,6 @@ packaging==17.1 pbr==2.0.0 prettytable==0.7.1 pycparser==2.18 -pyflakes==0.8.1 Pygments==2.2.0 pyinotify==0.9.6 pyOpenSSL==17.5.0 diff --git a/test-requirements.txt b/test-requirements.txt index 7044225bd9..9e9aeb5c29 100644 --- a/test-requirements.txt +++ b/test-requirements.txt @@ -7,7 +7,7 @@ beautifulsoup4>=4.6.0 # MIT coverage!=4.4,>=4.0 # Apache-2.0 doc8>=0.6.0 # Apache-2.0 extras>=1.0.0 # MIT -hacking>=1.1.0,<1.2.0 # Apache-2.0 +hacking>=3.0,<3.1.0 # Apache-2.0 oslo.log>=3.36.0 # Apache-2.0 oslotest>=3.2.0 # Apache-2.0 PrettyTable<0.8,>=0.7.1 # BSD diff --git a/tests/test_kolla_docker.py b/tests/test_kolla_docker.py index af00bc89f5..b2b9cca3d9 100644 --- a/tests/test_kolla_docker.py +++ b/tests/test_kolla_docker.py @@ -96,7 +96,7 @@ class ModuleArgsTest(base.BaseTestCase): dimensions=dict(required=False, type='dict', default=dict()), tty=dict(required=False, type='bool', default=False), client_timeout=dict(required=False, type='int', default=120), - ) + ) required_if = [ ['action', 'pull_image', ['image']], ['action', 'start_container', ['image', 'name']], diff --git a/tools/validate-all-file.py b/tools/validate-all-file.py index 21e5bef841..22a2d8be30 100755 --- a/tools/validate-all-file.py +++ b/tools/validate-all-file.py @@ -196,5 +196,6 @@ def main(): ) return sum([check() for check in checks]) + if __name__ == "__main__": sys.exit(main()) diff --git a/tools/validate-yaml.py b/tools/validate-yaml.py index 43156313e5..a69afe06fb 100755 --- a/tools/validate-yaml.py +++ b/tools/validate-yaml.py @@ -40,5 +40,6 @@ def main(): sys.exit(res) + if __name__ == '__main__': main() diff --git a/tox.ini b/tox.ini index 328575904c..d0f327fb06 100644 --- a/tox.ini +++ b/tox.ini @@ -98,6 +98,11 @@ commands = [flake8] show-source = True +# NOTE: Default ignore list is *not* empty! +# TODO: Enable either W503 or W504: +# W503 line break before binary operator +# W504 line break after binary operator +ignore = W503,W504 exclude=.eggs,.git,.tox,doc [testenv:lower-constraints]