plone / plone.recipe.codeanalysis

provides static code analysis for Buildout-based Python projects, including flake8, JSHint, CSS Lint, and other code checks
https://pypi.org/project/plone.recipe.codeanalysis/
11 stars 5 forks source link

unicodedecodeerror in setup.py #214

Open reinout opened 6 years ago

reinout commented 6 years ago

While trying to debug a possible buildout issue I got a UnicodeDecodeError out of the setup.py. See https://github.com/buildout/buildout/issues/434#issuecomment-352998315

No problems with python2.7, but when I run it with python 3.6:

$ python setup.py
Traceback (most recent call last):
  File "setup.py", line 19, in <module>
    read('CONTRIBUTORS.rst'),
  File "setup.py", line 12, in read
    return open(os.path.join(os.path.dirname(__file__), *rnames)).read()
  File "/usr/local/Cellar/python3/3.6.3/Frameworks/Python.framework/Versions/3.6/lib/python3.6/encodings/ascii.py", line 26, in decode
    return codecs.ascii_decode(input, self.errors)[0]
UnicodeDecodeError: 'ascii' codec can't decode byte 0xc3 in position 80: ordinal not in range(128)

The cause is the bare read() and a non-ascii contributor in CONTRIBUTORS.rst.

Something like this code (taken from zest.releaser) might help:

def read(filename):
    try:
        with codecs.open(filename, encoding='utf-8') as f:
            return unicode(f.read())
    except NameError:
        with open(filename, 'r', encoding='utf-8') as f:
            return f.read()