diff --git a/dev_scripts/pylint_plugins.py b/dev_scripts/pylint_plugins.py index f01942d8..8d6f87cc 100644 --- a/dev_scripts/pylint_plugins.py +++ b/dev_scripts/pylint_plugins.py @@ -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)) - text[0] = '# pylint: disable={}'.format(','.join(errors)) - mod.file_bytes = '\n'.join(text) + 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 = b'\n'.join(text) # This is what *should* happen, but doesn't work. # text.insert(0, '# pylint: disable=attribute-defined-outside-init')