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

Open
#1,014 1 comment 0 reactions 0 assignees View on GitHub

Nobody has claimed this yet.

Assessment

Difficulty
3/5
Estimated time
1-2 days
Newbie friendliness
45/100
Issue type
Bug
Clarity
Mostly clear
Activity status
Stale
Tech stack
python
Domain
cli

Research direction

Reproduce the issue with the provided task and invoke black, then inspect the output handling used by Context.run. Compare its behavior with direct black src and subprocess.run; done means Unicode characters such as ✨ and 🍰 are printed directly rather than as escape codes.

Written by the indexing model from the issue text.

Description

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)
>>>
Dominant language
Python
Stars
4.8k
Forks
412
PR merge metrics
No merged PRs in 30d

Contributor guide

No contributing guide indexed for this repository

First steps

  1. Read the whole issue, then the project's contributing guide.
  2. Comment on the issue to say you are picking it up — it saves two people doing the same work.
  3. Fork the repository and make your change on a branch.
  4. Open a pull request that references the issue number.

More from pyinvoke/invoke

All issues in pyinvoke/invoke

Similar issues

More Python issues

Get new issues in your inbox

A short digest of beginner-friendly GitHub issues.