From b681c9691a5e506d942e42c2a8020799744e8230 Mon Sep 17 00:00:00 2001 From: Murray Fordyce Date: Mon, 3 Oct 2022 14:21:21 -0500 Subject: [PATCH] Prevent colon confusion in output parsing By use a magic string that shouldn't appear in code, we make parsing easier. Really we should use a parser or something; but, this is an easy enough fix. Fixes #20 --- pycodestyle_magic.py | 7 ++++--- 1 file changed, 4 insertions(+), 3 deletions(-) diff --git a/pycodestyle_magic.py b/pycodestyle_magic.py index 06cd812..b922301 100644 --- a/pycodestyle_magic.py +++ b/pycodestyle_magic.py @@ -15,6 +15,7 @@ import os import logging import copy +import platform import pycodestyle as pycodestyle_module from flake8.api import legacy as flake8_module from contextlib import redirect_stdout @@ -162,7 +163,8 @@ def pycodestyle(line, cell, auto=False): f.close() # now we can check the file by name. # we might be able to use 'stdin', have to check implementation - format = '%(row)d:%(col)d: %(code)s %(text)s' + format_divider = 'FORMAT_DIVIDER' + format = format_divider+'%(row)d'+format_divider'%(col)d'+format_divider+' %(code)s %(text)s' pycodestyle = pycodestyle_module.StyleGuide(format=format) # check the filename pcs_result = pycodestyle.check_files(paths=[f.name]) @@ -171,8 +173,7 @@ def pycodestyle(line, cell, auto=False): for line in stdout: #logger.info(line) - # on windows drive path also contains : - line, col, error = line.split(':')[-4:] + line, col, error = line.split(format_divider,3)[:1] # do not subtract 1 for line for %%pycodestyle, inc pre py3.6 string if auto: add = -1