From 89df136bc401da97b6a10077300f65dafcb40f58 Mon Sep 17 00:00:00 2001 From: Andreas Jaeger Date: Thu, 2 Apr 2020 15:28:28 +0200 Subject: [PATCH] Update hacking and reenable local checks Update to hacking 3.0. Enable local hacking checks again, newer flake has a different interface. Remove hacking and friends from lower-constraints, they are not needed for installation. Unbreak docs: Don't build apidocs for hacking - blacklist in doc/source/conf.py. Change-Id: Ib230d72be9f0288d77cecd2c5ee0ff7aa91fc086 --- doc/requirements.txt | 1 + doc/source/conf.py | 2 ++ glance/hacking/checks.py | 27 +++++++++++++-------------- lower-constraints.txt | 4 ---- test-requirements.txt | 2 +- tox.ini | 16 +++++++++++++++- 6 files changed, 32 insertions(+), 20 deletions(-) diff --git a/doc/requirements.txt b/doc/requirements.txt index cbd4cc9ebb..7b3b6d9d59 100644 --- a/doc/requirements.txt +++ b/doc/requirements.txt @@ -10,3 +10,4 @@ whereto>=0.3.0 # Apache-2.0 # needed for apidoc support xattr>=0.9.2;sys_platform!='win32' # MIT + diff --git a/doc/source/conf.py b/doc/source/conf.py index d186b68849..e4202f785c 100644 --- a/doc/source/conf.py +++ b/doc/source/conf.py @@ -59,6 +59,8 @@ bug_tag = 'documentation' apidoc_module_dir = '../../glance' apidoc_output_dir = 'contributor/api' apidoc_excluded_paths = [ + 'hacking/*', + 'hacking', 'tests/*', 'tests', 'db/sqlalchemy/*', diff --git a/glance/hacking/checks.py b/glance/hacking/checks.py index b1771e0088..0ead27a1f1 100644 --- a/glance/hacking/checks.py +++ b/glance/hacking/checks.py @@ -14,6 +14,8 @@ import re +from hacking import core + """ Guidelines for writing new hacking checks @@ -44,6 +46,7 @@ unicode_func_re = re.compile(r"(\s|\W|^)unicode\(") dict_constructor_with_list_copy_re = re.compile(r".*\bdict\((\[)?(\(|\[)") +@core.flake8ext def assert_true_instance(logical_line): """Check for assertTrue(isinstance(a, b)) sentences @@ -53,6 +56,7 @@ def assert_true_instance(logical_line): yield (0, "G316: assertTrue(isinstance(a, b)) sentences not allowed") +@core.flake8ext def assert_equal_type(logical_line): """Check for assertEqual(type(A), B) sentences @@ -62,6 +66,7 @@ def assert_equal_type(logical_line): yield (0, "G317: assertEqual(type(A), B) sentences not allowed") +@core.flake8ext def assert_equal_none(logical_line): """Check for assertEqual(A, None) or assertEqual(None, A) sentences @@ -74,6 +79,7 @@ def assert_equal_none(logical_line): "sentences not allowed") +@core.flake8ext def no_translate_debug_logs(logical_line, filename): dirs = [ "glance/api", @@ -93,6 +99,7 @@ def no_translate_debug_logs(logical_line, filename): yield(0, "G319: Don't translate debug level logs") +@core.flake8ext def no_direct_use_of_unicode_function(logical_line): """Check for use of unicode() builtin @@ -102,6 +109,7 @@ def no_direct_use_of_unicode_function(logical_line): yield(0, "G320: Use six.text_type() instead of unicode()") +@core.flake8ext def check_no_contextlib_nested(logical_line): msg = ("G327: contextlib.nested is deprecated since Python 2.7. See " "https://docs.python.org/2/library/contextlib.html#contextlib." @@ -111,6 +119,7 @@ def check_no_contextlib_nested(logical_line): yield(0, msg) +@core.flake8ext def dict_constructor_with_list_copy(logical_line): msg = ("G328: Must use a dict comprehension instead of a dict constructor " "with a sequence of key-value pairs.") @@ -118,12 +127,14 @@ def dict_constructor_with_list_copy(logical_line): yield (0, msg) +@core.flake8ext def check_python3_xrange(logical_line): if re.search(r"\bxrange\s*\(", logical_line): yield(0, "G329: Do not use xrange. Use range, or six.moves.range for " "large loops.") +@core.flake8ext def check_python3_no_iteritems(logical_line): msg = ("G330: Use six.iteritems() or dict.items() instead of " "dict.iteritems().") @@ -131,6 +142,7 @@ def check_python3_no_iteritems(logical_line): yield(0, msg) +@core.flake8ext def check_python3_no_iterkeys(logical_line): msg = ("G331: Use six.iterkeys() or dict.keys() instead of " "dict.iterkeys().") @@ -138,22 +150,9 @@ def check_python3_no_iterkeys(logical_line): yield(0, msg) +@core.flake8ext def check_python3_no_itervalues(logical_line): msg = ("G332: Use six.itervalues() or dict.values instead of " "dict.itervalues().") if re.search(r".*\.itervalues\(\)", logical_line): yield(0, msg) - - -def factory(register): - register(assert_true_instance) - register(assert_equal_type) - register(assert_equal_none) - register(no_translate_debug_logs) - register(no_direct_use_of_unicode_function) - register(check_no_contextlib_nested) - register(dict_constructor_with_list_copy) - register(check_python3_xrange) - register(check_python3_no_iteritems) - register(check_python3_no_iterkeys) - register(check_python3_no_itervalues) diff --git a/lower-constraints.txt b/lower-constraints.txt index af3b93ffcc..e29c10b349 100644 --- a/lower-constraints.txt +++ b/lower-constraints.txt @@ -29,14 +29,12 @@ eventlet==0.22.0 extras==1.0.0 fasteners==0.14.1 fixtures==3.0.0 -flake8==2.5.5 future==0.16.0 futurist==1.2.0 gitdb2==2.0.3 GitPython==2.1.8 glance-store==1.0.0 greenlet==0.4.13 -hacking==2.0.0 httplib2==0.9.1 idna==2.6 imagesize==1.0.0 @@ -82,7 +80,6 @@ osprofiler==1.4.0 Paste==2.0.2 PasteDeploy==1.5.0 pbr==2.0.0 -pep8==1.5.7 pika-pool==0.1.3 pika==0.10.0 prettytable==0.7.1 @@ -90,7 +87,6 @@ psutil==3.2.2 psycopg2==2.8.4 pycadf==2.7.0 pycparser==2.18 -pyflakes==0.8.1 Pygments==2.2.0 pyinotify==0.9.6 PyMySQL==0.7.6 diff --git a/test-requirements.txt b/test-requirements.txt index a51071d998..9b0a775920 100644 --- a/test-requirements.txt +++ b/test-requirements.txt @@ -3,7 +3,7 @@ # process, which may cause wedges in the gate later. # Hacking already pins down pep8, pyflakes and flake8 -hacking>=2.0.0 # Apache-2.0 +hacking>=3.0,<3.1.0 # Apache-2.0 # For translations processing Babel!=2.4.0,>=2.3.4 # BSD diff --git a/tox.ini b/tox.ini index d450277834..e569ccc159 100644 --- a/tox.ini +++ b/tox.ini @@ -129,9 +129,23 @@ ignore = E402,E711,E712,H404,H405,W503,W504 exclude = .venv,.git,.tox,dist,doc,etc,*glance/locale*,*lib/python*,*egg,build [hacking] -local-check-factory = glance.hacking.checks.factory import_exceptions = glance.i18n +[flake8:local-plugins] +extension = + G316 = checks:assert_true_instance + G317 = checks:assert_equal_type + G318 = checks:assert_equal_none + G319 = checks:no_translate_debug_logs + G320 = checks:no_direct_use_of_unicode_function + G327 = checks:check_no_contextlib_nested + G328 = checks:dict_constructor_with_list_copy + G329 = checks:check_python3_xrange + G330 = checks:check_python3_no_iteritems + G331 = checks:check_python3_no_iterkeys + G332 = checks:check_python3_no_itervalues +paths = ./glance/hacking + [testenv:docs] deps = -c{env:UPPER_CONSTRAINTS_FILE:https://releases.openstack.org/constraints/upper/master}