Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Fix reading README & CHANGES RST files when the system encoding is not UTF-8 #48

Merged
merged 2 commits into from
Apr 16, 2015

Conversation

mitchellrj
Copy link
Contributor

By default open in text mode reads files in the system encoding, however in this case we know that the encoding of the files being read is UTF-8, regardless of the platform on which the package is being installed.

If this is run on a platform where the default encoding is not UTF-8, the setup.py call fails because CHANGES.rst cannot be read in ASCII mode (due to special characters in a contributor's name).

Collecting django-sortedm2m==0.9.4 (from -r /app/src/requirements.txt (line 36))
  Downloading django-sortedm2m-0.9.4.tar.gz
    Complete output from command python setup.py egg_info:
    Traceback (most recent call last):
      File "<string>", line 20, in <module>
      File "/tmp/pip-build-7vwuo22m/django-sortedm2m/setup.py", line 51, in <module>
        read('CHANGES.rst'),
      File "/tmp/pip-build-7vwuo22m/django-sortedm2m/setup.py", line 25, in read
        return open(os.path.join(os.path.dirname(__file__), *parts), 'r').read()
      File "/app/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 0xc3 in position 781: ordinal not in range(128)

    ----------------------------------------
     Command "python setup.py egg_info" failed with error code 1 in /tmp/pip-build-7vwuo22m/django-sortedm2m

…t UTF-8. By default open in text mdoe reads files in the system encoding (see https://github.com/python/cpython/blob/6f4d604990c4a22bc06fd044ad61fce331ac9f83/Modules/_io/_iomodule.c#L114), however in this case we know that the encoding of the files being read is UTF8, regardless of the platform on which the package is being installed.
@mitchellrj mitchellrj force-pushed the fix-setup-py3k branch 4 times, most recently from 5013452 to d09c0ee Compare April 15, 2015 15:54
gregmuellegger added a commit that referenced this pull request Apr 16, 2015
Fix reading README & CHANGES RST files when the system encoding is not UTF-8
@gregmuellegger gregmuellegger merged commit 712d4d6 into jazzband:master Apr 16, 2015
@gregmuellegger
Copy link
Collaborator

Awesome! Thanks for the contribution. That makes absolutely sense and you even removed one distinction between Python 2 and 3. Super cool :)

@gregmuellegger
Copy link
Collaborator

Does it make sense to create a new release for this? Or are installations via pip install ... not affected?

@mitchellrj
Copy link
Contributor Author

Yes, it would require a new release. Source distribution eggs include and run the setup.py. The problem I encountered was when trying to install it via pip on an Ubuntu EC2 instance.

@gregmuellegger
Copy link
Collaborator

Cool, thanks. I just released 0.9.5: https://pypi.python.org/pypi/django-sortedm2m/

@mitchellrj
Copy link
Contributor Author

Thanks for the rapid response!

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