-
-
Notifications
You must be signed in to change notification settings - Fork 196
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
Explicitly specify file encoding for windows #2007
base: master
Are you sure you want to change the base?
Conversation
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.
Thanks for raising this problem and offering a PR to fix it, @dalito! 🙏
I have an inline suggestion. And could you try adding a test that fails without the fix?
with Path(fname).open(encoding="utf-8") as conflicts_candidate: | ||
if any( | ||
line.rstrip() | ||
in {"<<<<<<< before updating", ">>>>>>> after updating"} |
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.
Or how about opening the file with "rb"
mode and turning the markers into byte strings?
with Path(fname).open(encoding="utf-8") as conflicts_candidate: | |
if any( | |
line.rstrip() | |
in {"<<<<<<< before updating", ">>>>>>> after updating"} | |
with Path(fname).open("rb") as conflicts_candidate: | |
if any( | |
line.rstrip() | |
in { | |
b"<<<<<<< before updating", | |
b">>>>>>> after updating", | |
} |
This way, we're independent of encodings.
@sisp Can you point me to the approximate place where to add a test? Ah, I just remember this: It may not be possible to reproduce this on the Windows runner as the encoding is different than on local Windows10/11. |
I'd add a test at the bottom of https://github.com/copier-org/copier/blob/master/tests/test_updatediff.py.
We can mock the default encoding. See, e.g., https://github.com/copier-org/copier/pull/2003/files#diff-7e70d7a9d4f971464d4b2f4f2bb1c5154cd6de349132cdf4acafc3f28b05bf4d. Does this help? |
It seems that this place was overlooked. The file encoding is specified on all other non-binary
open(...)
calls except for this one.Closes #2006