Strip ansi codes from pep8 message

Sometimes pep8 messages have ANSI color codes, as here:

https://review.opendev.org/#/c/697636/10/cinder/tests/unit/volume/drivers/vmware/test_fcd.py@567

Which is pretty noisy in a gerrit comment. Strip them.

Change-Id: I494ec23d05b9df54e31ff8a2c568309b0a01f98a
This commit is contained in:
Monty Taylor 2020-04-01 08:56:03 -05:00
parent e404589b84
commit 2fa3d6d3b2

View File

@ -40,6 +40,7 @@ import re
from ansible.module_utils.basic import AnsibleModule
PEP8_RE = re.compile(r"^(.*):(\d+):(\d+): (.*)$")
ANSI_RE = re.compile(r'(?:\x1B[@-_]|[\x80-\x9F])[0-?]*[ -/]*[@-~]')
def extract_pep8_comments(line):
@ -69,8 +70,10 @@ def extract_file_comments(tox_output):
if file_path.startswith('./'):
file_path = file_path[2:]
ret.setdefault(file_path, [])
ret[file_path].append(dict(line=int(start_line),
message=message))
ret[file_path].append(dict(
line=int(start_line),
message=ANSI_RE.sub('', message),
))
except Exception:
pass
return ret