Write generated docs as UTF-8 in typer ... utils docs --output#1881
Write generated docs as UTF-8 in typer ... utils docs --output#1881Sreekant13 wants to merge 2 commits into
typer ... utils docs --output#1881Conversation
`typer <app> utils docs --output FILE` wrote the Markdown file using the platform's default encoding, so non-ASCII help (for example emojis, which are common in Typer/Rich CLIs) raised UnicodeEncodeError on interpreters where the locale encoding is not UTF-8, such as cp1252 on Windows. Write the file as UTF-8, matching how the docs are read back in the tests, and add a regression test that forces a non-UTF-8 locale so it fails on the old behavior on any platform.
|
Heads up: check-labels is red only because no category label is set yet. This is a bug fix, so it'd be |
|
Hey, thanks for trying to contribute! A few notes, even though I am no maintainer;
These are just some thoughts I had while looking at the PR.. |
LC_ALL=C already overrides LANG, so LANG=C was redundant. Keep LC_ALL=C (forces a non-UTF-8 locale) and PYTHONUTF8=0 (keeps it non-UTF-8 on 3.15+ where UTF-8 mode is on by default), with a comment explaining why each is needed for the test to fail on the old behavior on any platform.
|
Thanks for the review, @phalberg!
Thanks again! |
|
Hi @svlandeg, gentle nudge on this one. The only failing check is check-labels, which just needs a category label added (it's a bug fix). Happy to make any changes you'd like. Thanks! |
There was a problem hiding this comment.
Hi @svlandeg, gentle nudge on this one
Discussion #1882 doesn't have a maintainer approving this PR as per the contribution guidelines & PR template. Also please don't ping maintainers, this really just slows us down and usually does not result in prioritization of your PR. Please consider how much work load we already have maintaining these repo's.
Discussion: #1882
Description
typer <app> utils docs --output FILEwrites the generated Markdown withPath.write_text(clean_docs), which uses the platform's default encoding. When the CLI's help contains non-ASCII characters (emojis are common in Typer/Rich apps) this raisesUnicodeEncodeErroron interpreters whose locale encoding isn't UTF-8 (for example cp1252 on Windows).Reproduction:
This writes the file as UTF-8, which matches how the docs are read back in the tests (
read_text(encoding="utf-8")).I also added a regression test that forces a non-UTF-8 locale (
LC_ALL=C,PYTHONUTF8=0) so it fails on the old behavior on any platform, not just Windows.