hacking: Prevent use of six

Spotted this in a review recently. We don't want people using six
anymore.

Change-Id: Ie107a95bc06390ab519d3b3af9b07103a9a14316
Signed-off-by: Stephen Finucane <stephenfin@redhat.com>
This commit is contained in:
Stephen Finucane 2022-04-05 11:24:49 +01:00
parent b0851b0e9c
commit b082d06cbc
3 changed files with 27 additions and 0 deletions

View File

@ -140,6 +140,7 @@ mock_class_as_new_value_in_patching_re = re.compile(
rwlock_re = re.compile(
r"(?P<module_part>(oslo_concurrency\.)?(lockutils|fasteners))"
r"\.ReaderWriterLock\(.*\)")
six_re = re.compile(r"^(import six(\..*)?|from six(\..*)? import .*)$")
class BaseASTChecker(ast.NodeVisitor):
@ -1030,3 +1031,18 @@ def check_lockutils_rwlocks(logical_line):
0,
msg % {'module': match.group('module_part')}
)
@core.flake8ext
def check_six(logical_line):
"""Check for use of six
nova is now Python 3-only so we don't want six. However, people might use
it out of habit and it will likely work since six is a transitive
dependency.
N370
"""
match = re.match(six_re, logical_line)
if match:
yield (0, "N370: Don't use or import six")

View File

@ -1020,3 +1020,13 @@ class HackingTestCase(test.NoDBTestCase):
nova_utils.ReaderWriterLock()
"""
self._assert_has_no_errors(code, checks.check_lockutils_rwlocks)
def test_check_six(self):
code = """
import six
from six import moves
from six.moves import range
import six.moves.urllib.parse as urlparse
"""
errors = [(x + 1, 0, 'N370') for x in range(4)]
self._assert_has_errors(code, checks.check_six, expected_errors=errors)

View File

@ -375,6 +375,7 @@ extension =
N367 = checks:do_not_alias_mock_class
N368 = checks:do_not_use_mock_class_as_new_mock_value
N369 = checks:check_lockutils_rwlocks
N370 = checks:check_six
paths =
./nova/hacking