1
0
mirror of https://github.com/ARM-software/workload-automation.git synced 2025-01-31 02:01:16 +00:00

dev_scripts: port pylint plugins to Python 3

This commit is contained in:
Sergei Trofimov 2018-07-09 15:27:33 +01:00 committed by Marc Bonnici
parent 915c363fd9
commit 0e0d4e0ff0

View File

@ -1,3 +1,5 @@
import sys
from astroid import MANAGER
from astroid import scoped_nodes
@ -23,18 +25,25 @@ def transform(mod):
if not text.strip():
return
text = text.split('\n')
text = text.split(b'\n')
# NOTE: doing it this way because the "correct" approach below does not
# work. We can get away with this, because in well-formated WA files,
# the initial line is the copyright header's blank line.
if 'pylint:' in text[0]:
if b'pylint:' in text[0]:
msg = 'pylint directive found on the first line of {}; please move to below copyright header'
raise RuntimeError(msg.format(mod.name))
if text[0].strip() and text[0][0] != '#':
if sys.version_info[0] == 3:
char = chr(text[0][0])
else:
char = text[0][0]
if text[0].strip() and char != '#':
msg = 'first line of {} is not a comment; is the copyright header missing?'
raise RuntimeError(msg.format(mod.name))
if sys.version_info[0] == 3:
text[0] = '# pylint: disable={}'.format(','.join(errors)).encode('utf-8')
else:
text[0] = '# pylint: disable={}'.format(','.join(errors))
mod.file_bytes = '\n'.join(text)
mod.file_bytes = b'\n'.join(text)
# This is what *should* happen, but doesn't work.
# text.insert(0, '# pylint: disable=attribute-defined-outside-init')