Merge "Update hacking and reenable local checks"

This commit is contained in:
Zuul 2020-04-03 10:49:24 +00:00 committed by Gerrit Code Review
commit 6d2c55bc76
6 changed files with 32 additions and 20 deletions

View File

@ -10,3 +10,4 @@ whereto>=0.3.0 # Apache-2.0
# needed for apidoc support
xattr>=0.9.2;sys_platform!='win32' # MIT

View File

@ -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/*',

View File

@ -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)

View File

@ -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

View File

@ -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

16
tox.ini
View File

@ -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}