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

Handle alternate names for UTF-8 encoding #3322

Merged
merged 1 commit into from
Nov 29, 2018

Conversation

ob-stripe
Copy link
Contributor

The issue

Currently, pipenv does this:

  1. In __init__.py, sys.stdout and sys.stderr are replaced by io.TextIOWrappers with encoding set to 'utf8' (no dash):
    stdout_wrapper = io.TextIOWrapper(sys.stdout.buffer, encoding='utf8')
    atexit.register(stdout_wrapper.close)
    stderr_wrapper = io.TextIOWrapper(sys.stderr.buffer, encoding='utf8')
    atexit.register(stderr_wrapper.close)
    sys.stdout = stdout_wrapper
    sys.stderr = stderr_wrapper
  2. In _compat.py, the encoding is forced to UTF-8 by checking if sys.stdout/err.encoding.lower() is equal to 'utf-8' (with a dash):
    if stdout_encoding.lower() != "utf-8" or stderr_encoding.lower() != "utf-8":

Fixes #3313.

The fix

  • Canonicalizes the encoding name using codecs.lookup(). This will always return 'utf-8' for UTF-8 encodings, no matter what alias is used ('utf8', 'UTF-8', 'u8', etc.)
  • Catch ImportError when importing ctypes, so that this code path doesn't crash with PyPy (which doesn't support ctypes). @frostming mentioned in Incompatibility with pypy3 #3313 that pipenv doesn't officially support PyPy so I can remove this if you'd prefer, but it seems like a net improvement to me.

The checklist

@techalchemy
Copy link
Member

Thanks! if you run into anything else definitely let us know, I may experiment with adding PyPy to CI if we can

@techalchemy techalchemy merged commit 4835512 into pypa:master Nov 29, 2018
@ob-stripe ob-stripe deleted the ob-fix-3313 branch November 29, 2018 09:45
@ob-stripe
Copy link
Contributor Author

Cool, thanks!

@ob-stripe
Copy link
Contributor Author

@techalchemy Sorry to bother you, but do you have any idea when the next pipenv version will be released? The issue I fixed in this PR has been affecting our CI pipeline for a few months now.

@techalchemy
Copy link
Member

Apologies, I have been forced to split focus on a number of projects. Stewardship here seems to have been excellent so I’m just catching up and getting my own changes together so hopefully soon!

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.

Incompatibility with pypy3
2 participants