-
Notifications
You must be signed in to change notification settings - Fork 122
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
Add explicit encoding to read_text. #577
Conversation
734f1fb
to
238563a
Compare
Might be worth enabling encoding warnings |
Here's where I do that for my projects: I scanned through the equivalent config for towncrier (the noxfile), but I don't immediately see how a environment variable could be set. It's also not obvious to me if it should be set for tests only or for all sessions. Reading through the docs, the Interestingly, running
|
Adding the environment variable to the tests does reveal that there are many more locations in the code where the warning is triggered:
|
Here's a distilled list of the violations:
|
82 checks is a little steep to fix by hand. I looked and ruff doesn't (yet) support fixing the warnings. How do you feel about enabling the warnings but not fixing all of them yet? |
5731419
to
d4ba19e
Compare
8396bac
to
dd70c55
Compare
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.
Looks good.
I think that before we merge this, we should add a note in the documentation that the files must be UTF-8 encoded.
@@ -0,0 +1 @@ | |||
Add explicit encoding to read_text. |
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 don't know if anyone is using non UTF-8 encoding in these days for source code.... maybe some legacy Windows shops might still use UTF-16
I am ok with this change, but I think that somewhere in the documentation, we should mention that towncrier
can only work with UTF-8 fragment files and it will produce UTF-8 encoded files.
Maybe this can be done as part of the "Philosophy" section
https://towncrier.readthedocs.io/en/latest/#philosophy
Maybe add
It assumes that the source code is stored in UTF-8 files.
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 don't know if anyone is using non UTF-8 encoding in these days for source code.... maybe some legacy Windows shops might still use UTF-16
In my experience, that's not been the case, even for text-oriented applications like towncrier. My instinct is it's still a bug fix, but for Windows users, it is technically a breaking change. My advice - hope that there aren't any Windows users relying on locale but be prepared to back out the change and introduce a compatibility shim if someone does encounter an issue. I'm happy to help with that if needed.
Maybe this can be done as part of the "Philosophy" section
I'm a little uneasy adding it to the Philosophy section since that section comes from the readme, and it feels more like an implementation detail. Philosophy doesn't even mention markdown or restructured text, a concern that's going to be a lot more salient to a reader.
In 83b8c02, I've proposed that it be added to the tutorial, near where "markdown" is mentioned and shortly after the user has first encountered creating content for news fragments. Let me know what you think.
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.
In e1caa2c, I took it a step further and explicitly mentioned other concerns that expect UTF-8.
@jaraco with this PR, I can see that the import warning are gone. Please consider update the documentation to mention that UTF-8 is mandatory and I think that after that we can merge this. Thanks again and sorry for the delay |
c484029
to
2b9e1cf
Compare
Thanks for the changes. I have merged this. If someone wants other encoding type, they can send a report and a PR. |
Closes #561
Description
Checklist
src/towncrier/newsfragments/
. Describe yourchange and include important information. Your change will be included in the public release notes.
docs/tutorial.rst
is still up-to-date.docs/cli.rst
reflects those changes.docs/configuration.rst
reflects those changes.