-
Notifications
You must be signed in to change notification settings - Fork 2.5k
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
Fix printing of emoji on Windows when stdout is redirected #3374
base: main
Are you sure you want to change the base?
Changes from all commits
405c2e0
08cc65d
5e52770
bd81114
3cf2c67
de02031
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -1411,6 +1411,22 @@ def patch_click() -> None: | |
|
||
|
||
def patched_main() -> None: | ||
#: Fixes errors with emoji in Windows terminals when output is redirected | ||
# (i.e. pre-commit): https://github.com/psf/black/issues/3156 | ||
# To be as safe as possible, we only enable this for "Windows 10 October | ||
# 2018 Update (version 1809)" and up. | ||
if ( | ||
"pytest" not in sys.modules | ||
and platform.system() == "Windows" | ||
and tuple(map(int, platform.version().split("."))) >= (10, 0, 1809) | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Can't decide if I love or hate that last line. Advantages:
The disadvantage is that it reads pretty clumsily ("make a tuple out of an int map of the string that But I guess the advantages outweigh my personal preference here. There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Pretty much sums up my feelings when writing it! |
||
): | ||
sys.stdout = io.TextIOWrapper( | ||
sys.stdout.buffer, encoding="utf-8" | ||
) # pragma: nocover | ||
sys.stderr = io.TextIOWrapper( | ||
sys.stderr.buffer, encoding="utf-8" | ||
) # pragma: nocover | ||
|
||
# PyInstaller patches multiprocessing to need freeze_support() even in non-Windows | ||
# environments so just assume we always need to call it if frozen. | ||
if getattr(sys, "frozen", False): | ||
|
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.