From 2fa3d6d3b2ce42290a277e901b10a90174648769 Mon Sep 17 00:00:00 2001 From: Monty Taylor Date: Wed, 1 Apr 2020 08:56:03 -0500 Subject: [PATCH] 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 --- roles/tox/library/tox_parse_output.py | 7 +++++-- 1 file changed, 5 insertions(+), 2 deletions(-) diff --git a/roles/tox/library/tox_parse_output.py b/roles/tox/library/tox_parse_output.py index 45972a2eb..55ec35b21 100644 --- a/roles/tox/library/tox_parse_output.py +++ b/roles/tox/library/tox_parse_output.py @@ -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