run pylint in leo-editor UnicodeDecodeError

138 views
Skip to first unread message

zhaohe wang

unread,
Oct 13, 2016, 8:06:18 PM10/13/16
to leo-editor
When I run pylint in leo-editor: Alt X, follow error occurred:

Leo 5.4-devel, build 20160722143100, Fri, Jul 22, 2016  2:31:00 PM
Git repo info: branch = master, commit = cb40bc3b4ca7
Python 2.7.12, PyQt version 4.8.7
linux2
pylint: keyLog.py
Traceback (most recent call last):
  File "<string>", line 1, in <module>
  File "leo/core/leoGlobals.py", line 1924, in run_pylint
    lint.Run(args)
  File "/usr/local/lib/python2.7/dist-packages/pylint/lint.py", line 1264, in __init__
    linter.read_config_file()
  File "/usr/local/lib/python2.7/dist-packages/pylint/config.py", line 627, in read_config_file
    parser.readfp(fp)
  File "/usr/local/lib/python2.7/dist-packages/backports/configparser/__init__.py", line 769, in readfp
    self.read_file(fp, source=filename)
  File "/usr/local/lib/python2.7/dist-packages/backports/configparser/__init__.py", line 724, in read_file
    self._read(f, source)
  File "/usr/local/lib/python2.7/dist-packages/backports/configparser/__init__.py", line 1035, in _read
    for lineno, line in enumerate(fp, start=1):
  File "/usr/lib/python2.7/codecs.py", line 314, in decode
    (result, consumed) = self._buffer_decode(data, self.errors, final)
  File "/usr/lib/python2.7/encodings/utf_8_sig.py", line 66, in _buffer_decode
    return codecs.utf_8_decode(input, errors, final)
UnicodeDecodeError: 'utf8' codec can't decode byte 0x92 in position 2297: invalid start byte

Simply run pylint in concole:

swot@pp:~/app$ pylint keyLog.py
No config file found, using default configuration
************* Module keyLog
C: 17, 0: Unnecessary parens after u'print' keyword (superfluous-parens)
C: 24, 0: Unnecessary parens after u'print' keyword (superfluous-parens)
C:  1, 0: Invalid module name "keyLog" (invalid-name)
C:  1, 0: Missing module docstring (missing-docstring)
C:  7, 0: Invalid function name "detectInputKey" (invalid-name)
C:  7, 0: Missing function docstring (missing-docstring)
E: 20,25: Module 'evdev.ecodes' has no 'EV_KEY' member (no-member)

What's wrong with this? Anyone could help answer this ? And thanks a lot!
keyLog.py

Edward K. Ream

unread,
Oct 14, 2016, 4:36:45 AM10/14/16
to leo-editor


On Thu, Oct 13, 2016 at 7:06 PM, zhaohe wang <wangz...@gmail.com> wrote:

​QQQ​
When I run pylint in leo-editor: Alt X, follow error occurred:
​[snip]

UnicodeDecodeError: 'utf8' codec can't decode byte 0x92 in position 2297: invalid start byte

Simply run pylint in con
​s​
ole:


swot@pp:~/app$ pylint keyLog.py
No config file found, using default configuration
​QQQ​

​The error occurs when processing the config file, so there is no error if the config file isn't found.

​Somehow the Leo's pylint file is finding a config file. Try putting a line like the following at the start of your config file:

   @first # -*- coding: utf-8 -*-

HTH.

Edward

Edward K. Ream

unread,
Oct 14, 2016, 5:22:29 AM10/14/16
to leo-editor

On Friday, October 14, 2016 at 3:36:45 AM UTC-5, Edward K. Ream wrote:

​The error occurs when processing the config file, so there is no error if the config file isn't found.

Leo's internal pylint command appends the leo directory to sys.path.  So you should do the same in the sitecustomize.py file for Python 2.7.

Edward

zhaohe wang

unread,
Oct 14, 2016, 6:30:45 AM10/14/16
to leo-editor
Is the config file:  ~/.pylintrc or leo-editor/leo/test/pylint-leo-rc.txt ?

在 2016年10月14日星期五 UTC+8下午4:36:45,Edward K. Ream写道:

Edward K. Ream

unread,
Oct 14, 2016, 7:06:48 AM10/14/16
to leo-editor
On Fri, Oct 14, 2016 at 5:30 AM, zhaohe wang <wangz...@gmail.com> wrote:
Is the config file:  ~/.pylintrc or
​​
leo-editor/leo/test/pylint-leo-rc.txt ?

​It should be in ​
 
​​leo-editor/leo/test/pylint-leo-rc.txt

EKR

zhaohe wang

unread,
Oct 14, 2016, 7:16:22 AM10/14/16
to leo-editor
Leo 5.4-devel, build 20160722143100, Fri, Jul 22, 2016  2:31:00 PM
Git repo info: branch = master, commit = cb40bc3b4ca7
Python 2.7.12, PyQt version 4.8.7
linux2
pylint: keyLog.py
Traceback (most recent call last):
  File "<string>", line 1, in <module>
  File "leo/core/leoGlobals.py", line 1924, in run_pylint
    lint.Run(args)
  File "/usr/local/lib/python2.7/dist-packages/pylint/lint.py", line 1264, in __init__
    linter.read_config_file()
  File "/usr/local/lib/python2.7/dist-packages/pylint/config.py", line 627, in read_config_file
    parser.readfp(fp)
  File "/usr/local/lib/python2.7/dist-packages/backports/configparser/__init__.py", line 769, in readfp
    self.read_file(fp, source=filename)
  File "/usr/local/lib/python2.7/dist-packages/backports/configparser/__init__.py", line 724, in read_file
    self._read(f, source)
  File "/usr/local/lib/python2.7/dist-packages/backports/configparser/__init__.py", line 1101, in _read
    raise MissingSectionHeaderError(fpname, lineno, line)
backports.configparser.MissingSectionHeaderError: File contains no section headers.
file: '/home/swot/leo-editor/leo/test/pylint-leo-rc.txt', line: 1
u'@first # -*- coding: utf-8 -*-\n'
pylint: done  0.23 sec.


在 2016年10月14日星期五 UTC+8下午7:06:48,Edward K. Ream写道:

Edward K. Ream

unread,
Oct 14, 2016, 1:32:25 PM10/14/16
to leo-editor
On Fri, Oct 14, 2016 at 6:16 AM, zhaohe wang <wangz...@gmail.com> wrote:
Leo 5.4-devel, build 20160722143100, Fri, Jul 22, 2016  2:31:00 PM
Git repo info: branch = master, commit = cb40bc3b4ca7
Python 2.7.12, PyQt version 4.8.7
linux2
pylint: keyLog.py
Traceback (most recent call last):

  File "/usr/local/lib/python2.7/dist-packages/backports/configparser/__init__.py", line 1101, in _read
    raise MissingSectionHeaderError(fpname, lineno, line)
backports.configparser.MissingSectionHeaderError: File contains no section headers.
file: '/home/swot/leo-editor/leo/test/pylint-leo-rc.txt', line: 1
u'@first # -*- coding: utf-8 -*-\n'
pylint: done  0.23 sec.

​Not sure what is happening.  You might try removing non-ascii characters from the file.

Edward

Edward K. Ream

unread,
Oct 14, 2016, 2:04:40 PM10/14/16
to leo-editor

I was confused.  Please remove the  # -*- coding: utf-8 -*- line.  It won't help.

I'm not sure how pylint handles config files, so you definitely should remove any non-ascii characters from the file.

HTH.

Edward

Edward K. Ream

unread,
Oct 15, 2016, 9:10:38 PM10/15/16
to leo-editor
 
The same kind of thing happened to me today after upgrading my Python distribution.
 
To find the location of the problem, I wrote this script:

path = r'c:\leo.repo\leo-editor\leo\test\pylint-leo-rc.txt'
f = open(path)
s = f.read()
f.close()
print(len(s))
errors = []
n = 0
for i, line in enumerate(g.splitLines(s)):
    try:
        print('  %3s %4s %s' % (i+1, n, line.rstrip()))
    except UnicodeEncodeError:
        print('**%3s %4s %s' % (i+1, n, len(line.rstrip())))
        errors.append(i)
    n += len(line)
print('error lines: %s' % errors)

The line looked like plain ascii, but removing it solved the problem.  This was a strange one.

Edward

zhaohe wang

unread,
Oct 16, 2016, 11:16:04 AM10/16/16
to leo-editor
Would you tell me which line like plain ascii?
error == [], when I run your script both wiht pylint-leo-rc.txt and my py file.

在 2016年10月16日星期日 UTC+8上午9:10:38,Edward K. Ream写道:

Edward K. Ream

unread,
Oct 16, 2016, 12:56:44 PM10/16/16
to leo-editor
On Sunday, October 16, 2016 at 10:16:04 AM UTC-5, zhaohe wang wrote:

Would you tell me which line like plain ascii?
error == [], when I run your script both wiht pylint-leo-rc.txt and my py file.

Hmm.  It looks like all the lines of these two files are ascii.  So it's even more of a mystery why you are getting Unicode errors.

Edward

zhaohe wang

unread,
Oct 16, 2016, 9:41:44 PM10/16/16
to leo-editor

Found it !!!
Line 207 in pylint-leo-rc-ref.txt
You committed on 29 Feb.


I changed the test py codes below. Add codecs.utf_8_decode(line), please have a ref
@language python
@tabwidth -4

import codecs

# path = r'c:\leo.repo\leo-editor\leo\test\pylint-leo-rc.txt'
path = r'/home/swot/leo-editor/leo/test/pylint-leo-rc.txt'
# path = r'/home/swot/app/keyLog.py'


f = open(path)
s = f.read()
f.close()
print(len(s))
errors = []
n = 0
for i, line in enumerate(g.splitLines(s)):
    try:
        print('  %3s %4s %s' % (i+1, n, line.rstrip()))
        codecs.utf_8_decode(line)

    except UnicodeEncodeError:
        print('**%3s %4s %s' % (i+1, n, len(line.rstrip())))
        errors.append(i)
    n += len(line)
print('error lines: %s' % errors)

在 2016年10月17日星期一 UTC+8上午12:56:44,Edward K. Ream写道:

Edward K. Ream

unread,
Oct 17, 2016, 6:00:33 AM10/17/16
to leo-editor
On Sun, Oct 16, 2016 at 8:41 PM, zhaohe wang <wangz...@gmail.com> wrote:

Found it !!!
​​
Line 207 in pylint-leo-rc-ref.txt
You committed on 29 Feb.

​Thanks for this.  I'll clean the offending line before releasing Leo 5.4b1.

Edward
Reply all
Reply to author
Forward
0 new messages