Skip to content

Conversation

@buckket
Copy link
Contributor

@buckket buckket commented Jan 16, 2017

When installing this module on a system with Python 3 which has no or non-utf8 locale variables set installation fails because you’re making use of the open() command in setup.py to pipe in things like README.rst and CHANGELOG.rst. This happens because Python 3 tries loading those files with the default encoding (which happens to be ASCII), and then fails with an UnicodeDecodeError.

Suggestion: Use io.open(), which is available for both Python 2 and 3 and specify the encoding of said files explicitly.

One could argue that this problem is client-sided, but I don’t see any real drawbacks fixing this on your side.

Thanks.

@pdp7
Copy link
Collaborator

pdp7 commented Jan 17, 2017

@buckket thanks for the pull request. What is the best way for me to test the failure condition which this PR fixes?

@buckket
Copy link
Contributor Author

buckket commented Jan 17, 2017

Invoke pip or setup.py with a non-utf8 locale, e.g. by passing empty LANG environment variable:

$ LANG="" python3 setup.py

@pdp7
Copy link
Collaborator

pdp7 commented Jan 17, 2017

@buckket Thanks

Fail with current master

debian@beaglebone:~/adafruit-beaglebone-io-python$ sudo bash -c 'LANG="" python3 ./setup.py install'
Traceback (most recent call last):
  File "./setup.py", line 38, in <module>
    long_description = open('README.rst').read() + open('CHANGELOG.rst').read(),
  File "/usr/lib/python3.4/encodings/ascii.py", line 26, in decode
    return codecs.ascii_decode(input, self.errors)[0]
UnicodeDecodeError: 'ascii' codec can't decode byte 0xe2 in position 813: ordinal not in range(128)

OK with the fix in this PR

debian@beaglebone:~/pr/adafruit-beaglebone-io-python$ sudo bash -c 'LANG="" python3 ./setup.py install'
running install
Checking .pth file support in /usr/local/lib/python3.4/dist-packages/
/usr/bin/python3 -E -c pass
TEST PASSED: /usr/local/lib/python3.4/dist-packages/ appears to support .pth files
running bdist_egg
running egg_info
writing Adafruit_BBIO.egg-info/PKG-INFO
<snip>
Installed /usr/local/lib/python3.4/dist-packages/Adafruit_BBIO-1.0.1-py3.4-linux-armv7l.egg
Processing dependencies for Adafruit-BBIO==1.0.1
Finished processing dependencies for Adafruit-BBIO==1.0.1

@pdp7 pdp7 merged commit 4c67dfc into adafruit:master Jan 17, 2017
@pdp7
Copy link
Collaborator

pdp7 commented Jan 17, 2017

Thanks @buckket

pdp7 added a commit that referenced this pull request Feb 1, 2017
Version 1.0.2: bug fixes and minor improvements:
- Merge pull request #130 from adafruit/issue129-usr-leds [1439133]
  - Add support for alternate USR LED labels
- Merge pull request #131 from adafruit/fix-gcc-warnings [f0ee018]
   - Fix gcc warnings
- Merge pull request #132 from buckket/setup_unicode_fix [4c67dfc]
   - Make use of io.open() with explicit file encoding in setup.py
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

2 participants