diff --git a/kolla/hacking/checks.py b/kolla/hacking/checks.py index a8df070977..64e3227863 100644 --- a/kolla/hacking/checks.py +++ b/kolla/hacking/checks.py @@ -12,6 +12,7 @@ import re +from hacking import core mutable_default_args = re.compile(r"^\s*def .+\((.+=\{\}|.+=\[\])") @@ -22,12 +23,13 @@ UNDERSCORE_IMPORT_FILES = [] string_translation = re.compile(r"[^_]*_\(\s*('|\")") translated_log = re.compile( r"(.)*LOG\.(audit|error|info|warn|warning|critical|exception)" - "\(\s*_\(\s*('|\")") + r"\(\s*_\(\s*('|\")") underscore_import_check = re.compile(r"(.)*import _(.)*") # We need this for cases where they have created their own _ function. custom_underscore_check = re.compile(r"(.)*_\s*=\s*(.)*") +@core.flake8ext def check_explicit_underscore_import(logical_line, filename): """Check for explicit import of the _ function @@ -50,6 +52,7 @@ def check_explicit_underscore_import(logical_line, filename): yield(0, "D703: Found use of _() without explicit import of _!") +@core.flake8ext def no_log_warn(logical_line): """Disallow 'LOG.warn(' @@ -63,13 +66,8 @@ def no_log_warn(logical_line): yield (0, msg) +@core.flake8ext def no_mutable_default_args(logical_line): msg = "K301: Method's default argument shouldn't be mutable!" if mutable_default_args.match(logical_line): yield (0, msg) - - -def factory(register): - register(check_explicit_underscore_import) - register(no_mutable_default_args) - register(no_log_warn) diff --git a/lower-constraints.txt b/lower-constraints.txt index 2d24ad02b2..d753b266cb 100644 --- a/lower-constraints.txt +++ b/lower-constraints.txt @@ -20,12 +20,10 @@ docker==2.4.2 dogpile.cache==0.6.5 extras==1.0.0 fixtures==3.0.0 -flake8==2.5.5 gitdb2==2.0.3 gitdb==0.6.4 GitPython==1.0.1 graphviz==0.4 -hacking==1.1.0 idna==2.6 iso8601==0.1.12 Jinja2==2.8 @@ -59,7 +57,6 @@ packaging==17.1 pbr==2.0.0 prettytable==0.7.1 pycparser==2.18 -pyflakes==0.8.1 pyinotify==0.9.6 pyOpenSSL==17.5.0 pyparsing==2.2.0 diff --git a/test-requirements.txt b/test-requirements.txt index ba0f5c5690..23b3b43d12 100644 --- a/test-requirements.txt +++ b/test-requirements.txt @@ -8,11 +8,10 @@ coverage!=4.4,>=4.0 # Apache-2.0 ddt>=1.0.1 # MIT extras>=1.0.0 # MIT graphviz!=0.5.0,>=0.4 # MIT License -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 -pyflakes>=1.4.0,<1.5 PyYAML>=3.10 # MIT python-barbicanclient>=4.0.0 # Apache-2.0 python-heatclient>=1.10.0 # Apache-2.0 diff --git a/tests/test_set_config.py b/tests/test_set_config.py index e4706c99d6..02046edc2a 100644 --- a/tests/test_set_config.py +++ b/tests/test_set_config.py @@ -66,6 +66,7 @@ class LoadFromEnv(base.BaseTestCase): mock.call().__exit__(None, None, None)], mo.mock_calls) + FAKE_CONFIG_FILES = [ set_configs.ConfigFile( '/var/lib/kolla/config_files/bar.conf', diff --git a/tools/validate-all-file.py b/tools/validate-all-file.py index c04fb4000a..67f03218ad 100755 --- a/tools/validate-all-file.py +++ b/tools/validate-all-file.py @@ -109,5 +109,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 400a3821b2..5af8668beb 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 09b93e82a1..d94bd279ea 100644 --- a/tox.ini +++ b/tox.ini @@ -192,8 +192,12 @@ show-source = True enable-extensions = H203,H106 exclude=.eggs,.git,.tox,doc -[hacking] -local-check-factory = kolla.hacking.checks.factory +[flake8:local-plugins] +extension = + D703 = checks:check_explicit_underscore_import + K301 = checks:no_mutable_default_args + K302 = checks:no_log_warn +paths = ./kolla/hacking [testenv:lower-constraints] deps =