Skip to content
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

context.run prints the codes of unicode chars from the output instead of printing the unicode characters themselves #1014

Open
borco opened this issue Nov 18, 2024 · 1 comment

Comments

@borco
Copy link

borco commented Nov 18, 2024

Create this simple task:

from invoke.tasks import task
from invoke.context import Context


@task
def black(c: Context) -> None:
    """Formats code with `black`."""
    c.run("black src")

Run the task with invoke:

invoke black

The invoke prints the code of the unicode chars returned by the black in its output:

All done! \u2728 \U0001f370 \u2728
...

However, this is the expected output (the output of running directly black src):

All done! ✨ 🍰 ✨
...

Executing black with subprocess.run produces the expected result:

Python 3.12.6 (tags/v3.12.6:a4a2d2b, Sep  6 2024, 20:11:23) [MSC v.1940 64 bit (AMD64)] on win32
Type "help", "copyright", "credits" or "license" for more information.
>>> import subprocess   
>>> subprocess.run("black src")
All done! ✨ 🍰 ✨
...
CompletedProcess(args='black src', returncode=0)
>>>
@borco
Copy link
Author

borco commented Nov 18, 2024

Changing the black task code to look like bellow produces the expected results:

from io import StringIO

from invoke.tasks import task
from invoke.context import Context


@task
def black(c: Context) -> None:
    """Formats code with `black`."""
    s = StringIO()
    c.run("black src", err_stream=s)
    print(s.getvalue().encode().decode("unicode-escape"))

Invoking the task:

inv black

The output:

All done! ✨ 🍰 ✨
...

Is this a bug or am I missing something?

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

1 participant