Skip to content

Commit

Permalink
Fix IO under Python 3.6 with locale not set (python-poetry#4038)
Browse files Browse the repository at this point in the history
  • Loading branch information
brandonchinn178 authored and 1nF0rmed committed Nov 15, 2021
1 parent 62068e5 commit 527074c
Showing 1 changed file with 15 additions and 0 deletions.
15 changes: 15 additions & 0 deletions poetry/console/application.py
Original file line number Diff line number Diff line change
Expand Up @@ -21,6 +21,7 @@
from cleo.io.outputs.output import Output

from poetry.__version__ import __version__
from poetry.core.utils._compat import PY37

from .command_loader import CommandLoader
from .commands.command import Command
Expand Down Expand Up @@ -143,6 +144,20 @@ def create_io(
) -> IO:
io = super().create_io(input, output, error_output)

# Remove when support for Python 3.6 is removed
# https://github.com/python-poetry/poetry/issues/3412
if (
not PY37
and hasattr(io.output, "_stream")
and hasattr(io.output._stream, "buffer")
and io.output._stream.encoding != "utf-8"
):
import io as io_

io.output._stream = io_.TextIOWrapper(
io.output._stream.buffer, encoding="utf-8"
)

# Set our own CLI styles
formatter = io.output.formatter
formatter.set_style("c1", Style("cyan"))
Expand Down

0 comments on commit 527074c

Please sign in to comment.