Merged
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.
Contributor
Author
|
@jaraco, please let me know if you are OK with a more aggressive move towards UTF-8. |
jaraco
approved these changes
Apr 21, 2024
Member
jaraco
left a comment
There was a problem hiding this comment.
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.
Comment on lines
+3334
to
+3336
| except UnicodeDecodeError: # pragma: no cover | ||
| with open(file, "r", encoding=fallback_encoding) as f: | ||
| return f.read() |
Member
There was a problem hiding this comment.
Maybe emit a warning here so the fallback can be removed?
Contributor
Author
There was a problem hiding this comment.
Will we be able to remove this?
The question comes to mind mainly because of sdists that have been produced by old versions of setuptools and published to PyPI...
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
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:
localeencoding.In my opinion the highest risk here are in the
easy_install/install_scriptscommands, 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. ↩