From 91686890070900c6f230edd09b9a10c1ab8da6f9 Mon Sep 17 00:00:00 2001 From: Ilya Shakhat Date: Sun, 5 Apr 2020 01:17:16 +0400 Subject: [PATCH] Resolve py27 and pep8 job failures 1. Cap version of stestr for py27 (the latest version is py3 only). 2. Flake8 is runtime dependency of diskimage-builder, currently they use version >= 3.6.0, so Shaker must conform to this version too. Failures found by the newer version of flake8: * W605 invalid escape sequence -- issues are fixed since they correspond to syntax warnings from py36. * E305 expected 2 blank lines after class or function definition -- issues are fixed (older version didn't restrict spaces between functions and `if __name__ == "__main__":` block). * W504 line break after binary operator -- the rule is ignored since it contradicts the code style of the whole project. Change-Id: I7fa53cfb6b654f5d93df30441a6eb2d47714d479 --- shaker/agent/agent.py | 1 + shaker/engine/all_in_one.py | 1 + shaker/engine/config.py | 2 +- shaker/tests/test_sla.py | 6 +++--- test-requirements.txt | 6 +++--- tox.ini | 5 ++--- 6 files changed, 11 insertions(+), 10 deletions(-) diff --git a/shaker/agent/agent.py b/shaker/agent/agent.py index 071e385..3fbad92 100644 --- a/shaker/agent/agent.py +++ b/shaker/agent/agent.py @@ -169,5 +169,6 @@ def main(): work(agent_id, endpoint, polling_interval) + if __name__ == "__main__": main() diff --git a/shaker/engine/all_in_one.py b/shaker/engine/all_in_one.py index e900ce0..4c2f814 100644 --- a/shaker/engine/all_in_one.py +++ b/shaker/engine/all_in_one.py @@ -61,5 +61,6 @@ def main(): LOG.info('Cleaning up') image_builder.cleanup() + if __name__ == "__main__": main() diff --git a/shaker/engine/config.py b/shaker/engine/config.py index 939d2f5..8b12a9e 100644 --- a/shaker/engine/config.py +++ b/shaker/engine/config.py @@ -37,7 +37,7 @@ class Endpoint(types.String): def __call__(self, value): value = str(value) - if not re.match('\S+:\d+', value): + if not re.match(r'\S+:\d+', value): raise ValueError('Wrong value of server_endpoint, ' 'expected :, but got: %s' % value) return value diff --git a/shaker/tests/test_sla.py b/shaker/tests/test_sla.py index 419ecaf..0fd934c 100644 --- a/shaker/tests/test_sla.py +++ b/shaker/tests/test_sla.py @@ -28,10 +28,10 @@ class TestSla(testtools.TestCase): self.assertFalse(sla.eval_expr('(not 11 > 7) or (not 5 < 6)')) def test_eval_regex(self): - self.assertTrue(sla.eval_expr('"some text" & "\w+\s+\w+"')) - self.assertFalse(sla.eval_expr('"some text" & "\d+"')) + self.assertTrue(sla.eval_expr(r'"some text" & "\w+\s+\w+"')) + self.assertFalse(sla.eval_expr(r'"some text" & "\d+"')) - self.assertFalse(sla.eval_expr('a & "\d+"', {'a': ''})) + self.assertFalse(sla.eval_expr(r'a & "\d+"', {'a': ''})) def test_eval_non_existent_ref(self): self.assertRaises(sla.SLAException, sla.eval_expr, diff --git a/test-requirements.txt b/test-requirements.txt index 459d014..55eeb2d 100644 --- a/test-requirements.txt +++ b/test-requirements.txt @@ -2,14 +2,14 @@ # 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 coverage>=4.0 # Apache-2.0 -hacking<1.2.0,>=1.1.0 # Apache-2.0 - should be in sync with diskimage-builder +flake8<4.0.0,>=3.6.0 # MIT - must be in sync with diskimage-builder mock>=2.0 # BSD oslotest>=1.10.0 # Apache-2.0 sphinx!=1.6.6,!=1.6.7,<2.0.0;python_version=='2.7' # BSD sphinx!=1.6.6,!=1.6.7;python_version>='3.4' # BSD sphinxcontrib-httpdomain # BSD sphinx_rtd_theme -stestr>=2.0.0 # Apache-2.0 +stestr>=2.0.0,<3.0.0;python_version=='2.7' # Apache-2.0 +stestr>=2.0.0;python_version>='3.4' # Apache-2.0 testtools>=1.4.0 # MIT diff --git a/tox.ini b/tox.ini index d549c7a..148026f 100644 --- a/tox.ini +++ b/tox.ini @@ -91,9 +91,8 @@ commands = bash tools/svg2png.sh # E125 continuation line does not distinguish itself from next logical line # H405 multi line docstring summary not separated with an empty line # E731 do not assign a lambda expression, use a def -# [H106] Don't put vim configuration in source files -# [H203] Use assertIs(Not)None to check for None -ignore = E125,H405,E731 +# W504 line break after binary operator +ignore = E125,H405,E731,W504 show-source = true builtins = _ exclude=.venv,.git,.tox,dist,doc,*openstack/common*,*lib/python*,*egg,tools,build