-
-
Notifications
You must be signed in to change notification settings - Fork 1.2k
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
Adopt more UTF-8 #4309
Adopt more UTF-8 #4309
Conversation
This change should be relatively safe
This should be safe because we use `tokenize.open` for source codes.
This change tries to use UTF-8 when writing `.egg-link` files. When reading other files, we first attempt to use UTF-8 and then fallback for the locale encoding.
Extract common pattern for reading a file with UTF-8 into the unicode_utils module.
Since Python3 is "UTF-8 first", this change should not cause problems.
@jaraco, please let me know if you are OK with a more aggressive move towards UTF-8. |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I'm enthusiastically in support. I'd also like to introduce a way to wean users off of any reliance of 'locale' encoding, though not necessarily in this change.
pkg_resources/__init__.py
Outdated
except UnicodeDecodeError: # pragma: no cover | ||
with open(file, "r", encoding=fallback_encoding) as f: | ||
return f.read() |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Maybe emit a warning here so the fallback can be removed?
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Will we be able to remove this?
The question comes to mind mainly because of sdist
s that have been produced by old versions of setuptools
and published to PyPI...
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Warning implemented in 3fbaa4c
Summary of changes
Previously, changes regarding UTF-8 avoided touching complicated parts of the code where it could cause incompatibility.
This PR is a bit more aggressive, but still try to maintain backwards compatibility:
locale
encoding.In my opinion the highest risk here are in the
easy_install/install_scripts
commands, because it might be the case some scripts are not meant to be UTF-8... But hopefully that risk would be minimal1.Closes
Pull Request Checklist
newsfragments/
.(See documentation for details)
Footnotes
Once file contents are encoded as Python strings they are already encoded as UTF-8, so it should be OK to write them directly to files. Moreover, most popular scripting languages nowadays support UTF-8. ↩