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