Add hacking rules to ban eventlet usage

Introduce hacking checks to ban eventlet usage
in keystoneclient. This helps maintain code quality and
prevents regression to deprecated eventlet patterns after
the recent eventlet removal.

- Add K001 check for eventlet imports
- Add K002 check for eventlet usage patterns in code
- Register checks as flake8 extensions in setup.cfg
- Skip comments and docstrings to avoid false positives

The checks will catch patterns like:
- import eventlet / from eventlet import ...
- eventlet.*, green.*, patcher.*, already_patched references

Generated-By: Claude Code
Change-Id: I26350578fa58f8f2b16821aeeeafbd58fac4b168
Signed-off-by: Hervé Beraud <hberaud@redhat.com>
This commit is contained in:
Hervé Beraud 2025-08-29 15:20:52 +02:00
parent ee58ef4d00
commit 5cf15f14be
3 changed files with 75 additions and 0 deletions

View file

@ -0,0 +1,13 @@
# Licensed under the Apache License, Version 2.0 (the "License"); you may
# not use this file except in compliance with the License. You may obtain
# a copy of the License at
#
# http://www.apache.org/licenses/LICENSE-2.0
#
# Unless required by applicable law or agreed to in writing, software
# distributed under the License is distributed on an "AS IS" BASIS, WITHOUT
# WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. See the
# License for the specific language governing permissions and limitations
# under the License.
"""keystoneclient hacking checks module."""

View file

@ -0,0 +1,58 @@
# Licensed under the Apache License, Version 2.0 (the "License"); you may
# not use this file except in compliance with the License. You may obtain
# a copy of the License at
#
# http://www.apache.org/licenses/LICENSE-2.0
#
# Unless required by applicable law or agreed to in writing, software
# distributed under the License is distributed on an "AS IS" BASIS, WITHOUT
# WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. See the
# License for the specific language governing permissions and limitations
# under the License.
"""keystoneclient's pep8 extensions.
In order to make the review process faster and easier for core devs we are
adding some keystoneclient specific pep8 checks. This will catch common
errors so that core devs don't have to.
"""
import re
from hacking import core
@core.flake8ext
def check_no_eventlet_imports(logical_line):
"""Check for eventlet imports.
K001: eventlet usage is deprecated in keystoneclient.
"""
if re.match(r'^\s*(import\s+eventlet|from\s+eventlet)', logical_line):
yield (0, "K001 eventlet usage is deprecated in keystoneclient")
@core.flake8ext
def check_no_eventlet_references(logical_line):
"""Check for eventlet references in code.
K002: eventlet usage is deprecated in keystoneclient.
"""
# Skip comments and docstrings
if (logical_line.strip().startswith('#') or
'"""' in logical_line or "'''" in logical_line):
return
# Check for eventlet usage patterns
eventlet_patterns = [
r'eventlet\.',
r'green\.',
r'patcher\.',
r'\balready_patched\b',
]
for pattern in eventlet_patterns:
if re.search(pattern, logical_line):
yield (0, "K002 eventlet usage is deprecated in keystoneclient")
break # Only report one error per line

View file

@ -36,3 +36,7 @@ keystoneclient.auth.plugin =
v3unscopedsaml = keystoneclient.contrib.auth.v3.saml2:Saml2UnscopedToken
v3scopedsaml = keystoneclient.contrib.auth.v3.saml2:Saml2ScopedToken
v3unscopedadfs = keystoneclient.contrib.auth.v3.saml2:ADFSUnscopedToken
flake8.extension =
K001 = keystoneclient.hacking.checks:check_no_eventlet_imports
K002 = keystoneclient.hacking.checks:check_no_eventlet_references