pyinvoke / invoke

Pythonic task management & command execution.
http://pyinvoke.org
BSD 2-Clause "Simplified" License
4.42k stars 370 forks source link

Invoke stdout redirection zaps emojis #790

Open MinchinWeb opened 3 years ago

MinchinWeb commented 3 years ago

Something in how invoke redirects stdout (and likely stderr) means that emojis aren't display, but their code point are in their place.

In a perfect world, it would be lovely if invoke could determine if emojis were printable, and pass them through if so.

Example:

image

Invoke 1.5.0, black v 19.10b0, on Windows 10 with Windows Terminal and PowerShell 7.1.3.

ameily commented 2 years ago

I believe I've found a workaround. It's not ideal but it does work. The trick is to set encoding='utf-8' and also setting the environment variable PYTHONIOENCODING to utf-8:

KWARGS = {}
if sys.platform == 'win32':
    KWARGS.update({'pty': False, 'encoding': 'utf-8', 'env': {'PYTHONIOENCODING': 'utf-8'}})
else:
    KWARGS.update({'pty': True})

@task
def lint(c):
    c.run("black --check <MOD_NAME>", **KWARGS)