Merge "Add hacking check to ban eventlet imports"

This commit is contained in:
Zuul
2025-08-28 23:00:26 +00:00
committed by Gerrit Code Review
2 changed files with 13 additions and 0 deletions

View File

@@ -31,6 +31,10 @@ underscore_import_check = re.compile(r"(.)*import _(.)*")
custom_underscore_check = re.compile(r"(.)*_\s*=\s*(.)*")
# I319: eventlet import not allowed
_eventlet_re = re.compile(r"\b(import|from)\s+eventlet\b")
@core.flake8ext
def check_explicit_underscore_import(logical_line, filename):
"""Check for explicit import of the _ function
@@ -52,3 +56,10 @@ def check_explicit_underscore_import(logical_line, filename):
elif (translated_log.match(logical_line)
or string_translation.match(logical_line)):
yield (0, "N323: Found use of _() without explicit import of _!")
@core.flake8ext
def no_eventlet_imports(logical_line):
"""Check for eventlet imports."""
if _eventlet_re.search(logical_line):
yield 0, "I319: eventlet import not allowed"

View File

@@ -180,8 +180,10 @@ per-file-ignores =
[flake8:local-plugins]
# [N323] Found use of _() without explicit import of _!
# [I319] eventlet import not allowed
extension =
N323 = checks:check_explicit_underscore_import
I319 = checks:no_eventlet_imports
paths = ./ironic/hacking/
[hacking]